tests — protocols

Module: tests-protocols Cohesion: 0.80 Members: 0

tests — protocols

This document provides an overview of the Agent-to-Agent (A2A) Protocol, as implemented and validated by the tests/protocols/a2a.test.ts module. This module serves as a comprehensive test suite, demonstrating the functionality and expected behavior of the A2A communication layer.

The A2A Protocol enables structured communication and task execution between different software agents within a system. It defines how agents are discovered, how tasks are submitted, executed, and how their results and status are managed.

1. Core Concepts

The A2A Protocol revolves around a few fundamental concepts:

2. AgentCard: Describing an Agent

An AgentCard provides essential information about an agent, allowing clients to understand its capabilities without needing to interact with it directly.

Example (from createTestCard):

const card = createAgentCard({
  name: 'SWE Agent',
  description: 'Software engineering agent',
  skills: [
    { id: 'edit', name: 'Edit', description: 'Edit files', inputModes: ['text/plain'], outputModes: ['text/plain'] },
  ],
});

3. Task: The Unit of Work

A Task object represents a single request sent to an agent and its subsequent execution state. It's a rich data structure that evolves throughout its lifecycle.

Task Lifecycle and Status

Tasks progress through a defined set of statuses, tracked in the Task.status and Task.history properties:

4. A2A Protocol Architecture

The A2A Protocol defines a client-server interaction model for agent communication.

sequenceDiagram
    participant Client as A2AAgentClient
    participant Server as A2AAgentServer
    participant Executor as Agent Executor Function

    Client->>Server: submitTask(agentName, message)
    activate Server
    Server->>Server: Update Task Status (SUBMITTED)
    Server->>Executor: Call executor(task)
    activate Executor
    Executor-->>Server: Return updated Task (or throw error)
    deactivate Executor
    Server->>Server: Update Task Status (WORKING, COMPLETED/FAILED)
    Server-->>Client: Return final Task
    deactivate Server

4.1. A2AAgentServer: The Agent's Endpoint

The A2AAgentServer is responsible for hosting an individual agent. It exposes an interface for receiving tasks and managing their execution.

    new A2AAgentServer(agentCard: AgentCard, executor: (task: Task) => Promise<Task>)

4.2. A2AAgentClient: The Orchestrator's Interface

The A2AAgentClient acts as a central registry and communication hub for interacting with multiple A2AAgentServer instances. It allows other parts of the system to discover and utilize agents.

    new A2AAgentClient()

5. Utility Functions

The protocol also includes helper functions for common operations:

6. Integration and Usage Patterns

The tests/protocols/a2a.test.ts module demonstrates the intended usage and interaction patterns:

  1. Agent Definition: An agent is defined by its AgentCard and an executor function, which are then used to instantiate an A2AAgentServer.
  2. Agent Registration: A2AAgentServer instances are registered with an A2AAgentClient under a unique name.
  3. Agent Discovery: Clients can list all agents, retrieve their AgentCards, or find agents based on specific skills.
  4. Task Submission: Clients submit tasks to registered agents via the A2AAgentClient, specifying the agent's name and the task message.
  5. Task Execution: The A2AAgentServer invokes the agent's executor function. The executor is responsible for performing the work, updating the Task object (e.g., adding artifacts, messages), and returning it.
  6. Task Lifecycle Management: The A2AAgentServer automatically updates the task's status and history throughout its execution (SUBMITTED -> WORKING -> COMPLETED/FAILED).
  7. Error Handling: If an agent's executor throws an error, the task's status is set to FAILED, and the error message is captured in Task.status.message.
  8. Event-Driven Interactions: A2AAgentServer emits events, allowing external systems to react to task state changes (e.g., logging, notifications).
  9. Result Extraction: The getTaskResult utility simplifies retrieving the primary output from a completed task.

This protocol provides a robust and extensible framework for building and orchestrating intelligent agents.