Skip to content

Commit ff89606

Browse files
committed
Add adk/a2a support
Signed-off-by: David Gageot <[email protected]>
1 parent a52613c commit ff89606

16 files changed

+878
-148
lines changed

cmd/root/adk.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package root
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
6+
"github.com/docker/cagent/pkg/adk"
7+
"github.com/docker/cagent/pkg/cli"
8+
"github.com/docker/cagent/pkg/config"
9+
"github.com/docker/cagent/pkg/telemetry"
10+
)
11+
12+
type adkFlags struct {
13+
agentName string
14+
workingDir string
15+
port int
16+
runConfig config.RuntimeConfig
17+
}
18+
19+
func newADKCmd() *cobra.Command {
20+
var flags adkFlags
21+
22+
cmd := &cobra.Command{
23+
Use: "adk <agent-file>",
24+
Short: "Start an ADK (Agent Development Kit) A2A server",
25+
Long: `Start an A2A (Agent-to-Agent) server that exposes cagent agents using Google's ADK framework`,
26+
Example: ` cagent adk ./agent.yaml
27+
cagent adk ./team.yaml --port 8080
28+
cagent adk agentcatalog/pirate --port 9000`,
29+
Args: cobra.ExactArgs(1),
30+
RunE: flags.runADKCommand,
31+
}
32+
33+
cmd.PersistentFlags().StringVarP(&flags.agentName, "agent", "a", "root", "Name of the agent to run")
34+
cmd.PersistentFlags().StringVar(&flags.workingDir, "working-dir", "", "Set the working directory for the session (applies to tools and relative paths)")
35+
cmd.PersistentFlags().IntVar(&flags.port, "port", 0, "Port to listen on (default: random available port)")
36+
addRuntimeConfigFlags(cmd, &flags.runConfig)
37+
38+
return cmd
39+
}
40+
41+
func (f *adkFlags) runADKCommand(cmd *cobra.Command, args []string) error {
42+
telemetry.TrackCommand("adk", args)
43+
44+
ctx := cmd.Context()
45+
out := cli.NewPrinter(cmd.OutOrStdout())
46+
agentFilename := args[0]
47+
48+
if err := setupWorkingDirectory(f.workingDir); err != nil {
49+
return err
50+
}
51+
52+
return adk.StartA2AServer(ctx, out, agentFilename, f.agentName, f.runConfig, f.port)
53+
}

cmd/root/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ func NewRootCmd() *cobra.Command {
8585
cmd.AddCommand(newAPICmd())
8686
cmd.AddCommand(newACPCmd())
8787
cmd.AddCommand(newMCPCmd())
88+
cmd.AddCommand(newADKCmd())
8889
cmd.AddCommand(newEvalCmd())
8990
cmd.AddCommand(newPushCmd())
9091
cmd.AddCommand(newPullCmd())

docs/adk-integration.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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

Comments
 (0)