Overview
AG2 (formerly AutoGen) is an open-source framework for building AI agents. AG2 has built-in support for the A2A protocol throughA2aRemoteAgent, allowing your agents to communicate with remote A2A agents like StackOne’s.
Use AG2 to build agents that:
- Consume StackOne’s A2A agents as remote agents
- Orchestrate multi-agent conversations with local and remote agents
- Access StackOne platform actions without managing tool definitions
Installation
Install AG2 with A2A support usinguv. Include your model provider’s extra (OpenAI here), and pin the a2a-sdk 0.3 line:
Pin
a2a-sdk to the 0.3 line: StackOne’s A2A server implements A2A 0.3, and the current ag2[a2a] otherwise resolves a2a-sdk 1.x (A2A v1.0), which is not compatible yet, so pinning 0.3 selects a compatible AG2 build. Also pass max_turns to a_initiate_chat (below) to bound the conversation, as each turn runs the remote StackOne agent end to end.Quick Start
This example creates a local agent that delegates HR tasks to a StackOne A2A agent.Architecture
AG2’sA2aRemoteAgent allows your local agent to communicate with remote A2A agents:
Complete Example
Here’s a complete example with a local tool and a remote StackOne agent:Creating from AgentCard
If you already have anAgentCard (e.g., fetched from a discovery service), create an A2aRemoteAgent directly from it:
Human in the Loop Support
A2aRemoteAgent automatically handles Human in the Loop (HITL) interactions when the remote agent requests human input. This happens transparently - the client loops until the agent completes its task or the conversation terminates.
Multiple StackOne Accounts
Connect to multiple StackOne accounts by creating separate HTTP clients andA2aRemoteAgent instances:
Advanced Configuration
Custom HTTP Client
Set custom options on the HTTP client such as headers and timeout:Client Configuration
Pass additional client configuration usingClientConfig:
Testing with MockClient
Mock remote agent replies for testing:Best Practices
Use Async Methods
Use Async Methods
A2aRemoteAgent only supports asynchronous methods. Always use a_initiate_chat and other async methods:Clear System Messages
Clear System Messages
Provide detailed system messages for your orchestrator agent. Include clear instructions about when to delegate to remote agents:
Error Handling
Error Handling
Wrap A2A calls in try-except blocks to handle network or protocol errors:
Message Format
Message Format
Always provide messages in the correct format with
role and content:Next Steps
A2A SDK
Build custom A2A tools with the Python or JavaScript SDK
Authentication
Learn about authentication and security
Quickstart
Learn A2A basics with cURL