Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dotnet/agent-framework-dotnet.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@
</Folder>
<Folder Name="/Samples/02-agents/A2A/">
<File Path="samples/02-agents/A2A/README.md" />
<Project Path="samples/02-agents/A2A/A2AAgent_BasicUsage/A2AAgent_BasicUsage.csproj" />
<Project Path="samples/02-agents/A2A/A2AAgent_AsFunctionTool/A2AAgent_AsFunctionTool.csproj" />
<Project Path="samples/02-agents/A2A/A2AAgent_Skills/A2AAgent_Skills.csproj" />
<Project Path="samples/02-agents/A2A/A2AAgent_PollingForTaskCompletion/A2AAgent_PollingForTaskCompletion.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net10.0</TargetFrameworks>

<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="A2A" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\src\Microsoft.Agents.AI.A2A\Microsoft.Agents.AI.A2A.csproj" />
</ItemGroup>

</Project>
14 changes: 14 additions & 0 deletions dotnet/samples/02-agents/A2A/A2AAgent_BasicUsage/Program.cs
Original file line number Diff line number Diff line change
@@ -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);
29 changes: 29 additions & 0 deletions dotnet/samples/02-agents/A2A/A2AAgent_BasicUsage/README.md
Original file line number Diff line number Diff line change
@@ -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).
6 changes: 4 additions & 2 deletions dotnet/samples/02-agents/A2A/README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.|
Expand All @@ -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.
Expand Down
Loading