name: agentica-infrastructure description: Agentica多代理基础设施API的参考指南 allowed-tools: [读取] user-invocable: false
Agentica 基础设施参考
Agentica多代理协调基础设施的完整API规范。
使用场景
- 使用Agentica模式构建多代理工作流
- 需要模式类的精确构造函数签名
- 想要了解协调数据库模式
- 使用原语实现自定义模式
- 调试代理跟踪或孤儿检测
快速参考
11个模式类
| 模式 | 用途 | 关键方法 |
|---|---|---|
Swarm |
并行视角 | .execute(query) |
Pipeline |
顺序阶段 | .run(initial_state) |
Hierarchical |
协调者 + 专家 | .execute(task) |
Jury |
投票共识 | .decide(return_type, question) |
GeneratorCritic |
迭代优化 | .run(task) |
CircuitBreaker |
失败回退 | .execute(query) |
Adversarial |
辩论 + 裁判 | .resolve(question) |
ChainOfResponsibility |
路由到处理程序 | .process(query) |
MapReduce |
扩散 + 合并 | .execute(query, chunks) |
Blackboard |
共享状态 | .solve(query) |
EventDriven |
事件总线 | .publish(event) |
核心基础设施
| 组件 | 文件 | 用途 |
|---|---|---|
CoordinationDB |
coordination.py |
SQLite 跟踪 |
tracked_spawn |
tracked_agent.py |
带跟踪的代理 |
HandoffAtom |
handoff_atom.py |
通用交接格式 |
BlackboardCache |
blackboard.py |
热层通信 |
MemoryService |
memory_service.py |
核心 + 归档内存 |
create_claude_scope |
claude_scope.py |
带文件操作的领域 |
原语
| 原语 | 用途 |
|---|---|
Consensus |
投票(多数、一致、阈值) |
Aggregator |
合并结果(合并、连接、最佳) |
HandoffState |
结构化代理交接 |
build_premise |
结构化前提构建器 |
gather_fail_fast |
基于TaskGroup的并行执行 |
完整API规范
参见:此技能目录中的 API_SPEC.md
使用示例
from scripts.agentica_patterns.patterns import Swarm, Jury
from scripts.agentica_patterns.primitives import ConsensusMode
from scripts.agentica_patterns.coordination import CoordinationDB
from scripts.agentica_patterns.tracked_agent import tracked_spawn
# 创建跟踪数据库
db = CoordinationDB(session_id="my-session")
# 带跟踪的Swarm
swarm = Swarm(
perspectives=["Security expert", "Performance expert"],
db=db
)
result = await swarm.execute("Review this code")
# 带共识的Jury
jury = Jury(
num_jurors=3,
consensus_mode=ConsensusMode.MAJORITY,
premise="You evaluate code quality",
db=db
)
verdict = await jury.decide(bool, "Is this code production ready?")
位置
API规范:.claude/skills/agentica-infrastructure/API_SPEC.md
源代码:scripts/agentica_patterns/