baymax

module
v0.0.0-...-c563d8d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2026 License: Apache-2.0

README

Baymax Agent Loop (Go)

Baymax 是一个 library-first、contract-first 的 Go Agent runtime,面向可嵌入的单 agent、多 agent、工具和 MCP 编排。它提供 Run/Stream 主循环、Provider 适配、Context projection、结构化诊断、replay 和离线治理门禁;宿主仍拥有 credential、网络、持久化和全局路由。

Host context resolver material 采用固定且有效 UTF-8 的 byte bounds(role 64 bytes、content 64 KiB、单次合计 256 KiB)并整组准入;request projection 可 opt-in 携带 configuration、prompt、tool-schema 的安全 revision/digest/length facts,不保留原文或推断缺失值。详见 host context contract 与 model projection contract。

5 分钟开始

要求 Go 1.26(仓库通过 go.mod 的 toolchain 声明验证工具链;建议使用当前 Go 1.26 安全补丁版本)。从仓库根目录运行:

go run ./examples/01-chat-minimal

接着按开始使用完成离线验证、真实 Provider 接入和宿主责任清单,再按集成指南选择工具、MCP 或多 agent 路径。最小示例只展示 library 接入,不代表生产配置、重试或安全策略。

能力边界

  • 统一 Run/Stream 主循环与终态语义。
  • OpenAI、Anthropic、Gemini 等 Provider adapter(协议细节位于 model/<provider>)。
  • bounded source-neutral execution topology projection across workflow, team and individual child dispatch; owner execution and restore digests remain separate. See execution graph guide.
  • bounded source-neutral execution topology projection across workflow, team and individual child dispatch; owner execution and restore digests remain separate. See execution graph guide.
  • local tool、MCP HTTP/STDIO、workflow、teams、A2A、scheduler、composer。
  • Context budget/projection、结构化 timeline/diagnostics、RuntimeRecorder 单写入口。
  • contract/replay/gate 作为离线、bounded、可重复的证据。
  • opt-in 外部沙箱运行时 adapter(e2b / open-sandbox / anthropic-sandbox-runtime,以及 offline onboarding 用的 local),统一映射到既有四种 canonical backend;默认 Disabled,不改变 observe + default_action=host 姿态,也不声明本仓自带真实隔离执行器。见 外部适配模板索引 与 适配迁移映射。
  • opt-in 原生执行事件 adapter:真实回调、独立宿主 references、保守 source capabilities 和有界观察失败反馈,见 接入示例。
  • reference-only 插件包契约:extension/plugin 提供 bundle 清单、plugin:<bundle>:<tool> 命名空间与 plugin.lock.v1 锁文件,extension/plugin/hookproc 提供 argv-only 有界子进程 hook;不做 marketplace、动态加载或签名信任链。见 插件包示例。

不提供自动 Provider 探测、隐式全局 registry、远程控制面或跨租户状态。架构与依赖边界见 架构总览、设计原则 和 模块 ownership。

按读者进入

当前状态与路线图

当前状态的唯一依据是 openspec list --json、开发路线图 和 归档索引。项目处于 0.x pre-1 阶段:不做 1.0.0/prod-ready 承诺;新增能力必须经过 OpenSpec、测试、文档影响评估和回滚审查。

版本阶段快照

0.x 阶段允许新增能力型提案,但每项提案必须明确 Why now、风险、回滚、文档影响和验证命令;本项目不把归档数量或 package 数量当作成熟度承诺。

