The AgentKit leverages several key libraries:
- @a2a-js/sdk: Core A2A protocol implementation.
A2AClient: For client-side interactions (used in CLI).- Server-side:
AgentCard,TaskStore(InMemoryTaskStore),AgentExecutor,DefaultRequestHandler,A2AExpressApp.
- Genkit: AI orchestration framework.
- Configured in
genkit.tsper agent with plugins (e.g.,@genkit-ai/googleai) and models. - Supports prompts (e.g.,
movie_agent.prompt), tools (e.g., TMDB searches), and custom formats (e.g., code output).
- Configured in
- Express: HTTP server for each agent, with routes set up by
A2AExpressApp.
Each agent in src/agents/<agent-name>/ follows a consistent pattern:
- index.ts: Main entry point.
- Defines
AgentCard(name, description, skills, capabilities like streaming). - Creates
TaskStore,AgentExecutor(custom class implementing task logic), andDefaultRequestHandler. - Sets up Express app with A2A routes and starts server on a specific port.
- Defines
- genkit.ts: Genkit configuration.
- Initializes
genkit()with plugins, model (e.g.,googleAI.model('gemini-1.5-pro')), and prompt directory. - Defines custom formats (e.g.,
defineCodeFormatfor Coder Agent).
- Initializes
- agent.prompt: Genkit prompt template.
- System instructions for AI behavior (e.g., output format for code blocks).
- tools.ts (optional): Genkit tools.
- Functions like
searchMoviesusing TMDB API, defined withai.defineTool.
- Functions like
- code-format.ts (Coder-specific): Custom schema and parsing for code artifacts.
- Client Request: CLI or external client sends a
Messageto agent's URL (e.g.,POST /a2a/v1/tasks). - Task Creation/Retrieval:
DefaultRequestHandlerusesTaskStoreto get or create aTaskwith ID and context ID. - Execution:
AgentExecutor.execute():- Publishes initial
Taskevent. - Sends "working" status via
TaskStatusUpdateEvent. - Prepares message history for Genkit.
- Runs Genkit prompt/tools (e.g.,
ai.generate()orprompt()). - Handles streaming/chunks (e.g., emits
TaskArtifactUpdateEventfor files). - Checks for cancellation.
- Publishes final status (completed, failed, input-required) with agent
Message.
- Publishes initial
- Event Publishing: All via
ExecutionEventBusfor real-time updates. - Artifacts: For Coder Agent, parses markdown code blocks into file artifacts.
- Uses
A2AClientto connect to agent URL. readlinefor interactive input.- Listens for events: Status updates (with emojis/colors), artifact emissions.
- Supports task cancellation.
- Add new agents: Copy folder structure, implement custom
AgentExecutor. - Customize AI: Update prompts, models, or add tools.
- Persistence: Replace
InMemoryTaskStorewith database-backed store for production."