简体中文 | English
matterloop-agents
这个包提供两层能力:可直接注入 Core 的标准 Agent 组件,以及由中心控制器管理的 TeamLoop。两层 共用模型与工具协议,但状态边界不同;TeamLoop 不靠 Agent 之间自由聊天来维持一致性。
pip install matterloop-agents
单 Agent:Planner、Worker、Verifier
from matterloop_agents import (
CriteriaVerifier,
CriteriaVerifierConfig,
ModelPlanner,
ModelPlannerConfig,
ToolCallingWorker,
ToolCallingWorkerConfig,
)
planner = ModelPlanner(models, ModelPlannerConfig(model="planner"), memory=memory)
worker = ToolCallingWorker(
models,
tools,
ToolCallingWorkerConfig(model="worker", tool_names=("filesystem",)),
)
verifier = CriteriaVerifier(models, CriteriaVerifierConfig(model="verifier"))
ModelPlanner 生成有限步骤计划,ToolCallingWorker 执行工具续轮,CriteriaVerifier 独立判断步骤
是否达到验收条件。ModelReviewer 可做更开放的质量审查,并通过 adapter 转成 Core Verifier。
每次模型事务都通过 ModelRegistry.acquire() 固定客户端;热替换只影响新事务。模型 JSON、计划
步骤和工具参数仍会在本地严格解析。计划超限、非法工具、解析失败和工具循环超限使用类型化 Agent
异常,由 Core 的重试策略决定是否重试。
单 Agent 配置速查
ModelPlannerConfig(model, default_executor, max_steps, max_output_tokens, memory_namespace, memory_limit):默认执行器default、20 步、4096 输出 Token、记忆 namespacedefault、最多 5 条记忆。ToolCallingWorkerConfig(model, tool_names, max_tool_rounds, max_output_tokens):默认无工具、最多 8 轮、每轮 4096 输出 Token。CriteriaVerifierConfig(model, pass_score, max_output_tokens):默认 80 分通过、2048 输出 Token。ModelReviewerConfig(model, max_output_tokens):默认 3072 输出 Token。ReviewResult(score, summary, evidence, issues, recommendations):通用审查结果;issues 非空时 adapter 不会判定通过。
这些上限约束单次组件调用,不是整个运行的 Token、费用或 cycle 预算。
TeamLoop:DAG,而不是群聊
TeamPlanner
└─ 根据能力快照、人工反馈和历史审查生成 TaskSpec DAG
└─ TeamOrchestrator 找出 READY 任务
├─ 审批 requires_approval 的任务
├─ AgentDirectory 分配有容量的 Endpoint
└─ 并行执行 → TaskVerifier
└─ fan-in → ResultAggregator → TeamReviewer
├─ ACCEPT
├─ REPLAN
├─ REQUEST_HUMAN
└─ STOP
TeamOrchestrator 是 TeamSnapshot 的唯一写入者。Endpoint 只收到隔离的 AgentTaskContext 并返回
TaskResult;批次结果在 fan-in 后由控制器顺序提交。依赖任务的正式通信通道是
dependency_results。Mailbox 和 ArtifactStore 是可选设施,不能绕过控制器修改全局状态。
Planner 只能选择 AgentDirectory 当前能力快照中的 capability。任务图必须无环、依赖存在、ID
唯一,并同时受到团队并发和每个 Agent 容量限制。
最小团队装配
from matterloop_agents.collaboration import (
AgentDirectory,
AgentSpec,
AsyncTeamRuntime,
LeastBusyScheduler,
LoopAgentEndpoint,
TeamOrchestrator,
TeamOrchestratorComponents,
)
directory = AgentDirectory()
directory.register(
LoopAgentEndpoint(
AgentSpec("python-worker", frozenset({"python"}), max_concurrency=2),
child_runtime,
)
)
components = TeamOrchestratorComponents(
planner=team_planner,
agents=directory,
selection_policy=LeastBusyScheduler(),
verifier=task_verifier,
approval_gate=approval_gate,
repository=team_repository,
events=team_events,
aggregator=result_aggregator,
reviewer=team_reviewer,
)
runtime = AsyncTeamRuntime(
TeamOrchestrator(components, owner_id="controller-a"),
resources=(child_runtime,),
)
如果 child_runtime 是 production preset 在传入 OtelExporter 后创建的 worker_runtime,
LoopAgentEndpoint 会暴露其观测能力,TeamOrchestrator 自动安装 Team 事件追踪与任务中间件;上述
components 不需要额外 OTel 字段。Endpoint 必须先注册,再构造 TeamOrchestrator。
自定义 Endpoint 代理若包裹 LoopAgentEndpoint,应原样转发可选的 team_instrumentation 属性;
内置 BudgetedAgentEndpoint 已处理该转发。
reviewer=None 会自动接受所有已通过任务验证的草稿;ResultSuccessVerifier 也只检查 success 标志。
它们适合测试,不构成生产验收。生产团队应配置领域 Verifier、整体 Reviewer 和真实审批门。
模型版团队组件使用 ModelTeamPlannerConfig(model, max_tasks, max_output_tokens)、
ModelTaskVerifierConfig(model, pass_score, max_output_tokens)、
ModelResultAggregatorConfig(model, max_output_tokens) 与
ModelTeamReviewerConfig(model, pass_score, max_output_tokens)。它们只保存注册名,不持有凭据。
重试、重新规划与恢复点
任务结果先保存为 VERIFYING,再调用 Verifier。验证阶段崩溃后恢复会复用已保存结果,不重复执行
可能有副作用的 Endpoint。验证失败先消耗任务级 attempt;耗尽后才归档当前 cycle,带着失败审查
进入下一轮规划。
TaskSpec.replay_safe 默认为 False。进程中断留下 RUNNING 时,默认进入
BLOCKED/RECOVERY_REQUIRED 等待宿主对账,不调用替代 Agent;只有宿主确认任务只读且可安全重放,
并显式设置 replay_safe=True,才会释放旧分配并开始下一次 attempt。
TeamLimits 分开限制单计划任务数、并发任务、单任务尝试、团队 cycle、计划 revision 和活跃超时。
暂停不会重置任何计数或用量,也不计入 active timeout。
AgentDirectory.replace() 只影响新租约;已有任务继续使用旧 Endpoint。Directory 不拥有 Endpoint
生命周期,应用要等待旧租约排空后关闭旧资源。
LoopAgentEndpoint 把团队任务映射为子 LoopRequest,并传入依赖结果、人工反馈和父子 usage scope。
它会在全部业务 metadata 合并后强制写入 tool_access_scope=read_only;任务、请求或 Endpoint metadata
中的同名字段都不能提权。ToolCallingWorker 将该范围传给 ToolRegistry,子 Agent 只能调用明确标记
为 READ 的工具;COMPUTE/WRITE/UNKNOWN 必须由主 Loop 在默认 FULL 范围内统一治理。
当前子 Loop 自己产生的 pending interaction 不会自动提升到团队层;需要这种行为时,应实现专用
Endpoint 桥接两级 HITL。
人工反馈
from matterloop_core import HumanAction, HumanResponse
paused = await runtime.run(request)
interaction = paused.pending_interaction
if interaction is not None:
await runtime.submit_human_response(
paused.run_id,
HumanResponse(
interaction_id=interaction.interaction_id,
action=HumanAction.REVISE,
content="拆成两个并行证据任务",
idempotency_key="revision-01",
),
)
result = await runtime.resume(paused.run_id)
提交反馈只写入仓储,不隐式恢复。APPROVE 精确继续且不重放已完成任务;REJECT 进入
BLOCKED/HUMAN_REJECTED;REVISE 和 PROVIDE_INPUT 保存历史并重新规划。相同幂等键与相同内容
是 no-op,同键不同内容抛冲突异常。
持久化与控制器租约
每次 Snapshot 保存都使用 version CAS。运行前,Orchestrator 还会取得运行级控制器租约,防止两个
控制器同时推进同一个团队。InMemoryTeamRepository 没有持久化或租约过期,只适合测试。
当前 TeamRepository 只有 acquire/release,没有 heartbeat/renew。生产实现应使用覆盖最坏执行
时间的租约、外部 fencing 或扩展续租协议。租约过早失效可能造成 Endpoint 副作用重复;CAS 只能
阻止最终状态覆盖,不能撤销已经发生的外部操作。
TeamLoop 公共数据结构速查
TeamRequest(goal, acceptance_criteria, limits, metadata)。TeamLimits(max_tasks, max_concurrency, max_task_attempts, max_cycles, max_plan_revisions, timeout_seconds):默认 50、4、3、3、2 和无超时。AgentSpec(agent_id, capabilities, max_concurrency, version, description, role, metadata)。TaskSpec(task_id, description, capability, dependencies, acceptance_criteria, requires_approval, priority, metadata, replay_safe);replay_safe默认False,只有明确可重放的纯计算任务才会在崩溃后自动再次执行。AgentTaskContext(team_run_id, request, task, agent_id, attempt, dependency_results, previous_error, human_feedback, propagation_context):propagation_context仅用于中间件向 Endpoint 传递标准关联载体。TaskResult(task_id, agent_id, success, output, artifacts, error, attempt, metadata)。TaskVerification(passed, feedback, score, evidence, failed_criteria)。TaskState(spec, status, attempt, approval_granted, assigned_agent, result, verification, error)。TeamPlanningContext(run_id, request, cycle, plan_revision, available_agents, prior_reviews, human_feedback)。TeamReviewContext(run_id, request, cycle, plan_revision, task_results, draft_output, prior_reviews, human_feedback)。TeamReview(action, feedback, score, evidence, failed_criteria, interaction)。TeamCycleRecord(cycle, plan_revision, tasks, draft_output, review, error)。TeamSnapshot(request, tasks, run_id, status, version, stop_reason, output, error, cycle, plan_revision, cycle_history, pending_interaction, pending_review, human_interactions, external_state_refs, review_approved_cycle, active_elapsed_seconds, active_started_at, propagation_context, created_at, updated_at):external_state_refs保留由 Runtime 管理的状态;propagation_context随快照 CAS 持久化,只保存受信的 W3C carrier。TeamResult(run_id, status, task_results, output, stop_reason, error, cycle, cycle_history, pending_interaction, human_interactions, started_at, finished_at)。TeamEvent(event_type, snapshot, detail, metadata, occurred_at):事件携带当时的完整快照,可能很大且敏感。AgentMessage(team_run_id, sender_agent_id, recipient_agent_id, message_type, content, correlation_id, metadata, message_id, created_at):可选 Mailbox DTO,不是全局状态通道。TeamOrchestratorComponents(planner, agents, selection_policy, verifier, approval_gate, repository, events, aggregator, reviewer, task_middleware, snapshot_preparer):task_middleware在 Endpoint 调用边界包裹一次任务,可传递不可变上下文副本但不能改变业务结果语义;snapshot_preparer在 CAS 保存前补充可持久化的中立关联字段。TeamSnapshotPreparer.prepare_snapshot(snapshot):返回仅补充中立关联字段的快照副本,故障由控制器隔离。
TeamReviewAction 为 ACCEPT/REPLAN/REQUEST_HUMAN/STOP。团队停止原因区分完成、审批/人工拒绝、任务
失败、无可用 Agent、容量、死锁、取消、超时、cycle/revision 上限、预算耗尽、恢复对账和组件错误。
生产边界
- 子 Agent 只生成方案和读取证据;计算、工具写入和业务写操作必须回到主 Loop 的审批、预算与审计链路。
- Endpoint、工具和业务写操作必须使用 team run/task/attempt 作为幂等键。
ResourceLimitExceededError映射为BLOCKED/BUDGET_EXHAUSTED,不作为普通任务错误重试。- Team 事件可能包含 goal、完整输出、人工意见和 metadata;Publisher 与 Repository 都要实施租户 隔离、加密、保留期和脱敏。
AsyncTeamRuntime会先拒绝新操作、等待在途run/resume/人工响应结束,再关闭resources中的对象;Directory、模型、仓储和事件后端不会被自动接管。LocalTeamRuntime使用专用事件循环线程,必须关闭,也不能在该线程内阻塞调用自己。
Metadata
Release files for matterloop-agents 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| matterloop_agents-0.2.1.tar.gz | 134.9 kB | With provenance | Details for matterloop_agents-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| matterloop_agents-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for matterloop_agents-0.2.1-py3-none-any.whl |
Total release size: 252.3 kB
Release files / matterloop_agents-0.2.1.tar.gz
| Download URL | matterloop_agents-0.2.1.tar.gz |
|---|---|
| Size | 134.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ccf7dbe95070919c233df1c2bf7b738738fb8dcf44abe41d6ca3a69b89821d45
|
|
BLAKE2b-256 checksum How to use checksums |
47e43d1c0c57467f455ff211313e04dad5b6b6b6870d7b510cfb6b27c4f77edd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 29, 2026.
Transparency logRelease files / matterloop_agents-0.2.1-py3-none-any.whl
| Download URL | matterloop_agents-0.2.1-py3-none-any.whl |
|---|---|
| Size | 117.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e9c7df10269dbdf6221a546c24845f682d50d6102dd1a434980c2c177c5b8f4a
|
|
BLAKE2b-256 checksum How to use checksums |
5a289e8b2fecf3157453a6fe8ee6cf3b718c76cf5ff94ffb7c7ce5195c3f620c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 29, 2026.
Transparency logSecurity for matterloop-agents 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for matterloop_agents-0.2.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 29, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.