Skip to content
Closed
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
6 changes: 5 additions & 1 deletion src/frontend/scripts/generate-twoslash-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ interface FunctionEntry {
interface DtoField {
name: string;
type: string;
isOptional?: boolean;
isNullable?: boolean;
}

interface DtoType {
Expand Down Expand Up @@ -690,9 +692,11 @@ for (const dto of dtoTypes) {
parts.push(`export interface ${dto.name} {`);
for (const f of dto.fields) {
const t = cleanType(f.type);
const optional = f.isOptional ? '?' : '';
const nullable = f.isNullable ? ' | null' : '';
extractTypeIdentifiers(t, referencedTypes);
scanExprForGenerics(t);
parts.push(` ${camelCase(f.name)}: ${t};`);
parts.push(` ${camelCase(f.name)}${optional}: ${t}${nullable};`);
}
parts.push(`}`);
parts.push('');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ If you're new to the Azure AI Foundry integration, start with the [Get started w

To start building an Aspire app that uses Azure AI Foundry, install the [📦 Aspire.Hosting.Foundry](https://www.nuget.org/packages/Aspire.Hosting.Foundry) NuGet package:

<Tabs syncKey="aspire-lang">
<TabItem id="csharp" label="C#">
<Tabs syncKey='aspire-lang'>
<TabItem id='csharp' label='C#'>

```bash title="Terminal"
aspire add azure-ai-foundry
Expand Down Expand Up @@ -61,7 +61,7 @@ Or, choose a manual installation approach:
</Aside>

</TabItem>
<TabItem id="typescript" label="TypeScript">
<TabItem id='typescript' label='TypeScript'>

```bash title="Terminal"
aspire add azure-ai-foundry
Expand Down Expand Up @@ -464,6 +464,72 @@ In publish mode, Aspire creates an `AzureHostedAgentResource` and publishes the

For C# AppHosts, the parameterless `AsHostedAgent()` overload reuses an existing Foundry project from the app model or creates one automatically. TypeScript AppHosts pass the project resource explicitly.

### Select the hosted agent protocol

By default, Aspire configures a hosted agent for the `responses` protocol. If your agent implements the `invocations` protocol, configure the protocol versions when configuring the hosted agent in your AppHost. The selected protocol affects both run mode (dashboard URLs and the **Send Message** command) and publish mode (the `container_protocol_versions` field in the Foundry hosted agent definition).

<Tabs syncKey="aspire-lang">
<TabItem id="csharp" label="C#">

```csharp title="C# — AppHost.cs"
var builder = DistributedApplication.CreateBuilder(args);

var foundry = builder.AddFoundry("foundry");
var project = foundry.AddProject("my-project");
var chat = project.AddModelDeployment("chat", FoundryModel.OpenAI.Gpt5Mini);

builder.AddProject<Projects.Agent>("agent-dotnet")
.WithReference(project)
.WithReference(chat)
.AsHostedAgent(project, configuration =>

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.

Thanks for checking this. I’m leaving the C# snippet as-is because the source-of-truth branch confirms this API exists: microsoft/aspire@2574ef57e97fc393aff67592fd442afca6a6d02f (release/13.4) exposes AsHostedAgent<T>(..., Action<HostedAgentConfiguration>? configure = null) at src/Aspire.Hosting.Foundry/api/Aspire.Hosting.Foundry.cs:99-101, and HostedAgentConfiguration.ContainerProtocolVersions at src/Aspire.Hosting.Foundry/api/Aspire.Hosting.Foundry.cs:981-982. The docs metadata appears stale for this C# surface, but the checked-out source branch confirms the PR text is correct.

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.

Updating the source-truth citation for this rejection: microsoft/aspire@9c260c29a6c3f9a63750a518a56440a3d855fb8f on release/13.4 includes the C# API in src/Aspire.Hosting.Foundry/HostedAgent/HostedAgentBuilderExtension.cs; AsHostedAgent accepts configuration that updates ContainerProtocolVersions, and src/Aspire.Hosting.Foundry/HostedAgent/HostedAgentOptions.cs exposes the corresponding protocol options. The PR text for the C# sample remains correct as written, so I am leaving this unresolved for reviewer follow-up.

{
configuration.ContainerProtocolVersions.Clear();
configuration.ContainerProtocolVersions.Add(
new ProtocolVersionRecord(ProjectsAgentProtocol.Invocations, "1.0.0"));
});

builder.Build().Run();
```

</TabItem>
<TabItem id="typescript" label="TypeScript">

```typescript title="TypeScript — apphost.mts" twoslash
import { createBuilder } from './.aspire/modules/aspire.mjs';

const builder = await createBuilder();

const foundry = await builder.addFoundry('foundry');
const project = await foundry.addProject('my-project');
const chat = await project.addModelDeployment('chat', {
name: 'gpt-5-mini',
version: '2025-06-01',
format: 'OpenAI',
});

const agent = await builder
.addProject('agent-dotnet', '../Agent/Agent.csproj')
.withReference(project)
.withReference(chat);

await agent.asHostedAgent(project, {
protocols: [{ protocol: 'invocations', version: '1.0.0' }],
});

await builder.build().run();
```

</TabItem>
</Tabs>

When the first configured protocol version uses the `invocations` protocol, Aspire:

- Labels the run-mode dashboard endpoint as **Invocations Endpoint** and routes dashboard URLs to `/invocations` instead of `/responses`.
- Configures the **Send Message** dashboard command to POST to `/invocations`.
- Emits the selected protocol versions in the `container_protocol_versions` field of the Foundry hosted agent definition at publish time.

Multiple protocol versions can be listed. In run mode only the first entry is used to select the endpoint path; in publish mode all entries are forwarded to the hosted agent definition.

### Add and publish a prompt agent

For prompt-only scenarios, use `AddPromptAgent` on a Foundry project:
Expand Down Expand Up @@ -539,7 +605,7 @@ Prompt agents are deployed to Azure AI Foundry even during local development. Lo

## Invoke agents from the Aspire dashboard

Aspire also makes the declared agents easy to try from the dashboard. Prompt agents get a **Send Message** command from `AddPromptAgent(...)`. Hosted agents configured with `AsHostedAgent(...)` get a highlighted **Send Message** command that posts to the selected protocol path, which defaults to the local `/responses` endpoint.
Aspire also makes the declared agents easy to try from the dashboard. Prompt agents get a **Send Message** command from `AddPromptAgent(...)`. Hosted agents configured with `AsHostedAgent(...)` get a highlighted **Send Message** command that posts to the selected protocol path (`/responses` by default, or `/invocations` when the invocations protocol is configured), plus dashboard links for the protocol endpoint, `/liveness`, and `/readiness`.

<ThemeAwareImage
dark={agentSendMessage}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,45 @@
"Aspire.Hosting.Foundry.AzureCognitiveServicesProjectResource"
]
},
{
"name": "withComputeEnvironment",
"capabilityId": "Aspire.Hosting.Foundry/withComputeEnvironmentExecutable",
"qualifiedName": "withComputeEnvironment",
"description": "Configures the resource to run as a hosted agent in Microsoft Foundry. If a project resource is not provided, the method will attempt to find an existing Microsoft Foundry project resource in the application model. If none exists, a new project resource (and its parent account resource) will be created automatically.",
"remarks": "In run mode, this configures the resource with hosted agent endpoints, health checks,\nand OpenTelemetry settings. In publish mode, the resource is deployed as a hosted agent\nin Microsoft Foundry.",
"kind": "Method",
"signature": "withComputeEnvironment(project?: AzureCognitiveServicesProjectResource, configure?: (obj: HostedAgentConfiguration) => Promise<void>): IResourceWithEndpoints",
"parameters": [
{
"name": "project",
"type": "AzureCognitiveServicesProjectResource",
"isOptional": true
},
{
"name": "configure",
"type": "callback",
"isOptional": true,
"isCallback": true,
"callbackSignature": "(obj: HostedAgentConfiguration) => Promise<void>"
}
],
"returnType": "IResourceWithEndpoints",
"returnsBuilder": true,
"targetTypeId": "Aspire.Hosting/Aspire.Hosting.ApplicationModel.IResourceWithEndpoints",
"expandedTargetTypes": [
"Aspire.Hosting.ApplicationModel.ContainerResource",
"Aspire.Hosting.ApplicationModel.ExecutableResource",
"Aspire.Hosting.ApplicationModel.ProjectResource",
"Aspire.Hosting.ApplicationModel.DotnetToolResource",
"Aspire.Hosting.ApplicationModel.CSharpAppResource",
"Aspire.Hosting.Foundry.FoundryResource",
"Aspire.Hosting.AzureCosmosDBResource",
"Aspire.Hosting.Azure.AzureStorageResource",
"Aspire.Hosting.Azure.AzureKeyVaultResource",
"Aspire.Hosting.Azure.AzureCosmosDBEmulatorResource",
"Aspire.Hosting.Azure.AzureStorageEmulatorResource"
]
},
{
"name": "withFoundryRoleAssignments",
"capabilityId": "Aspire.Hosting.Foundry/withFoundryRoleAssignments",
Expand Down Expand Up @@ -3089,6 +3128,69 @@
}
],
"dtoTypes": [
{
"name": "HostedAgentOptions",
"fullName": "Aspire.Hosting.Foundry.HostedAgentOptions",
"kind": "dto",
"description": "Optional hosted agent deployment options.",
"fields": [
{
"name": "Description",
"type": "string",
"isOptional": true,
"isNullable": true,
"description": "The description of the hosted agent."
},
{
"name": "EnvironmentVariables",
"type": "Dict<string,string>",
"isOptional": true,
"description": "Environment variables to set on the hosted agent resource."
},
{
"name": "Cpu",
"type": "number",
"isOptional": true,
"description": "CPU allocation for each hosted agent instance, in vCPU cores."
},
{
"name": "Memory",
"type": "number",
"isOptional": true,
"description": "Memory allocation for each hosted agent instance, in GiB. Must be 2x the CPU allocation."
},
{
"name": "Metadata",
"type": "Dict<string,string>",
"isOptional": true,
"description": "Additional metadata to associate with the hosted agent."
},
{
"name": "Protocols",
"type": "HostedAgentProtocolVersion[]",
"isOptional": true,
"description": "The hosted agent protocol versions."
}
]
},
{
"name": "HostedAgentProtocolVersion",
"fullName": "Aspire.Hosting.Foundry.HostedAgentProtocolVersion",
"kind": "dto",
"description": "A protocol and version supported by a Microsoft Foundry hosted agent container.",
"fields": [
{
"name": "Protocol",
"type": "string",
"description": "The protocol name, such as responses or invocations."
},
{
"name": "Version",
"type": "string",
"description": "The protocol version, such as 1.0.0."
}
]
},
{
"name": "FoundryModel",
"fullName": "Aspire.Hosting.Foundry.FoundryModel",
Expand Down
Loading
Loading