Skip to content
Open
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
4 changes: 4 additions & 0 deletions Aspire.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<Project Path="src/Aspire.Cli/Aspire.Cli.csproj" />
<Project Path="src/Aspire.Dashboard/Aspire.Dashboard.csproj" />
<Project Path="src/Aspire.Hosting.Analyzers/Aspire.Hosting.Analyzers.csproj" />
<Project Path="src/Aspire.Hosting.Agents/Aspire.Hosting.Agents.csproj" />
<Project Path="src/Aspire.Hosting.Integration.Analyzers/Aspire.Hosting.Integration.Analyzers.csproj" />
<Project Path="src/Aspire.Hosting.AppHost/Aspire.Hosting.AppHost.csproj" />
<Project Path="src/Aspire.Hosting.Browsers/Aspire.Hosting.Browsers.csproj" />
Expand Down Expand Up @@ -116,6 +117,8 @@
<File Path="playground/Directory.Build.props" />
<File Path="playground/Directory.Build.targets" />
<File Path="playground/README.md" />
<Project Path="playground/AspireAgents/AspireAgents.AppHost/AspireAgents.AppHost.csproj" />
<Project Path="playground/AspireAgents/ResponsesAgent/ResponsesAgent.csproj" />
<Project Path="playground/Playground.ServiceDefaults/Playground.ServiceDefaults.csproj" />
</Folder>
<Folder Name="/playground/BlazorHosted/">
Expand Down Expand Up @@ -498,6 +501,7 @@
</Folder>
<Folder Name="/tests/Hosting/">
<Project Path="tests/Aspire.Hosting.Analyzers.Tests/Aspire.Hosting.Analyzers.Tests.csproj" />
<Project Path="tests/Aspire.Hosting.Agents.Tests/Aspire.Hosting.Agents.Tests.csproj" />
<Project Path="tests/Aspire.Hosting.Foundry.Tests/Aspire.Hosting.Foundry.Tests.csproj" />
<Project Path="tests/Aspire.Hosting.Azure.Kusto.Tests/Aspire.Hosting.Azure.Kusto.Tests.csproj" />
<Project Path="tests/Aspire.Hosting.Azure.Kubernetes.Tests/Aspire.Hosting.Azure.Kubernetes.Tests.csproj" />
Expand Down
56 changes: 56 additions & 0 deletions playground/AspireAgents/AspireAgents.AppHost/AppHost.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Aspire.Hosting.Agents;
using Aspire.Hosting.Foundry;

#pragma warning disable ASPIREMCP001

var builder = DistributedApplication.CreateBuilder(args);

var foundry = builder.AddFoundry("agents-foundry");
var project = foundry.AddProject("agentsproject");
var chat = project.AddModelDeployment("chat", FoundryModel.OpenAI.Gpt41Mini);

var a2aAgent = builder.AddUvicornApp("a2a-jsonrpc-agent", "../weather-agent-python", "weather_agent_python.main:app")
.WithUv()
.WithReference(project)
.WithReference(chat)
.WaitFor(chat)
.AsAgent(AgentProtocol.A2A);

builder.AddProject<Projects.ResponsesAgent>("responses-agent")
.WithHttpEndpoint(env: "PORT")
.WithReference(chat)
.WithReference(a2aAgent)
.WaitFor(chat)
.AsAgent(AgentProtocol.Responses)
.WithMcpServer();

builder.AddProject<Projects.McpAgent>("mcp-agent")
.WithHttpEndpoint(env: "PORT")
.WithReference(chat)
.WaitFor(chat)
.WithMcpServer();

builder.AddUvicornApp("agui-acp-agent", "../agui-acp-agent-python", "agui_acp_agent.main:app")
.WithUv()
.WithReference(project)
.WithReference(chat)
.WaitFor(chat)
.AsAgent(AgentProtocol.AgUi)
.AsAgent(AgentProtocol.Acp);

builder.AddExecutable(
"agent-env-dump",
"sh",
".",
"-c",
"echo A2A_JSONRPC_AGENT_AGENTCARD_URL=$A2A_JSONRPC_AGENT_AGENTCARD_URL && sleep 3600")
.WithReference(a2aAgent).WaitFor(a2aAgent);

#if !SKIP_DASHBOARD_REFERENCE
builder.AddProject<Projects.Aspire_Dashboard>(KnownResourceNames.AspireDashboard);
#endif

builder.Build().Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireHost>true</IsAspireHost>
<UserSecretsId>e1c0f8c6-8b6b-4e42-84f3-59c0135a60ce</UserSecretsId>
<NoWarn>$(NoWarn);ASPIRECOMPUTE001;ASPIREPIPELINES001;ASPIREAZURE001;ASPIREPIPELINES003</NoWarn>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\..\KnownResourceNames.cs" Link="KnownResourceNames.cs" />
</ItemGroup>

<ItemGroup>
<AspireProjectOrPackageReference Include="Aspire.Hosting.AppHost" />
<AspireProjectOrPackageReference Include="Aspire.Hosting.Agents" />
<AspireProjectOrPackageReference Include="Aspire.Hosting.Foundry" />
<AspireProjectOrPackageReference Include="Aspire.Hosting.Python" />
<ProjectReference Include="..\McpAgent\McpAgent.csproj" />
<ProjectReference Include="..\ResponsesAgent\ResponsesAgent.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:43799;http://localhost:43800",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21012",
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22201"
}
},
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:43800",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19104",
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20135",
"ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true"
}
}
}
}
16 changes: 16 additions & 0 deletions playground/AspireAgents/McpAgent/McpAgent.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" />
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" />
<PackageReference Include="ModelContextProtocol.AspNetCore" VersionOverride="1.3.0" />
</ItemGroup>