OpenSpec 状态以 openspec list --json、路线图 和 归档索引 为准。能力边界和仍不支持的组合也见 集成能力矩阵,不要从 package 名称或旧的 release snapshot 推断。

  • model-visible-provenance-invariant(X;已归档 211,已归档并稳定):宿主 resolver 实现 ProvenanceResolver 时,每个进入模型请求的条目必须有可校验 provenance(reference/digest/length),缺失或漂移以稳定分类 fail-closed;记录不保留原文,不构成授权或业务提交。
  • lifecycle-hook-mount-points(T;已归档 210,已归档并稳定):插件包 hook 必须声明 canonical 生命周期挂点(before_acting/after_acting/before_reply 等 6 个 phase),挂点为声明式契约,执行与失败语义仍由宿主与既有 hooks contract 拥有。
  • layered-agents-md-instruction-loading(V;已归档 209,已归档并稳定):opt-in 的「全局 → 父目录由外到内 → 当前目录」分层技能发现,同名技能以更具体的层为准,层数受 max_layer_depth 预算约束;默认关闭,既有行为不变。详见 归档记录。
  • compaction-retained-reasoning-audit(W;已归档 208,已归档并稳定):核查上下文压缩的保留边界——压缩只重写模型消息正文,system/protected 原样保留;React Plan Notebook 属 runner 控制面、推理摘要只走事件流,均不在压缩输入中;交付证据文档与契约测试,不改变运行时行为。详见 核查文档 与 归档记录。
  • bounded-proactive-trigger-loop(Q;已归档 205,已归档并稳定):新增 orchestration/proactivedriver 宿主侧单 worker 有界驱动,把 wakeuprouting 的 admission intent 经注入的 admission/executor 完成闭环;进程内幂等与窗口预算,planner 错误不认领、rejected 不执行、预算耗尽不消费 trigger,不建全局 dispatcher、队列或终态。详见 归档记录 与 路线图。
  • outbound-notification-delivery-port(R;已归档 206,已归档并稳定):新增 orchestration/outbounddelivery reference-only 出站 descriptor 与最小 webhook DeliverySink;2xx 送达,408/429/5xx 与网络错误有界重试、其他状态终态失败,Idempotency-Key 由接收方去重,错误与日志脱敏;不建全局 notification service、投递账本或 exactly-once。详见 归档记录 与 路线图。
  • plugin-bundle-contract(S;已归档 207,已归档并稳定):新增 extension/plugin bundle 清单、plugin:<bundle>:<tool> 命名空间与 plugin.lock.v1 锁文件(稳定排序、原子替换、digest fail-closed),以及 extension/plugin/hookproc argv-only 有界子进程 hook;准入仍归 extension,不做 marketplace、动态加载与签名信任链。详见 归档记录 与 示例。
  • multi-thread-session-parallel-semantics(P;已归档 204,已归档并稳定):只做语义决策——thread 是 session 内的因果 Run 链标识,不是并行执行单元;会话内并行 thread 在 0.x 显式 unsupported,并行表达走 teams 或独立 session,并给出反向决策所需的影响清单与负向用例。详见 语义决策 与 归档记录。
  • event-wakeup-session-claim-routing(O;已归档 203,已归档并稳定):新增 orchestration/wakeuprouting 只读 planner,把外部事件转换为确定性 session/thread routing key,经既有 instance affinity 解析 owner 并产出 AdmissionIntent;无亲和/目标消失 fail-closed,不执行 handler、不 ack、不推进 cursor。详见 归档记录 与 路线图。
  • long-running-tool-resume-capability-negotiation(N;已归档 202,已归档并稳定):工具通过可选 ResumeSpec() 显式声明可恢复边界,tool/local 在结果边界校验并在未声明时 fail-closed(reason_code=tool_resume_unsupported),不暂停、不 checkpoint;声明通过后复用既有 checkpoint,已完成 effect 不重跑,且不承诺 exactly-once。详见 路线图。
  • durability-recovery-guarantee-matrix(M;已归档 201,已归档并稳定):在运行时 Harness 架构文档新增持久性与恢复保证矩阵,汇总既有 owner contract 的恢复范围、部署边界和证据路径,不改变运行时行为;详见 路线图。
  • redis-message-bridge-cross-instance(L;已归档 200,已归档并稳定):core/sourcecoordination.Redis 实现既有 Coordinator(租约 + fence + revision CAS,ping 失败 fail-closed 不上报 cross_machine);orchestration/mailbox.RedisStore 以「mailboxState 复用 + Redis 状态文档 + 分布式锁」与 memory/file 语义逐字节一致;core/runner 引入 CursorStore(memory 默认、redis 注入、出错回落内存);新增 orchestration/instanceregistry(实例心跳 TTL 与 session affinity);配置域 runtime.coordination.* 默认仍走 memory/file,未配置时 cross_machine 保持 unsupported 且 fail-closed。详见 归档记录 与 Redis 协调指南。
  • introduce-mainstream-sandbox-executor-backends(K;已归档 199,已归档并稳定):把 e2b、open-sandbox、anthropics/sandbox-runtime 映射到既有 canonical oci_runtime,交付 adapter/sandboxexternal、config 注册与 fail-fast 校验、runtime×kind 冻结失败分类矩阵和 onboarding 示例;默认 Disabled,不改变 observe + default_action=host 姿态,本仓仍不内置生产级隔离执行器。详见 归档记录。
  • refresh-upstream-findings-current-pin(已归档 197):按当前 Baymax pin 固化 upstream findings、contract evidence 和 provider live-smoke 配置边界;只更新 provenance/证据,不提升 unsupported capability。详见 归档记录。
  • role-scoped-runtime-ports-and-owner-index(已归档 193):为 resolver material、model surface 与 source adapter 三类既有语义建立可校验的唯一 owner 和证据索引;不收窄 runtime port 或改变运行时行为。详见归档记录与路线图。
  • host-authorization-provenance-and-resume-revalidation(已归档):宿主恢复授权的可选 provenance 已在 source claim 前重验证 policy 和 source scope,并保留旧版省略字段与取消语义。详见 归档索引。
  • source-adapter-lifecycle-contract(已归档 190):source-bound 外部投递、有限 disposition、pending evidence 和 cursor-after-commit;参见 source adapter 指南。
  • attention-oriented-runtime-diagnostics-projection(已归档 191):只读、有界待处理事项投影;分类和行动基于既有诊断及显式 owner 证据。详见 归档索引。
  • model-surface-revision-and-bounded-context-contract(已归档 192):resolver material 的固定有效 UTF-8 有界准入,以及显式、provider-neutral 的模型可见面 revision/digest/length replay 证据;参见 归档索引。
  • child-composer-continuation-contract(已归档 194):child checkpoint 已绑定 source cursor,并已验证三类 pause reason 的 fresh-owner 恢复与 capability evidence;声明范围限定为显式 File owner + native history + executor 的 same-host/single-writer/sequential reopen profile,其他 owner 或部署范围仍保持 unsupported。
  • team-native-continuation-checkpoint-restore(已归档 195):team continuation 已补齐聚合策略、投票参与 provenance 与 tie-break 的恢复绑定;能力声明仍限定为已验证的 same-host profile。
  • deployable-source-history-store-contract(已归档 196):source identity、journal、可选 projection ledger、coordinator 与 deployment scope 已绑定为显式 owner-store profile;跨机器协调和 source/projection 原子提交仍不声明支持。
  • mailbox-agent-pause-restore-boundary(已归档):显式 NewContinuationWorker + durable FileStore + registered resumer/revalidator 的 handler continuation 已具备三类 pause 的 fresh-process、successor lineage、duplicate/no-effect-rerun 和 terminal policy 证据;能力仅限 same-host/single-writer/sequential reopen。默认 lifecycle-only worker、mailbox replay/redelivery、跨机器/多写者恢复和 planbridge resumed execution 仍 unsupported。
  • 当前 pin 的 upstream finding 与 Baymax contract evidence 见 current-pin findings 和 contract evidence matrix。该 evidence refresh 只对齐 provenance、部署前提和未验证边界,不提升 subagent_fanout、team_parallel、team_vote 或未配置 owner 的 mailbox Agent continuation;provider live-smoke 未配置 endpoint/model/key 时保持 skipped-unconfigured。

