-
Notifications
You must be signed in to change notification settings - Fork 2.3k
.NET: Simplify A2A function tool samples #7861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
SergeyMenshykh
merged 3 commits into
microsoft:main
from
SergeyMenshykh:sergeymenshykh-simplify-a2a-samples
Aug 26, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
dotnet/samples/02-agents/A2A/A2AAgent_AsFunctionTool/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| // This sample shows how to expose an A2A agent as a function tool that another agent can call. | ||
|
|
||
| using A2A; | ||
| using Azure.AI.Projects; | ||
| using Azure.Identity; | ||
| using Microsoft.Agents.AI; | ||
|
|
||
| var endpoint = Environment.GetEnvironmentVariable("FOUNDRY_PROJECT_ENDPOINT") ?? throw new InvalidOperationException("FOUNDRY_PROJECT_ENDPOINT is not set."); | ||
| var model = Environment.GetEnvironmentVariable("FOUNDRY_MODEL") ?? "gpt-5.4-mini"; | ||
| var a2aAgentHost = Environment.GetEnvironmentVariable("A2A_AGENT_HOST") ?? throw new InvalidOperationException("A2A_AGENT_HOST is not set."); | ||
|
|
||
| // Initialize an A2ACardResolver to get an A2A agent card. | ||
| A2ACardResolver agentCardResolver = new(new Uri(a2aAgentHost)); | ||
|
|
||
| // Get the agent card | ||
| AgentCard agentCard = await agentCardResolver.GetAgentCardAsync(); | ||
|
|
||
| // Create an instance of the AIAgent for an existing A2A agent specified by the agent card. | ||
| AIAgent a2aAgent = agentCard.AsAIAgent(); | ||
|
|
||
| // Create the main agent, and provide the A2A agent as a function tool. | ||
| // WARNING: DefaultAzureCredential is convenient for development but requires careful consideration in production. | ||
| // In production, consider using a specific credential (e.g., ManagedIdentityCredential) to avoid | ||
| // latency issues, unintended credential probing, and potential security risks from fallback mechanisms. | ||
| AIAgent agent = new AIProjectClient(new Uri(endpoint), new DefaultAzureCredential()) | ||
| .AsAIAgent( | ||
| model: model, | ||
| instructions: "You are a helpful assistant. Use the available tools to answer the user's questions.", | ||
| tools: [a2aAgent.AsAIFunction()] | ||
| ); | ||
|
|
||
| // Invoke the agent and output the text result. | ||
| Console.WriteLine(await agent.RunAsync("What can you help me with?")); | ||
30 changes: 30 additions & 0 deletions
30
dotnet/samples/02-agents/A2A/A2AAgent_AsFunctionTool/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # A2A Agent as a Function Tool | ||
|
|
||
| This sample demonstrates how to expose an A2A agent as a single function tool that another AI agent can call. | ||
|
|
||
| The sample: | ||
|
|
||
| - Discovers a remote A2A agent from its agent card | ||
| - Converts the agent card to an `AIAgent` | ||
| - Converts that agent to one function tool with `AsAIFunction()` | ||
| - Registers the function tool with a main AI agent | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| Before you begin, ensure you have the following prerequisites: | ||
|
|
||
| - .NET 10 SDK or later | ||
| - Access to the A2A agent host service | ||
| - A Microsoft Foundry project with a deployed model | ||
|
|
||
| **Note**: These samples need to be run against a valid A2A server. If no A2A server is available, they can be run against the echo-agent that can be spun up locally by following the guidelines at: https://github.com/a2aproject/a2a-dotnet/blob/main/samples/AgentServer/README.md | ||
|
|
||
| Set the following environment variables: | ||
|
|
||
| Authenticate with Azure CLI by running `az login`, then set: | ||
|
|
||
| ```powershell | ||
| $env:A2A_AGENT_HOST="https://your-a2a-agent-host" # Replace with your A2A agent host endpoint | ||
| $env:FOUNDRY_PROJECT_ENDPOINT="https://your-project.services.ai.azure.com/api/projects/your-project" # Replace with your Foundry project endpoint | ||
| $env:FOUNDRY_MODEL="gpt-5.4-mini" # Optional, defaults to gpt-5.4-mini | ||
| ``` |
22 changes: 0 additions & 22 deletions
22
dotnet/samples/02-agents/A2A/A2AAgent_AsFunctionTools/README.md
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
dotnet/samples/02-agents/A2A/A2AAgent_Skills/A2AAgent_Skills.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFrameworks>net10.0</TargetFrameworks> | ||
|
|
||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="A2A" /> | ||
| <PackageReference Include="Azure.Identity" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\..\..\src\Microsoft.Agents.AI.A2A\Microsoft.Agents.AI.A2A.csproj" /> | ||
| <ProjectReference Include="..\..\..\..\src\Microsoft.Agents.AI.Foundry\Microsoft.Agents.AI.Foundry.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
25 changes: 8 additions & 17 deletions
25
...s/A2A/A2AAgent_AsFunctionTools/Program.cs → .../02-agents/A2A/A2AAgent_Skills/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # A2A Agent Skills | ||
|
|
||
| This sample demonstrates how to expose each skill advertised by an A2A agent as a separate function tool for another AI agent. | ||
|
|
||
| Unlike exposing the whole A2A agent as one tool, this approach gives the model a distinct tool for each skill. The sample uses the skill metadata from the A2A agent card to name and describe those tools. | ||
|
|
||
| All generated tools invoke the same A2A agent. Their names and descriptions help the main agent choose an advertised capability; they do not invoke separate skill-specific endpoints. | ||
|
|
||
| The sample: | ||
|
|
||
| - Discovers a remote A2A agent and its skills from the agent card | ||
| - Creates one function tool for each advertised skill | ||
| - Adds the skill's description, tags, examples, and supported modes to the function description | ||
| - Registers all generated function tools with a main AI agent | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| Before you begin, ensure you have the following prerequisites: | ||
|
|
||
| - .NET 10 SDK or later | ||
| - Access to the A2A agent host service | ||
| - A Microsoft Foundry project with a deployed model | ||
|
|
||
| **Note**: These samples need to be run against a valid A2A server. If no A2A server is available, they can be run against the echo-agent that can be spun up locally by following the guidelines at: https://github.com/a2aproject/a2a-dotnet/blob/main/samples/AgentServer/README.md | ||
|
|
||
| Set the following environment variables: | ||
|
|
||
| Authenticate with Azure CLI by running `az login`, then set: | ||
|
|
||
| ```powershell | ||
| $env:A2A_AGENT_HOST="https://your-a2a-agent-host" # Replace with your A2A agent host endpoint | ||
| $env:FOUNDRY_PROJECT_ENDPOINT="https://your-project.services.ai.azure.com/api/projects/your-project" # Replace with your Foundry project endpoint | ||
| $env:FOUNDRY_MODEL="gpt-5.4-mini" # Optional, defaults to gpt-5.4-mini | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.