用法#
AutoGen Studio (AGS) 提供了一个团队构建器界面,开发人员可以在其中定义多个组件和行为。用户可以创建团队,向团队添加代理,将工具和模型附加到代理,并定义团队终止条件。定义团队后,用户可以直接在团队构建器视图中进行测试,或将其附加到会话中以在 Playground 视图中使用。
观看 AutoGen Studio v0.4 (02/25) 的视频教程 - https://youtu.be/oum6EI7wohM
设置 API 密钥#
大多数代理都需要 API 密钥。您可以设置一个环境变量 OPENAI_API_KEY(假设您正在使用 OpenAI 模型),AutoGen 将自动将其用于您为代理或团队指定的任何 OpenAI 模型客户端。或者,您也可以将 API 密钥指定为团队或代理配置的一部分。
请参阅以下部分,了解如何使用可视化构建器或直接编辑 JSON 配置来构建代理团队。
构建代理团队#
AutoGen Studio 与 AutoGen AgentChat 提供的所有组件抽象紧密集成,包括团队、代理、模型、工具和终止条件。
AGS 中的团队构建器视图提供了一个可视化团队构建器,允许用户通过拖放功能或直接编辑团队的 JSON 配置来定义组件。
使用可视化构建器#
可视化构建器默认启用,允许用户将组件从提供的组件库拖放到团队构建器画布中。团队构建器画布代表一个团队,由一个主团队节点和一组连接的代理节点组成。它包含一个组件库,其中包含可添加到画布中团队或代理节点的一系列组件。

支持的核心行为包括
创建一个新团队。可以通过单击团队构建器视图中的“新团队”按钮或选择随默认 AGS 图库提供的任何现有默认团队来完成。一旦完成此操作,将在画布中创建一个新团队节点和代理节点。
将组件从库拖放到画布中的团队或代理节点。
团队:将代理和终止条件拖到团队节点(这些组件有特定的放置区)
代理:将模型和工具拖到代理节点(这些组件有特定的放置区)
编辑团队/代理节点:单击节点(右上角)的编辑图标以查看和编辑其属性。这将弹出一个面板,允许您编辑节点的字段。在某些情况下,您需要向下滚动并单击特定部分,例如,对于具有模型客户端的代理,您需要单击模型客户端部分以编辑模型客户端属性。编辑完成后,单击保存按钮以保存更改。
使用 JSON 编辑器#

AGS 还允许您直接修改团队的 JSON 配置。这可以通过关闭可视化构建器模式来完成。一旦完成此操作,您将看到团队的 JSON 配置。然后,您可以直接编辑 JSON 配置。
您知道您可以在 Python 中定义代理,将其导出为 JSON,然后将其粘贴到 JSON 编辑器中吗?以下部分将展示如何实现这一点。
组件的声明性规范#
AutoGen Studio 基于 AutoGen AgentChat 的声明性规范行为构建。这允许用户在 Python 中定义团队、代理、模型、工具和终止条件,然后将其转储到 JSON 文件中以在 AutoGen Studio 中使用。
这是一个代理团队的示例以及如何将其转换为 JSON 文件
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_agentchat.conditions import TextMentionTermination
agent = AssistantAgent(
name="weather_agent",
model_client=OpenAIChatCompletionClient(
model="gpt-4o-mini",
),
)
agent_team = RoundRobinGroupChat([agent], termination_condition=TextMentionTermination("TERMINATE"))
config = agent_team.dump_component()
print(config.model_dump_json())
{
"provider": "autogen_agentchat.teams.RoundRobinGroupChat",
"component_type": "team",
"version": 1,
"component_version": 1,
"description": "A team that runs a group chat with participants taking turns in a round-robin fashion\n to publish a message to all.",
"label": "RoundRobinGroupChat",
"config": {
"participants": [
{
"provider": "autogen_agentchat.agents.AssistantAgent",
"component_type": "agent",
"version": 1,
"component_version": 1,
"description": "An agent that provides assistance with tool use.",
"label": "AssistantAgent",
"config": {
"name": "weather_agent",
"model_client": {
"provider": "autogen_ext.models.openai.OpenAIChatCompletionClient",
"component_type": "model",
"version": 1,
"component_version": 1,
"description": "Chat completion client for OpenAI hosted models.",
"label": "OpenAIChatCompletionClient",
"config": { "model": "gpt-4o-mini" }
},
"tools": [],
"handoffs": [],
"model_context": {
"provider": "autogen_core.model_context.UnboundedChatCompletionContext",
"component_type": "chat_completion_context",
"version": 1,
"component_version": 1,
"description": "An unbounded chat completion context that keeps a view of the all the messages.",
"label": "UnboundedChatCompletionContext",
"config": {}
},
"description": "An agent that provides assistance with ability to use tools.",
"system_message": "You are a helpful AI assistant. Solve tasks using your tools. Reply with TERMINATE when the task has been completed.",
"model_client_stream": false,
"reflect_on_tool_use": false,
"tool_call_summary_format": "{result}"
}
}
],
"termination_condition": {
"provider": "autogen_agentchat.conditions.TextMentionTermination",
"component_type": "termination",
"version": 1,
"component_version": 1,
"description": "Terminate the conversation if a specific text is mentioned.",
"label": "TextMentionTermination",
"config": { "text": "TERMINATE" }
}
}
}
此示例展示了一个具有单个代理的团队,使用 RoundRobinGroupChat 类型和 TextMentionTermination 条件。您还将注意到模型客户端是 OpenAIChatCompletionClient 模型客户端,其中只指定了模型名称。在这种情况下,API 密钥被假定为已设置为环境变量 OPENAI_API_KEY。您也可以将 API 密钥指定为模型客户端配置的一部分。
要了解模型客户端的完整配置,您可以参考 AutoGen 模型客户端文档。
请注意,您可以类似地在 Python 中定义模型客户端,并对其调用 dump_component() 以获取 JSON 配置,并用它来更新团队或代理配置的模型客户端部分。
最后,您可以使用 load_component() 方法从 JSON 文件加载团队配置
import json
from autogen_agentchat.teams import BaseGroupChat
team_config = json.load(open("team.json"))
team = BaseGroupChat.load_component(team_config)
图库 - 共享和重用组件#
AGS 提供了一个图库视图,其中图库是组件(团队、代理、模型、工具和终止)的集合,可以在项目之间共享和重用。
用户可以创建本地图库或导入图库(通过 URL、JSON 文件导入或简单地复制粘贴 JSON)。在任何给定时间,用户都可以选择任何当前的图库项目作为默认图库。此默认图库将用于使用组件填充团队构建器侧边栏。
通过“图库”->“新建图库”创建新图库
根据需要编辑图库 JSON
设置默认图库(单击侧边栏中的图钉图标)以使组件在团队构建器中可用。
交互式运行团队#
AutoGen Studio Playground 允许用户
测试特定任务的团队
审查生成的工件(图像、代码、文本)
在任务执行期间监控团队的“内心独白”
查看性能指标(轮次计数、令牌使用情况)
跟踪代理操作(工具使用、代码执行结果)
导入和重用团队配置#
AutoGen Studio 的图库视图提供了一个默认组件集合并支持导入外部配置
通过“图库”->“新建图库”->“导入”创建/导入图库
通过侧边栏图钉图标设置默认图库
通过“侧边栏”->“从图库”访问团队构建器中的组件
Python 集成#
团队配置可以使用 TeamManager 类集成到 Python 应用程序中
from autogenstudio.teammanager import TeamManager
tm = TeamManager()
result_stream = tm.run(task="What is the weather in New York?", team_config="team.json") # or tm.run_stream(..)
要导出团队配置,请使用团队构建器中的导出按钮生成 JSON 文件以供 Python 应用程序使用。