要了解某个历史决策,请从归档索引进入对应 proposal/design/verification;不要把归档记录当作当前进行中的工作。

文档与事实源

模块 README

a2a/README.md · core/runner/README.md · core/types/README.md · tool/local/README.md · mcp/README.md · model/README.md · context/README.md · context/handoff/README.md · context/hostprojection/README.md · memory/README.md · orchestration/README.md · adapter/README.md · host/eventadapter/README.md · integration/README.md · runtime/config/README.md · runtime/diagnostics/README.md · runtime/security/README.md · observability/README.md · skill/loader/README.md

示例

examples/01-chat-minimal、examples/quickstart、02-tool-loop-basic、03-mcp-mixed-call、04-streaming-interrupt、05-parallel-tools-fanout、06-async-job-progress、07-09 多 agent 示例,以及 examples/agent-modes/MATRIX.md 模式矩阵。技能分层发现(runtime.skill.discovery.ancestor_layers)为 opt-in 配置能力,未新增示例;默认关闭,既有示例行为不变。宿主投影 provenance 不变量由调用方 resolver 是否实现 ProvenanceResolver 启用,同样未新增示例。

Agent mode 专项门禁:scripts/check-agent-mode-real-runtime-semantic-contract.sh、scripts/check-agent-mode-readme-runtime-sync-contract.sh、scripts/check-agent-mode-anti-template-contract.sh、scripts/check-agent-mode-doc-first-delivery-contract.sh(Windows 使用同名 .ps1 入口)。

开发验证

go test ./...
go test -race ./...
golangci-lint run --config .golangci.yml
bash scripts/check-docs-consistency.sh
bash scripts/check-openspec-documentation-impact.sh
bash scripts/check-quality-gate.sh

Windows 使用等价的 pwsh -File scripts/check-docs-consistency.ps1、check-openspec-documentation-impact.ps1 和 check-quality-gate.ps1。文件占用时,按 故障排查 使用隔离缓存逐包验证并记录未执行项。

