Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a1506c4
Remove existing HTTP/HTTPS endpoints before adding new ones in run mode
Apr 13, 2026
4a66ae7
include sample for foundry hosted agents
Apr 13, 2026
abbb568
Refactor PublishAsHostedAgent method to accept resources with endpoin…
Apr 13, 2026
b4ea257
updates foundry names
Apr 13, 2026
2f9be79
Update playground/FoundryHostedAgents/FoundryHostedAgents.AppHost/app…
tommasodotNET Apr 14, 2026
038a43d
Fix: Update HTTP endpoint proxying behavior in run mode test
Apr 14, 2026
801c8fa
Merge branch 'fix/hosted-agent-overwrite-http-endpoints' of github.co…
Apr 14, 2026
2793d22
Update src/Aspire.Hosting.Foundry/HostedAgent/HostedAgentBuilderExten…
tommasodotNET Apr 14, 2026
c52d654
adds dotnet example
Apr 14, 2026
541b4e1
Merge branch 'fix/hosted-agent-overwrite-http-endpoints' of github.co…
Apr 14, 2026
d0a5b80
reverts foundry names in sample
Apr 14, 2026
5b02382
allow multiple hosted agents to run locally by configuring different …
Apr 14, 2026
dd27397
update Microsoft.Agents.AI.OpenAI and OpenAI package versions to late…
Apr 14, 2026
4f41344
add Azure.AI.AgentServer package source and remove unused project ref…
Apr 14, 2026
cc944ce
set DefaultTargetFramework on samples
Apr 14, 2026
a92606b
fixes on the playground
Apr 14, 2026
e187d4b
refactor: streamline container resource deployment logic in HostedAge…
Apr 14, 2026
85b4a41
-fix apphost var ref
Apr 14, 2026
5aa7773
chore: update Microsoft.Agents.AI.OpenAI and Microsoft.Extensions.AI …
Apr 14, 2026
f320db2
adds end2end test
Apr 14, 2026
094aea5
fix: preserve existing HTTP endpoint target port in run mode
Apr 14, 2026
8af2bb5
fix: reorder method calls for clarity in hosted agent configuration
Apr 14, 2026
4a7bc24
fix: reorder method calls to ensure proper reference waiting in hoste…
Apr 14, 2026
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
3 changes: 3 additions & 0 deletions Aspire.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@
<Folder Name="/playground/FoundryAgentEnterprise/">
<Project Path="playground/FoundryAgentEnterprise/FoundryAgentEnterprise.AppHost/FoundryAgentEnterprise.AppHost.csproj" />
</Folder>
<Folder Name="/playground/FoundryHostedAgents/">
<Project Path="playground/FoundryHostedAgents/DotNetHostedAgent/DotNetHostedAgent.csproj" />
</Folder>
<Folder Name="/playground/GitHubModelsEndToEnd/">
<Project Path="playground/GitHubModelsEndToEnd/GitHubModelsEndToEnd.AppHost/GitHubModelsEndToEnd.AppHost.csproj" />
<Project Path="playground/GitHubModelsEndToEnd/GitHubModelsEndToEnd.WebStory/GitHubModelsEndToEnd.WebStory.csproj" />
Expand Down
4 changes: 3 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
</PropertyGroup>
<ItemGroup>
<!-- Azure SDK for .NET dependencies -->
<PackageVersion Include="Azure.AI.AgentServer.AgentFramework" Version="1.0.0-beta.11" />
<PackageVersion Include="Azure.AI.Inference" Version="1.0.0-beta.5" />
<PackageVersion Include="Azure.AI.OpenAI" Version="2.5.0-beta.1" />
<PackageVersion Include="Azure.AI.Projects" Version="1.2.0-beta.4" />
Expand Down Expand Up @@ -105,6 +106,7 @@
<PackageVersion Include="JsonPatch.Net" Version="3.3.0" />
<PackageVersion Include="Markdig" Version="0.45.0" />
<PackageVersion Include="Microsoft.AI.Foundry.Local" Version="0.3.0" />
<PackageVersion Include="Microsoft.Agents.AI.OpenAI" Version="1.1.0" />
<PackageVersion Include="Microsoft.Data.SqlClient" Version="6.1.4" />
<PackageVersion Include="Microsoft.FluentUI.AspNetCore.Components" Version="4.14.0" />
<PackageVersion Include="Microsoft.FluentUI.AspNetCore.Components.Icons" Version="4.14.0" />
Expand All @@ -117,7 +119,7 @@
<PackageVersion Include="NATS.Net" Version="2.7.2" />
<PackageVersion Include="NCrontab.Signed" Version="3.4.0" />
<PackageVersion Include="Npgsql.DependencyInjection" Version="10.0.1" />
<PackageVersion Include="OpenAI" Version="2.8.0" />
<PackageVersion Include="OpenAI" Version="2.9.1" />
<PackageVersion Include="Oracle.ManagedDataAccess.OpenTelemetry" Version="23.26.100" />
<PackageVersion Include="Polly.Core" Version="8.6.5" />
<PackageVersion Include="Polly.Extensions" Version="8.6.5" />
Expand Down
24 changes: 24 additions & 0 deletions playground/FoundryHostedAgents/DotNetHostedAgent/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>$(DefaultTargetFramework)</TargetFrameworks>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<EnablePreviewFeatures>true</EnablePreviewFeatures>
</PropertyGroup>

