Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
39 changes: 39 additions & 0 deletions playground/AspireAgents/AspireAgents.AppHost/AppHost.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 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;

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("weather-a2a-agent", "../weather-agent-python", "weather_agent_python.main:app")
.WithUv()
.WithReference(project)
.WithReference(chat)
.WaitFor(chat)
.AsAgent(AgentProtocol.A2AJsonRpc);

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

builder.AddExecutable(
"agent-env-dump",
"sh",
".",
"-c",
"echo WEATHER_A2A_AGENT_AGENTCARD_URL=$WEATHER_A2A_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,24 @@
<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.Foundry" />
<AspireProjectOrPackageReference Include="Aspire.Hosting.Python" />
<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"
}
}
}
}
61 changes: 61 additions & 0 deletions playground/AspireAgents/ResponsesAgent/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// 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;

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 = "weather-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();

var app = builder.Build();

app.MapOpenAIResponses();
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;
}
17 changes: 17 additions & 0 deletions playground/AspireAgents/ResponsesAgent/ResponsesAgent.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<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" />
</ItemGroup>

</Project>
5 changes: 5 additions & 0 deletions playground/AspireAgents/aspire.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"appHost": {
"path": "AspireAgents.AppHost/AspireAgents.AppHost.csproj"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.13
26 changes: 26 additions & 0 deletions playground/AspireAgents/weather-agent-python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[project]
name = "aspire-agents-weather-a2a"
version = "0.1.0"
description = "A2A weather agent playground for Aspire"
requires-python = ">=3.13"
dependencies = [
"agent-framework",
"agent-framework-a2a",
"agent-framework-azure",
"azure-identity>=1.25.0",
"fastapi>=0.119.0",
"opentelemetry-distro>=0.59b0",
"opentelemetry-exporter-otlp-proto-grpc>=1.38.0",
"opentelemetry-instrumentation-fastapi>=0.59b0",
"uvicorn>=0.37.0",
]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build.targets.wheel]
packages = ["weather_agent_python"]

[tool.uv]
prerelease = "allow"
Loading
Loading