提案治理

每个新 OpenSpec proposal/design/tasks 都必须包含 Documentation Impact Assessment,逐项判断 architecture、components、configuration、contract/API、diagnostics、examples、CLI/integration、best practices、roadmap,并提供 affected paths、owner 和 verification。行为/配置/contract/诊断/示例变化还必须声明 Example Impact Assessment。三份工件均须接受 Public Semantic Documentation Commitment;公开 API/contract、运行时行为、事件与终态、错误、配置、诊断、CLI/integration 或示例语义发生变化时,维护文档必须与变更同批提交,声明维护路径、owner 和验证证据;无变化也须写具体理由。

文档门禁:

  • scripts/check-openspec-documentation-impact.sh/.ps1:文档影响及公开语义同步承诺、跨工件一致性、变更面和链接;缺失、非法、无同步证据及声明漂移分别报出稳定分类码。
  • scripts/check-openspec-example-impact-declaration.sh/.ps1:示例影响声明。
  • scripts/check-openspec-roadmap-status-consistency.sh/.ps1:roadmap/OpenSpec/archive 状态一致性。

许可证与社区

详见 CONTRIBUTING.md、CODE_OF_CONDUCT.md、SECURITY.md、CHANGELOG.md 和 LICENSE。

Host execution plan bridge

Baymax includes the opt-in host_execution_plan.v1 bridge for hosts that need a bounded descriptor compiled against exactly one native execution owner. It supports inline direct, terminal-only parallel/vote teams, flat workflows, isolated local child dispatch and manifest-approved mailbox_async delegation to the existing mailbox owner. A configured mailbox handler continuation may be delegated only when the owner manifest exposes all requested pause cells and the same-host deployment scope; the bridge never creates the worker, resumer, queue, or restore loop. Resumed plan execution, subgraphs and shared child queues remain rejected before activation; descriptor digests and capability evidence are consistency facts, not authorization or business commit. See the offline example.

Source-owned native event history

The source-history contract is source-owned and read-only. Mailbox retains lifecycle facts through its existing MemoryStore/FileStore owner; runner, child, team and workflow can expose a retained journal only when the caller explicitly injects the matching owner journal. The deployable path is history.OpenOwnerStore, which binds source identity, journal, optional projection ledger, deployment request, and coordinator evidence without creating defaults. Memory journals are process-local; a plain FileStore supports same-host single-writer sequential reopen, while the file coordinator's fenced CAS profile is same-host multi-instance only, not cross-machine. Source append and an external projection remain separate commits: recovery uses stable source identity/cursor plus idempotent reconciliation, never a cross-project transaction or effect retry. The native event adapter remains a real-time callback projection: no callback ID or host observation sequence is a durable cursor, and replay cannot run, retry, resume, restore or commit a business effect. See the support matrix and integration guide and offline example.

Attention diagnostics

面向宿主的只读待处理事项投影见 attention diagnostics; 不会触发 retry/resume 或推断业务 effect 已提交。

Directories

Path Synopsis
adapter
modelcapability
Package modelcapability provides an explicit capability-discovery wrapper for model clients that intentionally implement only the minimal model SPI.
Package modelcapability provides an explicit capability-discovery wrapper for model clients that intentionally implement only the minimal model SPI.
cmd
host-jsonl command
Command host-jsonl serves the embedded host protocol over strict JSONL on stdin/stdout.
Command host-jsonl serves the embedded host protocol over strict JSONL on stdin/stdout.
context
budgetprojection
Package budgetprojection defines a versioned, bounded, read-only derived projection of budget facts that are owned elsewhere.
Package budgetprojection defines a versioned, bounded, read-only derived projection of budget facts that are owned elsewhere.
handoff
Package handoff defines the bounded, reference-first runtime handoff projection used when context is compressed or a run is resumed.
Package handoff defines the bounded, reference-first runtime handoff projection used when context is compressed or a run is resumed.
hostprojection
Package hostprojection defines the bounded, reference-only host context projection contract.
Package hostprojection defines the bounded, reference-only host context projection contract.
core
history
Package history provides a source-owned, read-only journal primitive for execution owners that need retained native event replay.
Package history provides a source-owned, read-only journal primitive for execution owners that need retained native event replay.
sourcecoordination
Package sourcecoordination provides source-owner scoped fencing and CAS for durable source state.
Package sourcecoordination provides source-owner scoped fencing and CAS for durable source state.
examples
01-chat-minimal command
durable-continuation-restore command
This example uses synthetic execution data and a local single-writer store.
This example uses synthetic execution data and a local single-writer store.
event-wakeup-routing command
Command event-wakeup-routing shows the offline composition of an external event, session/thread routing key, instance affinity and an admission plan.
Command event-wakeup-routing shows the offline composition of an external event, session/thread routing key, instance affinity and an admission plan.
execution-graph command
host-context-assembly command
This offline example uses a real runner with only synthetic opaque host references.
This offline example uses a real runner with only synthetic opaque host references.
host-resume-admission command
This offline example uses a real runner and synthetic host references.
This offline example uses a real runner and synthetic host references.
plugin-bundle command
quickstart command
redis-cross-instance command
Command redis-cross-instance demonstrates the Redis-backed coordination stack introduced by the cross-instance proposal:
Command redis-cross-instance demonstrates the Redis-backed coordination stack introduced by the cross-instance proposal:
sandbox-external-backends command
Command sandbox-external-backends demonstrates how mainstream external sandbox runtimes (e2b, open-sandbox, anthropic-sandbox-runtime) plug into the existing SandboxExecutor contract without changing the default posture.
Command sandbox-external-backends demonstrates how mainstream external sandbox runtimes (e2b, open-sandbox, anthropic-sandbox-runtime) plug into the existing SandboxExecutor contract without changing the default posture.
source-adapter-lifecycle command
Source adapter lifecycle is an offline integration example.
Source adapter lifecycle is an offline integration example.
Package extension contains transport-neutral extension governance primitives.
Package extension contains transport-neutral extension governance primitives.
plugin
Package plugin composes validated extension descriptors into plugin bundles.
Package plugin composes validated extension descriptors into plugin bundles.
plugin/hookproc
Package hookproc runs out-of-process plugin hooks with bounded I/O.
Package hookproc runs out-of-process plugin hooks with bounded I/O.
Package host provides a transport-neutral embedded host coordinator.
Package host provides a transport-neutral embedded host coordinator.
eventadapter
Package eventadapter observes one serial source callback stream.
Package eventadapter observes one serial source callback stream.
jsonl
Package jsonl implements the strict local JSONL binding for host envelopes.
Package jsonl implements the strict local JSONL binding for host envelopes.
sourceadapter
Package sourceadapter provides an explicit, bounded external-source delivery lifecycle.
Package sourceadapter provides an explicit, bounded external-source delivery lifecycle.
integration
scenariosimulation
Package scenariosimulation contains bounded, offline-only contracts used by integration tests.
Package scenariosimulation contains bounded, offline-only contracts used by integration tests.
mcp
model
catalog
Package catalog provides a bounded, host-injected provider/model admission catalog.
Package catalog provides a bounded, host-injected provider/model admission catalog.
conformance
Package conformance contains the provider-neutral, bounded stream-edge projection used by adapter tests and replay tooling.
Package conformance contains the provider-neutral, bounded stream-edge projection used by adapter tests and replay tooling.
observability
orchestration
graph
Package graph defines bounded, deterministic execution topology facts.
Package graph defines bounded, deterministic execution topology facts.
instanceregistry
Package instanceregistry records live instances and session→instance affinity in a shared store so a routing layer can forward sticky sessions across pods.
Package instanceregistry records live instances and session→instance affinity in a shared store so a routing layer can forward sticky sessions across pods.
outbounddelivery
Package outbounddelivery defines a reference-only outbound notification descriptor and a minimal webhook delivery sink implemented by the host.
Package outbounddelivery defines a reference-only outbound notification descriptor and a minimal webhook delivery sink implemented by the host.
outboxbridge
Package outboxbridge binds a host-owned application outbox to one native owner.
Package outboxbridge binds a host-owned application outbox to one native owner.
planbridge
Package planbridge compiles bounded host descriptions and delegates to native owners.
Package planbridge compiles bounded host descriptions and delegates to native owners.
proactivedriver
Package proactivedriver runs one bounded host-side loop that turns planned wakeups into admissions and executions.
Package proactivedriver runs one bounded host-side loop that turns planned wakeups into admissions and executions.
wakeuprouting
Package wakeuprouting plans how an external event reaches the instance that owns a session, without executing a handler, acknowledging the event or advancing a source cursor.
Package wakeuprouting plans how an external event reaches the instance that owns a session, without executing a handler, acknowledging the event or advancing a source cursor.
runtime
skill
tool
schemaaudit
Package schemaaudit provides a bounded, provider-neutral offline audit of admitted tool schema pressure and synthetic selection quality.
Package schemaaudit provides a bounded, provider-neutral offline audit of admitted tool schema pressure and synthetic selection quality.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL