# AgentFrameworkBuilderExtensions Methods

- Package: [Aspire.Hosting.AgentFramework.DevUI](/reference/api/csharp/aspire.hosting.agentframework.devui.md)
- Type: [AgentFrameworkBuilderExtensions](/reference/api/csharp/aspire.hosting.agentframework.devui/agentframeworkbuilderextensions.md)
- Kind: `Methods`
- Members: `2`

Provides extension methods for adding Agent Framework DevUI resources to the application model.

## AddDevUI(IDistributedApplicationBuilder, string, int?)

- Name: `AddDevUI(IDistributedApplicationBuilder, string, int?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<DevUIResource>`

Adds a DevUI resource for testing AI agents in a distributed application.

```csharp
public static class AgentFrameworkBuilderExtensions
{
    public static IResourceBuilder<DevUIResource> AddDevUI(
        this IDistributedApplicationBuilder builder,
        string name,
        int? port = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
  The `Hosting.IDistributedApplicationBuilder`.
- `name` (`string`)
  The name to give the resource.
- `port` (`int?`) `optional`
  The host port for the DevUI web interface. If not specified, a random port will be assigned.

## Returns

`IResourceBuilder<DevUIResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1` for chaining.

## Remarks

DevUI is a web-based interface for testing and debugging AI agents using the OpenAI Responses protocol. When configured with [AgentFrameworkBuilderExtensions.WithAgentService(IResourceBuilder<DevUIResource>, IResourceBuilder<TSource>, IReadOnlyList<AgentEntityInfo>, string?)](/reference/api/csharp/aspire.hosting.agentframework.devui/agentframeworkbuilderextensions/methods.md#withagentservice-iresourcebuilder-devuiresource-iresourcebuilder-tsource-ireadonlylist-agententityinfo-string), it aggregates agents from multiple backend services and provides a unified testing interface.

The aggregator runs as an in-process reverse proxy within the AppHost, requiring no external container image. It serves the DevUI frontend from embedded resources in Microsoft.Agents.AI.DevUI when available, and falls back to proxying from the first configured backend. It aggregates entity listings from all backends.

This resource is excluded from the deployment manifest as it is intended for development use only.

## Examples

```csharp
var devui = builder.AddDevUI("devui")
    .WithAgentService(dotnetAgent)
    .WithAgentService(pythonAgent);
```

## WithAgentService(IResourceBuilder<DevUIResource>, IResourceBuilder<TSource>, IReadOnlyList<AgentEntityInfo>, string?)

- Name: `WithAgentService(IResourceBuilder<DevUIResource>, IResourceBuilder<TSource>, IReadOnlyList<AgentEntityInfo>, string?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<DevUIResource>`

Configures DevUI to connect to an agent service backend.

```csharp
public static class AgentFrameworkBuilderExtensions
{
    public static IResourceBuilder<DevUIResource> WithAgentService<TSource>(
        this IResourceBuilder<DevUIResource> builder,
        IResourceBuilder<TSource> agentService,
        IReadOnlyList<AgentEntityInfo>? agents = null,
        string? entityIdPrefix = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<DevUIResource>`)
  The DevUI resource builder.
- `agentService` (`IResourceBuilder<TSource>`)
  The agent service resource to connect to.
- `agents` ([IReadOnlyList<AgentEntityInfo>](/reference/api/csharp/aspire.hosting.agentframework.devui/agententityinfo.md)) `optional`
  Optional list of agents declared by this backend. When provided, the aggregator uses these declarations directly. When not provided, defaults to a single agent named after the `agentService` resource. The backend doesn't need to expose a `/v1/entities` endpoint in either case.
- `entityIdPrefix` (`string?`) `optional`
  An optional prefix to add to entity IDs from this backend. If not specified, the resource name will be used as the prefix.

## Returns

`IResourceBuilder<DevUIResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1` for chaining.

## Remarks

Each agent service should expose the OpenAI Responses and Conversations API endpoints (via `MapOpenAIResponses` and `MapOpenAIConversations`).

When `agents` is provided, the aggregator builds the entity listing from these declarations without querying the backend. When not provided, a single agent named after the service resource is assumed. Agent services don't need a `/v1/entities` endpoint.

## Examples

```csharp
var writerAgent = builder.AddProject<Projects.WriterAgent>("writer-agent");
var editorAgent = builder.AddProject<Projects.EditorAgent>("editor-agent");

builder.AddDevUI("devui")
    .WithAgentService(writerAgent, agents: [new("writer", "Writes short stories")])
    .WithAgentService(editorAgent, agents: [new("editor", "Edits and formats stories")])
    .WaitFor(writerAgent)
    .WaitFor(editorAgent);
```
