Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
[This article is prerelease documentation and is subject to change.]
What is an A2A Client?
An A2A client is an agent or application that can proactively send tasks to A2A servers and interact with them using the A2A protocol.
Using AgentManager to Call A2A Servers
You can use the AgentManager
to register and send tasks to different A2A servers:
// import { AgentManager } from "@microsoft/teams.a2a";
const directlyUserAgentManager = async (message: string) => {
const agentManager = new AgentManager();
agentManager.use("my-agent", "https://my-agent.com/a2a");
const taskId = "my-task-id"; // Generated or reused from previous task
await agentManager.sendTask("my-agent", {
id: taskId,
message: {
role: 'user',
parts: [{ type: 'text' as const, text: message }],
},
});
}
Using A2AClientPlugin with ChatPrompt
A2A is most effective when used with an LLM. The A2AClientPlugin
can be added to your chat prompt to allow interaction with A2A agents. Once added, the plugin will automatically configure the system prompt and tool calls to determine if the a2a server is needed for a particular task, and if so, it will do the work of orchestrating the call to the A2A server.
// import { ChatPrompt } from "@microsoft/teams.ai";
// import { OpenAIChatModel } from "@microsoft/teams.openai";
// import { A2AClientPlugin } from "@microsoft/teams.a2a";
const prompt = new ChatPrompt(
{
logger,
model: new OpenAIChatModel({
apiKey: process.env.OPENAI_API_KEY,
model: "gpt-4o-mini",
}),
},
// Add the A2AClientPlugin to the prompt
[new A2AClientPlugin()]
)
// Provide the agent's server URL
.usePlugin("a2a", {
key: "my-weather-agent",
url: "http://localhost:4000/a2a",
});
// Now we can send the message to the prompt and it will decide if
// the a2a agent should be used or not and also manages contacting the agent
const result = await prompt.send(message);
return result;
Sequence Diagram
To understand how the A2A client works with the ChatPrompt
, A2AClientPlugin
, and AgentManager
, here is a sequence diagram that illustrates the flow of messages. The main thing to note is that the A2AClientPlugin
has 3 main responsibilities:
- Keep state of the A2A agents that it can call. It does so using the
AgentManager
described above. - Before sending a message to the LLM, it gets the agent cards for the required agents, and includes their descriptions in the system prompt.
- It configures the tool calls for the LLM to decide if it needs to call a particular A2A agent.
- If the LLM decides to call an A2A agent, the plugin will use the
AgentManager
to call the agent and return the result.
Notes
- This package and the A2A protocol are experimental.
- Ensure you handle errors and edge cases when interacting with remote agents.