diff --git a/dotnet/agent-framework-dotnet.slnx b/dotnet/agent-framework-dotnet.slnx index e2a8083dc9e..2cd2bbd6ce7 100644 --- a/dotnet/agent-framework-dotnet.slnx +++ b/dotnet/agent-framework-dotnet.slnx @@ -409,6 +409,7 @@ + diff --git a/dotnet/samples/02-agents/A2A/A2AAgent_BasicUsage/A2AAgent_BasicUsage.csproj b/dotnet/samples/02-agents/A2A/A2AAgent_BasicUsage/A2AAgent_BasicUsage.csproj new file mode 100644 index 00000000000..d21ac952b3a --- /dev/null +++ b/dotnet/samples/02-agents/A2A/A2AAgent_BasicUsage/A2AAgent_BasicUsage.csproj @@ -0,0 +1,19 @@ + + + + Exe + net10.0 + + enable + enable + + + + + + + + + + + diff --git a/dotnet/samples/02-agents/A2A/A2AAgent_BasicUsage/Program.cs b/dotnet/samples/02-agents/A2A/A2AAgent_BasicUsage/Program.cs new file mode 100644 index 00000000000..f3f4f4f83a7 --- /dev/null +++ b/dotnet/samples/02-agents/A2A/A2AAgent_BasicUsage/Program.cs @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft. All rights reserved. + +// This sample shows how to send a message to an existing A2A agent and receive its response using default settings. + +using A2A; +using Microsoft.Agents.AI; + +var a2aAgentHost = Environment.GetEnvironmentVariable("A2A_AGENT_HOST") ?? throw new InvalidOperationException("A2A_AGENT_HOST is not set."); + +A2ACardResolver agentCardResolver = new(new Uri(a2aAgentHost)); +AIAgent agent = await agentCardResolver.GetAIAgentAsync(); + +AgentResponse response = await agent.RunAsync("Tell me a joke about a pirate."); +Console.WriteLine(response); diff --git a/dotnet/samples/02-agents/A2A/A2AAgent_BasicUsage/README.md b/dotnet/samples/02-agents/A2A/A2AAgent_BasicUsage/README.md new file mode 100644 index 00000000000..8536f11b2ba --- /dev/null +++ b/dotnet/samples/02-agents/A2A/A2AAgent_BasicUsage/README.md @@ -0,0 +1,29 @@ +# A2A Agent Basic Usage + +This sample shows how to send a single message to an existing A2A agent and receive its response using default settings. +It discovers the remote agent's card using `A2ACardResolver`, creates an `A2AAgent` through +`GetAIAgentAsync()`, and uses the standard `AIAgent.RunAsync()` method to send a prompt and print the response. + +## Prerequisites + +- .NET 10.0 SDK or later +- A running A2A agent server that exposes an agent card and an HTTP+JSON or JSON-RPC interface + +If you do not have an A2A server, you can run the +[local echo agent](https://github.com/a2aproject/a2a-dotnet/blob/main/samples/AgentServer/README.md). +For this server, set `A2A_AGENT_HOST` to `http://localhost:5048`. + +## Run the sample + +From the repository root: + +```powershell +cd dotnet\samples\02-agents\A2A\A2AAgent_BasicUsage +$env:A2A_AGENT_HOST="https://your-a2a-agent-host" # Replace with your A2A agent host endpoint +dotnet run +``` + +The sample prints the remote agent's response to "Tell me a joke about a pirate." +The echo agent repeats the prompt instead of generating a joke. + +For more advanced scenarios, see the other [A2A samples](../README.md). diff --git a/dotnet/samples/02-agents/A2A/README.md b/dotnet/samples/02-agents/A2A/README.md index 0e6d52e95bc..6dcea7e9e83 100644 --- a/dotnet/samples/02-agents/A2A/README.md +++ b/dotnet/samples/02-agents/A2A/README.md @@ -1,6 +1,7 @@ # Agent-to-Agent (A2A) Samples -These samples demonstrate how to work with Agent-to-Agent (A2A) specific features in the Agent Framework. +These samples demonstrate how to use Agent-to-Agent (A2A) agents in the Agent Framework. +Start with [A2A Agent Basic Usage](./A2AAgent_BasicUsage/) for a minimal example using default settings. For other samples that demonstrate how to use AIAgent instances, see the [Getting Started With Agents](../Agents/README.md) samples. @@ -13,6 +14,7 @@ See the README.md for each sample for the prerequisites for that sample. |Sample|Description| |---|---| +|[A2A Agent Basic Usage](./A2AAgent_BasicUsage/)|Send a single message to an existing A2A agent using default settings and display the response.| |[A2A Agent as a Function Tool](./A2AAgent_AsFunctionTool/)|This sample demonstrates how to expose an A2A agent as a single function tool that another AI agent can call.| |[A2A Agent Skills](./A2AAgent_Skills/)|This sample demonstrates how to expose each skill advertised by an A2A agent as a separate function tool.| |[A2A Agent Polling For Task Completion](./A2AAgent_PollingForTaskCompletion/)|This sample demonstrates how to poll for long-running task completion using continuation tokens with an A2A agent.| @@ -24,7 +26,7 @@ See the README.md for each sample for the prerequisites for that sample. To run the samples, navigate to the desired sample directory, e.g. ```powershell -cd A2AAgent_AsFunctionTool +cd A2AAgent_BasicUsage ``` Set the required environment variables as documented in the sample readme.