DevUI 是一个轻型独立示例应用程序,用于在 Microsoft Agent Framework 中运行代理和工作流。 它提供了一个 Web 界面,用于交互式测试以及与 OpenAI 兼容的 API 后端,使你能够在将代理和工作流集成到应用程序之前直观地调试、测试和迭代生成的代理和工作流。
Important
DevUI 是一个 示例应用 ,可帮助你在开发过程中可视化和调试代理和工作流。 它 不适用于 生产用途。
安装软件包
对于单个.NET服务,请安装 DevUI 包。 对于聚合多个代理服务的 Aspire AppHost,还安装 Aspire 托管集成。
dotnet add package Microsoft.Agents.AI.DevUI --prerelease
dotnet add package Aspire.Hosting.AgentFramework.DevUI --prerelease
将 DevUI 与 Aspire 配合使用
每个代理服务都会公开 OpenAI 响应和对话终结点。 Aspire AppHost 添加一个 DevUI 资源并连接代理服务。
var writerAgent = builder.AddProject<Projects.WriterAgent>("writer-agent", launchProfileName: "https")
.WithHttpHealthCheck("/health", endpointName: "https")
.WithReference(foundry).WaitFor(foundry);
// Add the editor agent service
var editorAgent = builder.AddProject<Projects.EditorAgent>("editor-agent")
.WithHttpHealthCheck("/health")
.WithReference(foundry).WaitFor(foundry);
// Add DevUI integration that aggregates agents from all agent services.
// Agent metadata is declared here so backends don't need a /v1/entities endpoint.
_ = builder.AddDevUI("devui")
.WithAgentService(writerAgent, agents: [new("writer")]) // the name of the agent should match the agent declaration in WriterAgent/Program.cs
.WithAgentService(editorAgent, agents: [new("editor")]) // the name of the agent should match the agent declaration in EditorAgent/Program.cs
.WaitFor(writerAgent)
.WaitFor(editorAgent);
agents:传递给WithAgentService的名称必须与每个服务中注册AddAIAgent(...)的名称匹配。
公开代理服务终结点
var builder = WebApplication.CreateBuilder(args);
builder.AddServiceDefaults();
builder.AddAzureChatCompletionsClient(connectionName: "foundry",
configureSettings: settings =>
{
// WARNING: DefaultAzureCredential is convenient for development but requires careful consideration in production.
// In production, consider using a specific credential (e.g., ManagedIdentityCredential) to avoid
// latency issues, unintended credential probing, and potential security risks from fallback mechanisms.
settings.TokenCredential = new DefaultAzureCredential();
settings.EnableSensitiveTelemetryData = builder.Environment.IsDevelopment();
})
.AddChatClient("gpt41");
builder.AddAIAgent("writer", "You write short stories (300 words or less) about the specified topic.");
// Register services for OpenAI responses and conversations
builder.Services.AddOpenAIResponses();
builder.Services.AddOpenAIConversations();
var app = builder.Build();
app.UseHttpsRedirection();
// Map OpenAI API endpoints — DevUI aggregator routes requests here
DevUI 聚合器将所有已配置服务中的实体合并在一起,并将响应和对话请求路由到正确的后端。
Features
- Web 界面:用于测试代理和工作流的交互式 UI
- 灵活的输入类型:支持基于工作流的第一个执行程序的文本、文件上传和自定义输入类型
- 基于目录的发现:从目录结构中自动发现代理和工作流
- In-Memory 注册:在不设置文件系统的情况下以编程方式注册实体
- OpenAI-Compatible API:使用 OpenAI Python SDK 与代理交互
- 示例库:在未发现实体时浏览和下载特选示例
- Tracing:查看 OpenTelemetry 追踪信息,用于调试和可观测性
输入类型
DevUI 根据实体类型调整其输入接口:
- 代理:支持文本输入和文件附件(图像、文档等)进行多模式交互
- 工作流:输入接口基于第一个执行程序的输入类型自动生成。 DevUI 审视工作流并反映预期的输入结构,使工作流能够轻松地使用结构化或自定义输入类型进行测试。
通过此动态输入处理,可以像在应用程序中接收输入一样测试代理和工作流。
安装
从 PyPI 安装 DevUI:
pip install agent-framework-devui --pre
快速入门
选项 1:编程注册
使用已注册内存中的代理启动 DevUI:
from agent_framework import Agent
from agent_framework.openai import OpenAIChatClient
from agent_framework.devui import serve
def get_weather(location: str) -> str:
"""Get weather for a location."""
return f"Weather in {location}: 72F and sunny"
# Create your agent
agent = Agent(
name="WeatherAgent",
client=OpenAIChatClient(),
tools=[get_weather]
)
# Launch DevUI
serve(entities=[agent], auto_open=True)
# Opens browser to http://localhost:8080
选项 2:目录发现(CLI)
如果代理和工作流组织在目录结构中,请从命令行启动 DevUI:
# Launch web UI + API server
devui ./agents --port 8080
# Web UI: http://localhost:8080
# API: http://localhost:8080/v1/*
有关所需目录结构的详细信息,请参阅 目录发现 。
使用 OpenAI SDK
DevUI 提供与 OpenAI 兼容的响应 API。 可以使用 OpenAI Python SDK 与代理交互:
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:8080/v1",
api_key="not-needed" # API key not required for local DevUI
)
response = client.responses.create(
metadata={"entity_id": "weather_agent"}, # Your agent/workflow name
input="What's the weather in Seattle?"
)
# Extract text from response
print(response.output[0].content[0].text)
有关 API 的更多详细信息,请参阅 API 参考。
CLI 选项
devui [directory] [options]
Options:
--port, -p Port (default: 8080)
--host Host (default: 127.0.0.1)
--headless API only, no UI
--no-open Don't automatically open browser
--tracing Enable OpenTelemetry tracing
--reload Enable auto-reload
--mode developer|user (default: developer)
--auth Enable Bearer token authentication
--auth-token Custom authentication token
注释
Go 语言对该功能的支持即将推出。 有关最新状态,请参阅 Agent Framework Go 存储库 。
后续步骤
更深入: