|
| 1 | +# CAgent ADK Integration |
| 2 | + |
| 3 | +This document describes the ADK (Agent Development Kit) integration for cagent, which enables exposing cagent agents via Google's A2A (Agent-to-Agent) protocol. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The ADK integration allows cagent agents to be exposed as A2A servers, enabling agent-to-agent communication using Google's standardized protocol. This makes cagent agents interoperable with other ADK-based agents. |
| 8 | + |
| 9 | +## Components |
| 10 | + |
| 11 | +### 1. Package: `pkg/adk` |
| 12 | + |
| 13 | +This package contains the core integration code: |
| 14 | + |
| 15 | +- **`adapter.go`**: Wraps cagent agents as ADK agents |
| 16 | + - `NewCAgentAdapter(team, agentName)`: Creates an ADK agent from a cagent agent |
| 17 | + - Converts cagent runtime events to ADK session events |
| 18 | + - Handles streaming responses and error propagation |
| 19 | + |
| 20 | +- **`server.go`**: A2A server implementation |
| 21 | + - `StartA2AServer(team, agentName, port, out)`: Starts an A2A server |
| 22 | + - Uses ADK's `a2asrv` package for the server implementation |
| 23 | + - Provides agent card at `/.well-known/agent.json` |
| 24 | + |
| 25 | +### 2. Command: `cagent adk` |
| 26 | + |
| 27 | +Located in `cmd/root/adk.go`, this command starts an A2A server for a cagent agent. |
| 28 | + |
| 29 | +#### Usage |
| 30 | + |
| 31 | +```bash |
| 32 | +# Start A2A server for an agent |
| 33 | +cagent adk ./agent.yaml |
| 34 | + |
| 35 | +# Specify a custom port |
| 36 | +cagent adk ./agent.yaml --port 8080 |
| 37 | + |
| 38 | +# Use an agent from the catalog |
| 39 | +cagent adk agentcatalog/pirate --port 9000 |
| 40 | +``` |
| 41 | + |
| 42 | +#### Features |
| 43 | + |
| 44 | +- Auto-selects available port if not specified |
| 45 | +- Loads agents from files or agent catalog |
| 46 | +- Supports all cagent features (tools, models gateway, etc.) |
| 47 | +- Provides agent metadata via standard A2A agent card |
| 48 | + |
| 49 | +## Architecture |
| 50 | + |
| 51 | +The integration works by: |
| 52 | + |
| 53 | +1. **Agent Wrapping**: Cagent agents are wrapped using ADK's `agent.New()` with a custom Run function |
| 54 | +2. **Event Conversion**: Cagent runtime events are converted to ADK session events: |
| 55 | + - `AgentChoiceEvent` → LLM response events (with streaming support) |
| 56 | + - `ErrorEvent` → Error propagation |
| 57 | + - `StreamStoppedEvent` → Final complete event |
| 58 | +3. **A2A Server**: The ADK `a2asrv` package handles the HTTP server and A2A protocol |
| 59 | + |
| 60 | +## Event Flow |
| 61 | + |
| 62 | +``` |
| 63 | +User Request |
| 64 | + ↓ |
| 65 | +ADK InvocationContext (contains user message) |
| 66 | + ↓ |
| 67 | +CAgent Session (created from user message) |
| 68 | + ↓ |
| 69 | +CAgent Runtime (executes agent logic) |
| 70 | + ↓ |
| 71 | +Runtime Events (streamed) |
| 72 | + ↓ |
| 73 | +ADK Session Events (converted) |
| 74 | + ↓ |
| 75 | +A2A Response (sent to client) |
| 76 | +``` |
| 77 | + |
| 78 | +## Dependencies |
| 79 | + |
| 80 | +The integration requires: |
| 81 | +- `google.golang.org/adk` v0.1.0 |
| 82 | +- `github.com/a2aproject/a2a-go` v0.3.0 |
| 83 | +- Standard cagent dependencies |
| 84 | + |
| 85 | +## Limitations and Future Work |
| 86 | + |
| 87 | +1. **Tool Call Visibility**: Currently, tool calls are handled internally and not exposed as separate ADK events |
| 88 | +2. **Artifacts**: ADK artifact support not yet integrated |
| 89 | +3. **Memory**: ADK memory features not yet integrated |
| 90 | +4. **Sub-agents**: Cagent teams/multi-agent scenarios need further work |
| 91 | +5. **Callbacks**: ADK before/after agent callbacks not yet used |
| 92 | + |
| 93 | +## Testing |
| 94 | + |
| 95 | +Build and test: |
| 96 | +```bash |
| 97 | +# Build |
| 98 | +go build -o cagent . |
| 99 | + |
| 100 | +# Test |
| 101 | +./cagent adk --help |
| 102 | +``` |
| 103 | + |
| 104 | +## Implementation Notes |
| 105 | + |
| 106 | +- The adapter uses ADK's custom agent API (`agent.New`) rather than implementing the full `Agent` interface |
| 107 | +- Events are yielded using Go 1.22's `iter.Seq2` pattern for streaming |
| 108 | +- The implementation focuses on single-agent scenarios; multi-agent support may need refinement |
| 109 | +- OAuth and other A2A features are handled by the ADK library |
0 commit comments