Skip to content

Foundry hosted agent deployment fails when endpoint has targetPort #17803

@tommasodotNET

Description

@tommasodotNET

Describe the bug

Deploying a Foundry hosted agent fails when the underlying project endpoint is configured with WithHttpEndpoint(targetPort: 9000) before calling AsHostedAgent(project).

The deployment pipeline rejects the generated hosted agent endpoint because it contains the TargetPort endpoint property:

19:47:37 (deploy-proj-dotnet-hosted-agent-ha) ✗ [ERR] Step 'deploy-proj-dotnet-hosted-agent-ha' failed.
19:47:37 (deploy-proj-dotnet-hosted-agent-ha) ✗ Step 'deploy-proj-dotnet-hosted-agent-ha' failed: The endpoint property 'TargetPort' is
not supported for Foundry hosted agent endpoints. Only 'Url' and 'Scheme' are supported.
19:47:37 (pipeline-execution) ✗ [ERR] Step 'deploy-proj-dotnet-hosted-agent-ha' failed: The endpoint property 'TargetPort' is not 
supported for Foundry hosted agent endpoints. Only 'Url' and 'Scheme' are supported.

It looks like AsHostedAgent(...)/deployment export is carrying through the TargetPort metadata from the Aspire project endpoint, but Foundry hosted agent endpoints only accept Url and Scheme.

Repro

Minimal AppHost from the repro repository:

#:sdk Aspire.AppHost.Sdk@13.4.0
#:package Aspire.Hosting.Foundry@13.4.0-preview.1.26281.15
#:package Aspire.Hosting.Python@13.4.0

#:project ./DotNetHostedAgent/DotNetHostedAgent.csproj

using Aspire.Hosting.Foundry;

var builder = DistributedApplication.CreateBuilder(args);

var foundry = builder.AddFoundry("aifskiresort");
var project = foundry.AddProject("projvoiceskiresort");
var chat = project.AddModelDeployment("gpt41", FoundryModel.OpenAI.Gpt41)
    .WithProperties(configure => configure.SkuCapacity = 10);

builder.AddProject<Projects.DotNetHostedAgent>("proj-dotnet-hosted-agent")
    .WithHttpEndpoint(targetPort: 9000)
    .WithReference(chat).WaitFor(chat)
    .AsHostedAgent(project);

builder.Build().Run();

The hosted agent app itself binds to the Aspire-provided DEFAULT_AD_PORT environment variable:

string port = Environment.GetEnvironmentVariable("DEFAULT_AD_PORT") ?? "8088";
builder.WebHost.UseUrls($"http://+:{port}");

Steps:

  1. Create/use the AppHost above with a web project converted to a Foundry hosted agent via .AsHostedAgent(project).
  2. Deploy the Aspire app.
  3. Observe the hosted agent deploy step fails with the TargetPort unsupported error.

Expected behavior

Deployment should succeed, or the Foundry hosted agent deployment/export path should omit/translate endpoint properties that Foundry hosted agent endpoints do not support.

If targetPort is fundamentally unsupported for hosted agents, Aspire should ideally fail earlier during AppHost validation with an actionable error rather than failing during the deployment step.

Actual behavior

The deployment pipeline fails at the hosted agent deployment step because the endpoint includes TargetPort, even though the endpoint was configured using the normal Aspire .WithHttpEndpoint(targetPort: 9000) API.

Versions

  • AppHost SDK: Aspire.AppHost.Sdk@13.4.0
  • Foundry hosting package: Aspire.Hosting.Foundry@13.4.0-preview.1.26281.15
  • AppHost style: C# file-based AppHost (apphost.cs)
  • Hosted project target framework: net10.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No fields configured for Bug.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions