Skip to main content

Overview

AG2 (formerly AutoGen) is an open-source framework for building AI agents. AG2 has built-in support for the A2A protocol through A2aRemoteAgent, 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
A2aRemoteAgent supports only asynchronous methods - this is a limitation of the A2A client.

Installation

Install AG2 with A2A support using uv. 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.
See Authentication Guide for details on obtaining your API key and account ID.

Architecture

AG2’s A2aRemoteAgent 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 an AgentCard (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 and A2aRemoteAgent instances:

Advanced Configuration

Custom HTTP Client

Set custom options on the HTTP client such as headers and timeout:

Client Configuration

Pass additional client configuration using ClientConfig:

Testing with MockClient

Mock remote agent replies for testing:

Best Practices

A2aRemoteAgent only supports asynchronous methods. Always use a_initiate_chat and other async methods:
Provide detailed system messages for your orchestrator agent. Include clear instructions about when to delegate to remote agents:
Wrap A2A calls in try-except blocks to handle network or protocol errors:
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