<ItemGroup>
<PackageVersion Update="Microsoft.Extensions.AI" Version="10.4.0" />
<PackageVersion Update="Microsoft.Extensions.AI.OpenAI" Version="10.4.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Remove="Microsoft.CodeAnalysis.NetAnalyzers" />
<PackageReference Remove="Microsoft.VisualStudio.Threading.Analyzers" />
<PackageReference Remove="xunit.analyzers" />
<PackageReference Remove="Moq.Analyzers" />
<PackageReference Remove="Roslynator.Analyzers" />
<PackageReference Remove="Roslynator.CodeAnalysis.Analyzers" />
<PackageReference Remove="Roslynator.Formatting.Analyzers" />
<PackageReference Include="Azure.AI.AgentServer.AgentFramework" />
<PackageReference Include="Azure.AI.Projects" />
<PackageReference Include="Azure.AI.OpenAI" />
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Microsoft.Agents.AI.OpenAI" />
<PackageReference Include="Microsoft.Extensions.AI" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" />
</ItemGroup>

</Project>
90 changes: 90 additions & 0 deletions playground/FoundryHostedAgents/DotNetHostedAgent/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// 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.AgentServer.AgentFramework.Extensions;
using Azure.AI.OpenAI;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;

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

DbConnectionStringBuilder chatConnectionBuilder = new()
{
ConnectionString = chatConnectionString,
};

string endpoint = GetRequiredConnectionValue(chatConnectionBuilder, "Endpoint");
string deploymentName = GetRequiredConnectionValue(chatConnectionBuilder, "Deployment");

if (!Uri.TryCreate(endpoint, UriKind.Absolute, out Uri? openAiEndpoint) || openAiEndpoint is null)
{
throw new InvalidOperationException("ConnectionStrings__chat contains an invalid Endpoint value.");
}

Console.WriteLine($"OpenAI Endpoint: {openAiEndpoint}");
Console.WriteLine($"Model Deployment: {deploymentName}");

// Read the port from environment variable (set by Aspire), default to 8088
string? portString = Environment.GetEnvironmentVariable("DEFAULT_AD_PORT");
int port = int.TryParse(portString, out int parsedPort) ? parsedPort : 8088;

[Description("Get a weather forecast")]
WeatherForecast[]? GetWeatherForecast()
{
string[] summaries = ["Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"];
var forecast = Enumerable.Range(1, 5).Select(index =>
new WeatherForecast
(
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
Random.Shared.Next(-20, 55),
summaries[Random.Shared.Next(summaries.Length)]
))
.ToArray();
return forecast;
}

DefaultAzureCredential credential = new();

IChatClient chatClient = new AzureOpenAIClient(openAiEndpoint, credential)
.GetChatClient(deploymentName)
.AsIChatClient()
.AsBuilder()
.UseOpenTelemetry(sourceName: "Agents", configure: cfg => cfg.EnableSensitiveData = true)
.Build();

AIAgent agent = chatClient.AsAIAgent(
name: "WeatherAgent",
instructions: """You are the Weather Intelligence Agent that can return weather forecast using your tools.""",
tools: [AIFunctionFactory.Create(GetWeatherForecast)])
.AsBuilder()
.UseOpenTelemetry(sourceName: "Agents", configure: cfg => cfg.EnableSensitiveData = true)
.Build();

Console.WriteLine($"Weather Agent Server running on http://localhost:{port}");
await agent.RunAIAgentAsync(telemetrySourceName: "Agents");

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

string? value = rawValue.ToString();

if (string.IsNullOrWhiteSpace(value))
{
throw new InvalidOperationException($"ConnectionStrings__chat has an empty '{key}' value.");
}

return value;
}

