Skip to content

Fixes Foundry Hosted Agents HTTP endpoints#16130

Open
tommasodotNET wants to merge 20 commits intomicrosoft:mainfrom
tommasodotNET:fix/hosted-agent-overwrite-http-endpoints
Open

Fixes Foundry Hosted Agents HTTP endpoints#16130
tommasodotNET wants to merge 20 commits intomicrosoft:mainfrom
tommasodotNET:fix/hosted-agent-overwrite-http-endpoints

Conversation

@tommasodotNET
Copy link
Copy Markdown

@tommasodotNET tommasodotNET commented Apr 13, 2026

Description

Closes #16115. Overwrites existing http/https endpoints on resource to allow the creation of dedicated hosted agent endpoint. Does not hard code http port (letting aspire handle port assignment). PublishAsHostedAgent accepts generic resource with endpoint (e.g. ProjectResource) allowing hosted agents in dotnet (see also #15968).
Allows for custom targetPorts to allow locally run multiple hosted agents

Adds a playground sample for hosted agents in python

Fixes # (issue)

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

@tommasodotNET tommasodotNET requested a review from eerhardt April 13, 2026 21:07
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 13, 2026

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 16130

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 16130"

@tommasodotNET tommasodotNET marked this pull request as ready for review April 13, 2026 21:54
Copilot AI review requested due to automatic review settings April 13, 2026 21:54
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the Foundry hosted-agent run-mode behavior to avoid endpoint conflicts when PublishAsHostedAgent is applied to resources that already define HTTP endpoints, and adds a new playground sample for hosted agents.

Changes:

  • In run mode, removes existing HTTP/HTTPS endpoint annotations before adding the hosted-agent HTTP endpoint.
  • Refactors publish-mode containerization to explicitly handle ProjectResource vs ExecutableResource.
  • Adds a playground/FoundryHostedAgents sample (AppHost + Python agent app scaffolding).

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/Aspire.Hosting.Foundry.Tests/HostedAgentExtensionTests.cs Adds tests asserting hosted-agent run-mode endpoint overwrite behavior and non-hardcoded port behavior.
src/Aspire.Hosting.Foundry/HostedAgent/HostedAgentBuilderExtension.cs Implements endpoint removal in run mode and adjusts publish-mode containerization logic.
playground/FoundryHostedAgents/aspire.config.json Adds Aspire config pointing to the new playground AppHost.
playground/FoundryHostedAgents/app/pyproject.toml Adds Python agent sample dependencies/config.
playground/FoundryHostedAgents/app/main.py Adds Python agent sample implementation.
playground/FoundryHostedAgents/app/.dockerignore Adds Docker ignore rules for the Python sample.
playground/FoundryHostedAgents/FoundryHostedAgents.AppHost/appsettings.json Adds logging configuration for the new AppHost sample.
playground/FoundryHostedAgents/FoundryHostedAgents.AppHost/appsettings.Development.json Adds development Azure settings for the sample (currently includes specific identifiers).
playground/FoundryHostedAgents/FoundryHostedAgents.AppHost/Properties/launchSettings.json Adds launch profiles for the new AppHost sample.
playground/FoundryHostedAgents/FoundryHostedAgents.AppHost/FoundryHostedAgents.AppHost.csproj Adds a new AppHost project file for the playground sample.
playground/FoundryHostedAgents/FoundryHostedAgents.AppHost/AppHost.cs Adds the new playground AppHost wiring for Foundry + Python hosted agent.

tommasodotNET and others added 7 commits April 14, 2026 08:45
…settings.Development.json

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…m:tommasodotNET/aspire into fix/hosted-agent-overwrite-http-endpoints
…sion.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…m:tommasodotNET/aspire into fix/hosted-agent-overwrite-http-endpoints
@tommasodotNET
Copy link
Copy Markdown
Author

tommasodotNET commented Apr 14, 2026

UPDATE: instead of removing the existing endpoints, we can overwrite them. looks like a better solution. The fix still enables use with dotnet hosted agents (sample added).
We also allow custom targetPorts to handle multiple local hosted agents

@tommasodotNET tommasodotNET changed the title Remove existing HTTP/HTTPS endpoints before adding new ones in run mode Fixes Foundry Hosted Agents HTTP endpoints Apr 14, 2026

var tenantId = builder.AddParameterFromConfiguration("tenant", "Azure:TenantId");

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

.AddProject("my-project");

var app = builder.AddPythonApp("agent", "./app.py", "main:app")
.WithHttpEndpoint(name: "http", targetPort: 5000)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
.WithHttpEndpoint(name: "http", targetPort: 5000)
.WithHttpEndpoint(targetPort: 5000)

Assert.True(app.Resource.TryGetEndpoints(out var endpoints));
var httpEndpoints = endpoints.Where(e => e.Name == "http").ToList();
Assert.Single(httpEndpoints);
Assert.Equal(8088, httpEndpoints[0].TargetPort);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

? shouldn't this be 5000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Foundry Hosted Agent should overwrite existing HTTP Endpoints

5 participants