</Project>
74 changes: 74 additions & 0 deletions playground/AspireAgents/McpAgent/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.ComponentModel;
using System.Data.Common;
using Azure.AI.OpenAI;
using Azure.Identity;
using Microsoft.Extensions.AI;
using ModelContextProtocol.Server;

var chatConnectionString = Environment.GetEnvironmentVariable("ConnectionStrings__chat")
?? throw new InvalidOperationException("ConnectionStrings__chat is not set.");

DbConnectionStringBuilder chatConnectionBuilder = new() { ConnectionString = chatConnectionString };
var endpoint = GetRequiredConnectionValue(chatConnectionBuilder, "Endpoint");
var deploymentName = GetRequiredConnectionValue(chatConnectionBuilder, "Deployment");

var builder = WebApplication.CreateBuilder(args);
builder.WebHost.UseUrls($"http://+:{Environment.GetEnvironmentVariable("PORT") ?? "8080"}");

QuestionTools.Initialize(
new AzureOpenAIClient(new Uri(endpoint), new DefaultAzureCredential())
.GetChatClient(deploymentName)
.AsIChatClient());

builder.Services
.AddMcpServer()
.WithHttpTransport()
.WithTools<QuestionTools>();

var app = builder.Build();

app.MapGet("/health", () => Results.Ok("Healthy"));
app.MapMcp("/mcp");

app.Run();

static string GetRequiredConnectionValue(DbConnectionStringBuilder connectionBuilder, string key)
{
if (!connectionBuilder.TryGetValue(key, out var rawValue) || rawValue is null)
{
throw new InvalidOperationException($"Connection string is missing '{key}'.");
}

var value = rawValue.ToString();
if (string.IsNullOrWhiteSpace(value))
{
throw new InvalidOperationException($"Connection string has an empty '{key}' value.");
}

return value;
}

[McpServerToolType]
public sealed class QuestionTools
{
private static IChatClient? s_chatClient;

public static void Initialize(IChatClient chatClient)
{
s_chatClient = chatClient;
}

[McpServerTool(Name = "answer_question")]
[Description("Uses the Foundry model deployment to answer a question.")]
public static async Task<string> AnswerQuestion([Description("The question to answer.")] string question)
{
var chatClient = s_chatClient ?? throw new InvalidOperationException("The chat client is not initialized.");
var response = await chatClient.GetResponseAsync(
$"You are a concise MCP agent. Answer this question: {question}");

return response.Text;
}
}
78 changes: 78 additions & 0 deletions playground/AspireAgents/ResponsesAgent/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.ComponentModel;
using System.Data.Common;
using Azure.AI.OpenAI;
using Azure.Identity;
using Microsoft.Agents.AI.Hosting;
using Microsoft.Extensions.AI;
using ModelContextProtocol.Server;

var chatConnectionString = Environment.GetEnvironmentVariable("ConnectionStrings__chat")
?? throw new InvalidOperationException("ConnectionStrings__chat is not set.");

DbConnectionStringBuilder chatConnectionBuilder = new() { ConnectionString = chatConnectionString };
var endpoint = GetRequiredConnectionValue(chatConnectionBuilder, "Endpoint");
var deploymentName = GetRequiredConnectionValue(chatConnectionBuilder, "Deployment");

var builder = WebApplication.CreateBuilder(args);
builder.WebHost.UseUrls($"http://+:{Environment.GetEnvironmentVariable("PORT") ?? "8080"}");

const string AgentName = "responses-agent";

var chatClient = new AzureOpenAIClient(new Uri(endpoint), new DefaultAzureCredential())
.GetChatClient(deploymentName)
.AsIChatClient();

builder.Services.AddChatClient(chatClient);

[Description("Get a weather forecast for a location.")]
static string GetWeather([Description("The location to get the weather for.")] string location)
{
return $"The weather in {location} is sunny with a high of 22 C.";
}

builder.AddAIAgent(AgentName, "You are a concise weather agent. Use tools when users ask for forecasts.")
.WithAITool(AIFunctionFactory.Create(GetWeather, name: "get_weather"));

builder.Services.AddOpenAIResponses();
builder.Services
.AddMcpServer()
.WithHttpTransport()
.WithTools<McpWeatherTools>();

var app = builder.Build();

app.MapOpenAIResponses();
app.MapMcp("/mcp");
app.MapGet("/health", () => Results.Ok("Healthy"));

app.Run();

static string GetRequiredConnectionValue(DbConnectionStringBuilder connectionBuilder, string key)
{
if (!connectionBuilder.TryGetValue(key, out var rawValue) || rawValue is null)
{
throw new InvalidOperationException($"Connection string is missing '{key}'.");
}

var value = rawValue.ToString();
if (string.IsNullOrWhiteSpace(value))
{
throw new InvalidOperationException($"Connection string has an empty '{key}' value.");
}

return value;
}

[McpServerToolType]
public sealed class McpWeatherTools
{
[McpServerTool(Name = "get_weather")]
[Description("Returns a sample weather forecast.")]
public static string GetWeather([Description("The location to forecast.")] string location)
{
return $"The weather in {location} is sunny with a high of 22 C.";
}
}
18 changes: 18 additions & 0 deletions playground/AspireAgents/ResponsesAgent/ResponsesAgent.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<NoWarn>$(NoWarn);MAIF001;OPENAI001</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" />
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Microsoft.Agents.AI.Hosting.OpenAI" VersionOverride="1.7.0-alpha.260526.1" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" />
<PackageReference Include="ModelContextProtocol.AspNetCore" VersionOverride="1.3.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""AG-UI and ACP agent playground package."""
Loading
Loading