internal sealed record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
{
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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.Foundry;

var builder = DistributedApplication.CreateBuilder(args);

var foundry = builder.AddFoundry("aif-myfoundry");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've tried adding one. not sure if it's correct, though

var project = foundry.AddProject("proj-myproject");
var chat = project.AddModelDeployment("chat", FoundryModel.OpenAI.Gpt41);

builder.AddPythonApp("weather-hosted-agent", "../app", "main.py")
.WithUv()
.WithReference(chat).WaitFor(chat)
.PublishAsHostedAgent(project);

builder.AddProject<Projects.DotNetHostedAgent>("proj-dotnet-hosted-agent")
.WithEndpoint("http", e => e.TargetPort = 9000)
.WithReference(chat).WaitFor(chat)
.PublishAsHostedAgent(project);

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>$(DefaultTargetFramework)</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireHost>true</IsAspireHost>
<UserSecretsId>232bfcff-4739-4857-9b6f-6d7681cb0980</UserSecretsId>
</PropertyGroup>

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

<ItemGroup>
<AspireProjectOrPackageReference Include="Aspire.Hosting.Azure" />
<AspireProjectOrPackageReference Include="Aspire.Hosting.Foundry" />
<AspireProjectOrPackageReference Include="Aspire.Hosting.AppHost" />
<AspireProjectOrPackageReference Include="Aspire.Hosting.Python" />
<ProjectReference Include="../DotNetHostedAgent/DotNetHostedAgent.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:17145;http://localhost:15099",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21011",
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22200"
}
},
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:15099",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19103",
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20134",
"ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true"
}
},
"generate-manifest": {
"commandName": "Project",
"launchBrowser": true,
"dotnetRunMessages": true,
"commandLineArgs": "--publisher manifest --output-path aspire-manifest.json",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Aspire.Hosting.Dcp": "Warning"
}
}
}
7 changes: 7 additions & 0 deletions playground/FoundryHostedAgents/app/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Byte-compiled / optimized / DLL files
**/__pycache__/
**/*.py[cod]

# Virtual environment
.env
.venv/
63 changes: 63 additions & 0 deletions playground/FoundryHostedAgents/app/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import asyncio
import datetime
import json
import os
import random

# Microsoft Agent Framework
from agent_framework import Agent, tool
from agent_framework.azure import AzureOpenAIChatClient
from azure.ai.agentserver.agentframework import from_agent_framework
from azure.identity import DefaultAzureCredential

@tool(name="get_forecast", description="Get a weather forecast")
async def get_forecast() -> str:
try:
summaries = [
"Freezing",
"Bracing",
"Chilly",
"Cool",
"Mild",
"Warm",
"Balmy",
"Hot",
"Sweltering",
"Scorching",
]

forecast = []
for index in range(1, 6): # Range 1 to 5 (inclusive)
temp_c = random.randint(-20, 55)
forecast_date = datetime.datetime.now() + datetime.timedelta(days=index)
forecast_item = {
"date": forecast_date.isoformat(),
"temperatureC": temp_c,
"temperatureF": int(temp_c * 9 / 5) + 32,
"summary": random.choice(summaries),
}
forecast.append(forecast_item)

return json.dumps(forecast, indent=2)
except Exception as e:
return json.dumps({"error": str(e)})

async def main():
"""Main function to run the agent as a web server."""

# client = FoundryChatClient(project_endpoint=os.getenv("CHAT_URI"), credential=AzureCliCredential(), model="chat")
agent = AzureOpenAIChatClient(endpoint=os.getenv("CHAT_URI"), credential=DefaultAzureCredential(), deployment_name="chat").as_agent(
# client = client,
name="weather-agent",
instructions="""You are the Weather Intelligence Agent that can return weather forecast using your tools.""",
tools=[get_forecast],
)


app = from_agent_framework(agent)

await app.run_async()


if __name__ == "__main__":
asyncio.run(main())
14 changes: 14 additions & 0 deletions playground/FoundryHostedAgents/app/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[project]
name = "weather-agent-python"
version = "0.1.0"
description = "Weather intelligence agent for AlpineAI ski resort"
requires-python = ">=3.11"
dependencies = [
"fastapi>=0.104.1",
"agent-framework",
"azure-ai-agentserver-agentframework>=1.0.0b17",
"azure-identity",
]

[tool.uv]
prerelease = "allow"
5 changes: 5 additions & 0 deletions playground/FoundryHostedAgents/aspire.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"appHost": {
"path": "FoundryHostedAgents.AppHost/FoundryHostedAgents.AppHost.csproj"
}
}
Loading
Loading