|
| 1 | +# Multi-Protocol Support in a2ajava |
| 2 | + |
| 3 | +The a2ajava framework now supports three major agent protocols, making it the most comprehensive agent integration platform available: |
| 4 | + |
| 5 | +1. **A2A (App-to-App)** - Google's JSON-RPC based protocol |
| 6 | +2. **MCP (Model Context Protocol)** - LLM communication protocol |
| 7 | +3. **ACP (Agent Connect Protocol)** - Cisco's REST-based protocol |
| 8 | + |
| 9 | +## Overview |
| 10 | + |
| 11 | +All three protocols work seamlessly with the same underlying agent implementations using `@Agent` and `@Action` annotations. The framework automatically handles protocol translation and routing. |
| 12 | + |
| 13 | +## Agent Implementation |
| 14 | + |
| 15 | +Create agents using standard annotations that work with all protocols: |
| 16 | + |
| 17 | +```java |
| 18 | +@Agent(groupName = "customer support", groupDescription = "actions related to customer support") |
| 19 | +public class CustomerSupportAgent { |
| 20 | + |
| 21 | + @Action(description = "Create a support ticket for customer issues") |
| 22 | + public String createTicket(String customerName, String issue) { |
| 23 | + return "Ticket created for " + customerName + ": " + issue; |
| 24 | + } |
| 25 | + |
| 26 | + @Action(description = "Check the status of an existing ticket") |
| 27 | + public String checkTicketStatus(String ticketId) { |
| 28 | + return "Ticket " + ticketId + " is in progress"; |
| 29 | + } |
| 30 | +} |
| 31 | +``` |
| 32 | + |
| 33 | +## A2A Protocol Usage |
| 34 | + |
| 35 | +A2A uses JSON-RPC for communication. Here's how to interact with agents: |
| 36 | + |
| 37 | +### Client Example |
| 38 | +```java |
| 39 | +// A2A JSON-RPC client |
| 40 | +JsonRpcController controller = new JsonRpcController(applicationContext); |
| 41 | + |
| 42 | +// Get agent card |
| 43 | +AgentCard card = controller.getAgentCard(); |
| 44 | + |
| 45 | +// Execute action |
| 46 | +Map<String, Object> params = Map.of( |
| 47 | + "customerName", "John Doe", |
| 48 | + "issue", "Login problem" |
| 49 | +); |
| 50 | +String result = controller.executeAction("createTicket", params); |
| 51 | +``` |
| 52 | + |
| 53 | +### JSON-RPC Request |
| 54 | +```json |
| 55 | +{ |
| 56 | + "jsonrpc": "2.0", |
| 57 | + "method": "createTicket", |
| 58 | + "params": { |
| 59 | + "customerName": "John Doe", |
| 60 | + "issue": "Login problem" |
| 61 | + }, |
| 62 | + "id": 1 |
| 63 | +} |
| 64 | +``` |
| 65 | + |
| 66 | +## MCP Protocol Usage |
| 67 | + |
| 68 | +MCP is designed for LLM communication with structured tool calling: |
| 69 | + |
| 70 | +### Client Example |
| 71 | +```java |
| 72 | +// MCP client |
| 73 | +MCPToolsController mcpController = new MCPToolsController(applicationContext); |
| 74 | + |
| 75 | +// List available tools |
| 76 | +ListToolsResult tools = mcpController.listTools(); |
| 77 | + |
| 78 | +// Call tool |
| 79 | +CallToolRequest request = new CallToolRequest(); |
| 80 | +request.setName("createTicket"); |
| 81 | +request.setArguments(Map.of( |
| 82 | + "customerName", "Jane Smith", |
| 83 | + "issue", "Payment issue" |
| 84 | +)); |
| 85 | + |
| 86 | +CallToolResult result = mcpController.callTool(request); |
| 87 | +``` |
| 88 | + |
| 89 | +### MCP Tool Call |
| 90 | +```json |
| 91 | +{ |
| 92 | + "method": "tools/call", |
| 93 | + "params": { |
| 94 | + "name": "createTicket", |
| 95 | + "arguments": { |
| 96 | + "customerName": "Jane Smith", |
| 97 | + "issue": "Payment issue" |
| 98 | + } |
| 99 | + } |
| 100 | +} |
| 101 | +``` |
| 102 | + |
| 103 | +## ACP Protocol Usage |
| 104 | + |
| 105 | +ACP uses REST endpoints for agent interaction: |
| 106 | + |
| 107 | +### Client Example |
| 108 | +```java |
| 109 | +// ACP REST client |
| 110 | +ACPRestController acpController = new ACPRestController(applicationContext); |
| 111 | + |
| 112 | +// Search agents |
| 113 | +AgentSearchRequest searchRequest = new AgentSearchRequest(); |
| 114 | +searchRequest.setQuery("customer support"); |
| 115 | +List<Agent> agents = acpController.searchAgents(searchRequest).getBody(); |
| 116 | + |
| 117 | +// Create stateless run |
| 118 | +RunCreateStateless runRequest = new RunCreateStateless(); |
| 119 | +runRequest.setAgentId(agents.get(0).getAgentId()); |
| 120 | +runRequest.setInput(Map.of( |
| 121 | + "customerName", "Bob Wilson", |
| 122 | + "issue", "Account locked" |
| 123 | +)); |
| 124 | + |
| 125 | +AgentRun run = acpController.createStatelessRun(runRequest).getBody(); |
| 126 | +``` |
| 127 | + |
| 128 | +### REST API Calls |
| 129 | +```bash |
| 130 | +# Search agents |
| 131 | +curl -X POST http://localhost:8080/acp/agents/search \ |
| 132 | + -H "Content-Type: application/json" \ |
| 133 | + -d '{"query": "customer support", "limit": 10}' |
| 134 | + |
| 135 | +# Get agent details |
| 136 | +curl http://localhost:8080/acp/agents/{agent-id} |
| 137 | + |
| 138 | +# Create stateless run |
| 139 | +curl -X POST http://localhost:8080/acp/runs \ |
| 140 | + -H "Content-Type: application/json" \ |
| 141 | + -d '{ |
| 142 | + "agent_id": "550e8400-e29b-41d4-a716-446655440000", |
| 143 | + "input": { |
| 144 | + "customerName": "Bob Wilson", |
| 145 | + "issue": "Account locked" |
| 146 | + } |
| 147 | + }' |
| 148 | +``` |
| 149 | + |
| 150 | +## Stateful vs Stateless Execution |
| 151 | + |
| 152 | +### ACP Stateful Execution with Threads |
| 153 | +```java |
| 154 | +// Create thread for stateful conversation |
| 155 | +Map<String, Object> metadata = Map.of("session", "customer-session-123"); |
| 156 | +Thread thread = acpController.createThread(metadata).getBody(); |
| 157 | + |
| 158 | +// Create stateful run |
| 159 | +RunCreateStateful statefulRequest = new RunCreateStateful(); |
| 160 | +statefulRequest.setAgentId(agentId); |
| 161 | +statefulRequest.setThreadId(thread.getThreadId()); |
| 162 | +statefulRequest.setInput(Map.of("customerName", "Alice Brown")); |
| 163 | + |
| 164 | +AgentRun run = acpController.createStatefulRun( |
| 165 | + thread.getThreadId(), |
| 166 | + statefulRequest |
| 167 | +).getBody(); |
| 168 | +``` |
| 169 | + |
| 170 | +### A2A Task-based Execution |
| 171 | +```java |
| 172 | +// A2A uses Task model for state management |
| 173 | +Task task = new Task(); |
| 174 | +task.setId("task-123"); |
| 175 | +task.setSessionId("session-456"); |
| 176 | + |
| 177 | +// Execute with task context |
| 178 | +controller.executeWithTask(task, "createTicket", params); |
| 179 | +``` |
| 180 | + |
| 181 | +## Protocol Comparison |
| 182 | + |
| 183 | +| Feature | A2A | MCP | ACP | |
| 184 | +|---------|-----|-----|-----| |
| 185 | +| Transport | JSON-RPC | JSON-RPC | REST | |
| 186 | +| State Management | Task-based | Stateless | Thread-based | |
| 187 | +| Agent Discovery | AgentCard | Tool listing | Agent search | |
| 188 | +| Streaming | Yes | Yes | Yes | |
| 189 | +| Authentication | Custom | Custom | REST standard | |
| 190 | +| Use Case | App integration | LLM tools | Enterprise agents | |
| 191 | + |
| 192 | +## Configuration |
| 193 | + |
| 194 | +### Spring Boot Configuration |
| 195 | +```java |
| 196 | +@Configuration |
| 197 | +public class MultiProtocolConfig { |
| 198 | + |
| 199 | + @Bean |
| 200 | + public JsonRpcController a2aController(ApplicationContext context) { |
| 201 | + return new SpringAwareJSONRpcController(context); |
| 202 | + } |
| 203 | + |
| 204 | + @Bean |
| 205 | + public MCPToolsController mcpController(ApplicationContext context) { |
| 206 | + return new SpringAwareMCPToolsController(context); |
| 207 | + } |
| 208 | + |
| 209 | + @Bean |
| 210 | + public ACPRestController acpController(ApplicationContext context) { |
| 211 | + return new SpringAwareACPController(context); |
| 212 | + } |
| 213 | +} |
| 214 | +``` |
| 215 | + |
| 216 | +### Application Properties |
| 217 | +```properties |
| 218 | +# Enable all protocols |
| 219 | +a2a.enabled=true |
| 220 | +mcp.enabled=true |
| 221 | +acp.enabled=true |
| 222 | + |
| 223 | +# Protocol-specific settings |
| 224 | +acp.base-url=http://localhost:8080/acp |
| 225 | +a2a.jsonrpc.endpoint=/jsonrpc |
| 226 | +mcp.tools.endpoint=/mcp |
| 227 | +``` |
| 228 | + |
| 229 | +## Testing All Protocols |
| 230 | + |
| 231 | +The framework includes comprehensive tests for all protocols: |
| 232 | + |
| 233 | +```java |
| 234 | +@Test |
| 235 | +void testMultiProtocolIntegration() { |
| 236 | + // Test A2A |
| 237 | + String a2aResult = a2aController.executeAction("createTicket", params); |
| 238 | + |
| 239 | + // Test MCP |
| 240 | + CallToolResult mcpResult = mcpController.callTool(mcpRequest); |
| 241 | + |
| 242 | + // Test ACP |
| 243 | + AgentRun acpResult = acpController.createStatelessRun(acpRequest).getBody(); |
| 244 | + |
| 245 | + // All should produce equivalent results |
| 246 | + assertThat(a2aResult).contains("Ticket created"); |
| 247 | + assertThat(mcpResult.getContent()).contains("Ticket created"); |
| 248 | + assertThat(acpResult.getStatus()).isEqualTo(AgentRun.RunStatus.success); |
| 249 | +} |
| 250 | +``` |
| 251 | + |
| 252 | +## Best Practices |
| 253 | + |
| 254 | +1. **Single Agent Implementation**: Write agents once using `@Agent`/`@Action` annotations |
| 255 | +2. **Protocol Selection**: Choose protocol based on client needs: |
| 256 | + - A2A for app-to-app integration |
| 257 | + - MCP for LLM tool calling |
| 258 | + - ACP for enterprise REST APIs |
| 259 | +3. **State Management**: Use appropriate state models for each protocol |
| 260 | +4. **Error Handling**: Implement consistent error handling across protocols |
| 261 | +5. **Testing**: Test agents with all three protocols to ensure compatibility |
| 262 | + |
| 263 | +## Migration Guide |
| 264 | + |
| 265 | +### From A2A-only to Multi-Protocol |
| 266 | + |
| 267 | +1. Add ACP and MCP dependencies to `pom.xml` |
| 268 | +2. Configure additional controllers in Spring |
| 269 | +3. Existing `@Agent`/`@Action` code works unchanged |
| 270 | +4. Add protocol-specific endpoints as needed |
| 271 | + |
| 272 | +### Protocol-Specific Considerations |
| 273 | + |
| 274 | +- **A2A**: Maintains backward compatibility |
| 275 | +- **MCP**: Requires tool schema definitions |
| 276 | +- **ACP**: Needs REST endpoint configuration |
| 277 | + |
| 278 | +## Conclusion |
| 279 | + |
| 280 | +The a2ajava framework's multi-protocol support enables seamless agent integration across different ecosystems. Whether you're building LLM tools, enterprise APIs, or app integrations, a single agent implementation works across all three major protocols. |
| 281 | + |
| 282 | +For more examples and detailed API documentation, see the individual protocol documentation in the `/docs` directory. |
0 commit comments