Aster 框架中有多个与"多Agent"相关的概念,它们各自解决不同层次的问题,互不冲突,而是互补协作。
| 概念 | 层次 | 生命周期 | 主要职责 | 使用场景 |
|---|---|---|---|---|
| SubAgent | 中间件层 | 短暂(任务级) | 任务委派、上下文隔离 | 单个 Agent 内部的复杂任务拆分 |
| Stars | 协作层 | 中等(会话级) | 多 Agent 协作、消息路由 | 多个 Agent 之间的协同工作 |
| Cosmos | 管理层 | 长期(应用级) | Agent 生命周期管理 | 创建、销毁、监控所有 Agent |
| AsterOS | 运行时层 | 持久(系统级) | 统一运行时、API 网关 | 对外提供服务、资源注册 |
定位: 单个 Agent 内部的任务委派机制
核心特点:
task 工具调用使用场景:
// 场景:一个 Agent 需要并行处理多个独立的复杂任务
// 例如:同时研究3个不同的主题
// Agent 调用 task 工具
task(description="研究詹姆斯的成就", subagent_type="general-purpose")
task(description="研究乔丹的成就", subagent_type="general-purpose")
task(description="研究科比的成就", subagent_type="general-purpose")
// 3个 SubAgent 并行执行,完成后返回摘要
// 主 Agent 收集结果并进行比较
关键点:
定位: 多个 Agent 之间的协作单元
核心特点:
使用场景:
// 场景:多个专业 Agent 协作完成复杂项目
// 例如:软件开发团队(架构师、开发者、测试员)
stars := stars.New(cosmos, "DevTeam")
stars.Join("architect-agent", stars.RoleLeader)
stars.Join("developer-agent", stars.RoleWorker)
stars.Join("tester-agent", stars.RoleWorker)
// Leader 分配任务,Workers 协作完成
stars.Run(ctx, "开发一个用户认证系统")
关键点:
定位: Agent 生命周期管理器
核心特点:
使用场景:
// 场景:管理应用中所有的 Agent 实例
cosmos := cosmos.New(&cosmos.Options{
Dependencies: deps,
MaxAgents: 50,
})
// 创建不同类型的 Agent
chatAgent, _ := cosmos.Create(ctx, &types.AgentConfig{
AgentID: "chat-1",
TemplateID: "chat-assistant",
})
codeAgent, _ := cosmos.Create(ctx, &types.AgentConfig{
AgentID: "code-1",
TemplateID: "code-assistant",
})
// 统一管理所有 Agent
allAgents := cosmos.List("")
关键点:
定位: 系统级运行时和 API 网关
核心特点:
使用场景:
// 场景:对外提供 Agent 服务的生产系统
os, _ := asteros.New(&asteros.Options{
Name: "ProductionOS",
Port: 8080,
Cosmos: cosmos,
})
// 注册 Agent
os.RegisterAgent("chat-agent", chatAgent)
// 注册 Stars
os.RegisterStars("dev-team", devTeamStars)
// 启动服务,自动生成 API
os.Serve()
// 客户端可以通过 HTTP 访问:
// GET /api/agents
// POST /api/agents/chat-agent/run
// POST /api/stars/dev-team/run
关键点:
这四个概念形成了完整的层次结构,互不冲突:
┌─────────────────────────────────────────────────────────┐
│ AsterOS (统一运行时) │
│ - HTTP/A2A/AGUI Interfaces │
│ - Registry (Agents/Stars/Workflows) │
│ - Auto API Generation │
└─────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────┐
│ Cosmos (生命周期管理) + Stars (协作调度) │
│ - Create/Delete Agents │
│ - Leader-Worker Pattern │
│ - Message Routing │
└─────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────┐
│ Agent Runtime (执行引擎) │
│ - Middleware Stack │
│ - Provider Integration │
│ - Tool Execution │
└─────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────┐
│ SubAgent Middleware (任务委派) │
│ - task Tool │
│ - Context Isolation │
│ - Parallel Execution │
└─────────────────────────────────────────────────────────┘
// 简单应用:一个 Agent 处理复杂任务
agent := agent.Create(ctx, config, deps)
// 使用 SubAgent 中间件拆分任务
agent.Chat(ctx, "同时研究3个主题并比较")
// Agent 内部会并行启动3个 SubAgent
不需要: Stars、Cosmos、AsterOS
// 中等应用:多个 Agent 协作
cosmos := cosmos.New(opts)
stars := stars.New(cosmos, "Team")
// 创建多个 Agent
leader := cosmos.Create(ctx, leaderConfig)
worker1 := cosmos.Create(ctx, worker1Config)
worker2 := cosmos.Create(ctx, worker2Config)
// 组建团队
stars.Join(leader.ID(), stars.RoleLeader)
stars.Join(worker1.ID(), stars.RoleWorker)
stars.Join(worker2.ID(), stars.RoleWorker)
// 执行协作任务
stars.Run(ctx, "开发一个系统")
不需要: AsterOS(如果不对外提供服务)
// 生产应用:对外提供 Agent 服务
cosmos := cosmos.New(opts)
// 创建多个 Agent
chatAgent := cosmos.Create(ctx, chatConfig)
codeAgent := cosmos.Create(ctx, codeConfig)
// 创建协作团队
devTeam := stars.New(cosmos, "DevTeam")
devTeam.Join(codeAgent.ID(), stars.RoleLeader)
// 创建 AsterOS
os := asteros.New(&asteros.Options{
Cosmos: cosmos,
Port: 8080,
})
// 注册资源
os.RegisterAgent("chat", chatAgent)
os.RegisterAgent("code", codeAgent)
os.RegisterStars("dev-team", devTeam)
// 启动服务
os.Serve()
使用全套: SubAgent(Agent 内部)+ Stars(协作)+ Cosmos(管理)+ AsterOS(对外服务)
它们各司其职,互不冲突,共同构建了完整的多 Agent 系统架构。