Skip to content

Agent-Box Work Core v0.1:架构与执行流

面向开发者。描述 experiment/work-core-v0.1 当前已经实现并完成真实 E2E 验证的原型。

1. 一张图看懂当前原型

图例:

  • 蓝色:Work Core 自己拥有的语义和代码。
  • 黄色:Work Core 到 provider 的窄适配层。
  • 紫色:Agent-Box 已有能力,原型直接复用。
  • 灰色:外部协议、runtime 或系统。
  • 实线:控制流;虚线:引用或动态数据投影。

2. Work Core 实现了什么

已实现

  • 独立 Work ID、objective、acceptance criteria、ProjectRef。
  • 固定 Plan → Execute → Review 状态机及 needs_replan / needs_fix 回路。
  • PlannerExecutorReviewer 三个逻辑 Role。
  • Role → Profile binding 与 binding revision。
  • 每次 Role 执行对应一个独立 Attempt。
  • Role/Profile → harness/model/workspace/capability 的 Effective Resolution。
  • ACP-first 的 session create、prompt、stream、permission、cancel、close。
  • Git worktree 创建、状态投影、patch 导出和安全 cleanup。
  • provider-neutral Effective Work State。
  • Handoff Artifact、Decision ledger、Artifact index 与 provenance。
  • Planner Profile replacement;新 Planner 使用新 native session 接续。
  • SQLite persistence 和 CLI 控制面。

刻意未实现

  • 通用 workflow engine、任意 DAG、动态节点 DSL。
  • 通用 Task/Issue 系统。
  • native transcript 迁移或跨 harness conversation resume。
  • mid-tool-call hot swap。
  • object store、分布式 scheduler、OTel Collector。
  • 新 sandbox runtime。
  • 自动 commit、merge 或 PR。
  • GUI 驱动的 E2E。

Table 1 — Core vs External Boundary

ComponentOwned by Core?Type (Own/Ref/Delegate/Adapter/External)Responsibility
Work lifecycleYesOwn创建、推进、停止、完成、cleanup
Fixed workflow state machineYesOwn校验 outcome,决定下一 phase/Role
Work / Attempt / Decision / Handoff / ArtifactRefYesOwnprovider-neutral identity、continuity、correlation
RoleBinding / EffectiveResolutionYesOwn嵌入 Work/Attempt 的不可变语义快照
Profile contentNoReferenceCore 只保存 profile_ref 和 digest;Profile 系统仍是权威来源
Project / WorkspacePartlyReference + Delegate保存 ProjectRef/WorkspaceRef;Git provider 管理实际 worktree
Native sessionNoReference保存 NativeSessionRef;不复制 native state/transcript
Workflow executionYesOwnv0.1 仅有固定小状态机,不委托外部 workflow runtime
Capability resolutionYesOwn + AdapterCore 定义 required/closure;adapter/provider 报告 available
Harness process controlNoAdapterACP adapter 统一 create/prompt/cancel/close
Model inferenceNoExternalClaude、Codex、Hermes/DeepSeek 执行实际 agent 工作
Environment projectionNoReference + Delegate复用 Profile、Project、既有 launch plan
Sandbox enforcementNoDelegate复用既有 bwrap launch surface
Artifact bodyNoDelegate文件系统保存正文;Core 只拥有索引与 digest
Persistence schemaYesOwn复用 Agent-Box SQLite/migration,新增五张 Work 表
CLIPartlyAdapter新增 WorkCommands,复用既有 CLI/REPL surface

3. 当前外部依赖

Table 2 — External Providers

ProviderCurrent ChoiceResponsibilityWhy Not Built in Core
Session transportACP + agent-client-protocol==0.9.0initialize、new session、prompt、stream、permission、cancel避免为每个 harness 重写 transport
Claude harnessclaude-agent-acp 0.70.0Planner/Reviewer native runtimeClaude 的工具、模型和 session 由 Claude runtime 拥有
Codex harnesscodex-acp 1.6.2Executor native runtimeCodex 的工具执行和模型选择由 Codex runtime 拥有
Hermes harnesshermes-agent 0.19.0 ACPreplacement Planner;实际模型 custom:deepseek-v4-proHermes/DeepSeek 推理不属于 Work continuity domain
WorkspaceGit worktree隔离 Work 代码状态、base/branch/diff、cleanupGit 已提供成熟 revision/worktree 语义
SandboxExisting bubblewrap/bwrap运行时挂载、cwd、权限隔离原型复用既有安全边界,不新增 sandbox runtime
EnvironmentExisting launch planProfile + Project + process env + mounts避免复制既有 launch/config 逻辑
Artifact bodyFilesystemPlan、report、handoff、patch 文件v0.1 不需要 object store
Artifact/source resultGit + patchtracked/new source result 与可恢复 diffGit 是代码状态的权威系统
PersistenceExisting SQLiteWork correlation、bindings、Attempt、Decision、refs单机原型不需要外部数据库
Control surfaceExisting CLI / agent-box execcreate、step、show、replace、cleanupGUI 不应阻塞 E2E

4. Role、Profile、Harness、Session、Attempt

ConceptMeaning
RoleWorkflow 中稳定的逻辑职责,例如 Planner。替换 Provider 后 Role 仍是 Planner。
ProfileAgent-Box 配置资源:harness、provider/model、instructions、skills、MCP、permissions、runtime preferences。
Harness实际 agent 产品/runtime 类型,例如 Claude、Codex、Hermes。
Native Session某个 harness 创建的临时会话。属于 provider,portable=false
Attempt一个 Role 在一个 binding revision 下的一次执行记录;连接 Core continuity 与一次 native session。

因此:

text
Role ≠ Profile ≠ Harness ≠ Native Session
Attempt = Role execution boundary + immutable resolution + native session reference

Attempt 为什么必要

  • Work 可能多轮进入同一个 Role;直接挂 session 无法区分每一轮。
  • 同一 Role 可以更换 Profile、Harness 和模型。
  • 每次运行需要冻结当时的 binding revision、Profile digest、capabilities 和 runtime identity。
  • Attempt 承担输入 Handoff、输出 Handoff、outcome、error 和 provenance correlation。
  • replacement 后必须创建新 Attempt;旧 Attempt 保留为历史证据,不被改写成 Hermes Attempt。

5. Core 数据结构

ProjectRefWorkspaceRefEnvironmentRefNativeSessionRef 当前是 JSON reference/value,不是独立 Core entity。原型没有单独的 ExternalRef 表。

下表中的七个对象/值均由 Core 定义;前五个独立持久化,后两个嵌入父对象。它们内部的 Profile、Workspace、Environment 和 NativeSession 内容仍只是 external reference。

Table 3 — Core Domain Objects

ObjectPurposeKey FieldsWhy It Exists
Work整个闭环的稳定 identity 和 workflow cursorid, objective, phase, status, role_bindings, workspace_ref, final_resultProvider replacement 后仍需有独立于 session 的工作主体
Attempt某 Role 的一次实际运行role_key, binding_revision, effective_resolution, native_session_ref, handoff ids, outcome支持多轮执行、replacement、错误与 provenance
Decision跨 Provider 保留的关键判断kind, summary, rationale, actor, related_attempt_idReviewer finding 和 replacement 不能只留在 transcript
Handoff从一个 Attempt 到目标 Role 的 continuation recordfrom_attempt_id, to_role_key, artifact_id, consumed_by_attempt_id把 durable state 交给下一 Role,并记录消费关系
ArtifactRefArtifact body 的小型索引kind, locator, digest, producer_attempt_id, metadata不建 object store,也能保留结果和校验 provenance
RoleBindingWork 内嵌的 Role→Profile 版本化映射role_key, profile_ref, revision, change_reasonreplacement 改映射而不改变 Role identity
EffectiveResolutionAttempt 内嵌的实际运行配置快照profile_digest, harness, model, capability_report, workspace_refProfile 可变化;已运行 Attempt 的上下文不可变化

6. Effective Work State

Effective Work State:

  • 不是单一数据库字段;
  • 不是 session transcript;
  • 是 Core records 与 provider-owned 当前状态的动态投影;
  • 每次 Attempt 启动前重新生成;
  • replacement 时提供不依赖旧 harness 的 continuation context。

Table 5 — Source of Truth

InformationSource of TruthStored in Core?How Used
Work identity/objective/acceptanceworksYes所有 Role 的稳定目标
Workflow phase/statusworks + fixed state machineYes决定下一 Role 和合法 outcome
Role→Profile bindingworks.role_bindings_jsonYesresolution 与 replacement revision
Profile instructions/provider/model intentExisting Profile systemRef + digest启动 harness,不复制完整配置
Attempt history/outcomework_attemptsYescompleted/provenance/continuation
Review findings/replacementwork_decisionsYes后续 Planner/Reviewer 的 durable context
Handoff correlationwork_handoffsYes选择最新未消费 Handoff并记录 consumer
Artifact index/digestwork_artifactsYes定位并校验 Plan/Report/Patch
Artifact bodyFilesystemReference only拼接 Handoff、读取最终结果
Git base/head/diff/dirtyGit workspaceReference + dynamic projection让新 Role看到真实代码状态
Effective runtime/model/versionACP response + Attempt snapshotYes, per Attemptprovenance;不依赖 Profile 当前值
Native conversationClaude/Codex/Hermes runtimeNo不用于跨 Provider continuation
Environment refs/permission intentProfile + Project + launch planRef + per-Attempt snapshotresolution 与 prompt constraints
Capability availabilityACP/session adapter + workspace/launchPer-Attempt snapshotfail-closed resolution

7. Handoff

当前 Handoff 最少承载:

  • objective 与 acceptance criteria;
  • workflow phase/status;
  • completed attempts;
  • decisions/findings;
  • pending Role/action;
  • current Role bindings;
  • workspace/Git snapshot;
  • Artifact refs;
  • Attempt provenance;
  • environment/capability constraints;
  • latest durable report。

区别:

ConceptScope
Effective Work State随时可重建的完整当前投影
Handoff某次 transition/replacement 生成、面向目标 Role 的 durable delivery package
Native transcriptProvider-owned conversation history;v0.1 不复制、不依赖

Current implementation: Handoff body 是 Markdown,其中包含完整 Effective Work State JSON 和 latest durable report。

Intended abstraction: Handoff 是 provider-neutral、可校验、可消费的 continuation package;不要求它永远使用当前 Markdown/完整投影格式。

8. Capability Resolution

Resolution 流程:

text
Role required capabilities
+ ACP harness probe
+ workspace/launch capabilities
= capability report
→ unsupported 非空:fail closed
→ unsupported 为空:产生 EffectiveResolution

术语:

SetMeaning
RequiredCapabilities当前 Role 要求的最小能力
AvailableCapabilitiesadapter、workspace、sandbox/launch 报告的原始能力
EffectiveCapabilities可实际使用;包括 True 与显式 degraded 能力
UnsupportedCapabilitiesrequired 但不可用;非空则阻止 Attempt 启动
DegradedCapabilities可继续使用但约束弱于理想状态,保留原因字符串

Table 4 — Capability Model

CapabilityRequired ByProvided ByCurrent Handling
headlessPlanner, Executor, ReviewerACP adapter executable + SDK probe必需;缺失则 resolution 失败
workspace_readPlanner, Executor, ReviewerGit workspace/launch必需
workspace_writeExecutorGit workspace/launchExecutor 必需
terminalExecutor, ReviewerACP harness必需;Planner 不要求
session_resumeACP adapter当前为 false;replacement 明确不 resume
mcpACP harness/Profile config记录 available;不进入 v0.1 Role closure
backgroundACP harness记录 available;未参与状态机
user_approval无硬性 requirementACP permission callback + CLI真实运行使用 Allow Once;未作为 Role fail-closed 条件
network_controlExisting sandbox/launch当前为 false;记录限制
sandbox_enforcement无硬性 requirementExisting bwrap/launch当前报告 degraded: broad rw root/share-net

9. 完整 Work 流程

贯穿示例:

text
Work: 为 Agent-Box 增加 capability resolver 改造
Workflow: Plan → Execute → Review

Planner  → claude-architect
Executor → codex-coder
Reviewer → claude-reviewer

Replacement:
Planner  → hermes-analyst (Hermes + DeepSeek)

真实 E2E 使用等价 Profile:

文档示例名实际验证 Profile
claude-architectlearn
codex-codercodex-main
claude-reviewerwork-e2e-reviewer
hermes-analysthermes-main

真实验收最终形成 6 个 Attempt、2 个 Decision、6 个 Handoff 和 13 个 Artifact;cleanup 后 Work/Core records 与 Artifact 保留,受管 worktree 已删除。

完整流程图

每阶段的 Core 变化

StageAttemptCore mutationProvider callArtifact / Decision
Create新 Work、三个 RoleBinding、WorkspaceRefGit worktree create
Plan 1P1Attempt + phase plan→executeClaude ACP sessionPlan + Executor Handoff
Execute 1E1Attempt + phase execute→reviewCodex ACP sessionImplementation Report + Reviewer Handoff
Review 1R1Attempt + phase review→planClaude ACP sessionReview Report + review_finding + Planner Handoff
ReplacePlanner binding revision 1→2无 native resumeprofile_replacement + replacement Handoff
Plan 2P2新 Attempt,binding revision 2;phase plan→execute全新 Hermes ACP sessionRevised Plan + Executor Handoff
Execute 2E2新 Attempt;phase execute→review新 Codex ACP sessionFix Report + Reviewer Handoff
Review 2R2新 Attempt;phase review→complete,status completed新 Claude ACP sessionApproved Review Report
Completefinal_result、cleanup pendingGit snapshot/exportGit Patch Artifact
Cleanupcleanup_state=completedGit worktree removeCore/Artifact provenance 保留

10. 从创建到替换再到完成:时序图

11. Current implementation vs intended abstraction

AreaCurrent implementationIntended abstraction represented by it
WorkflowFixedPlanExecuteReviewWorkflow Python transition tableWork Core owns workflow cursor and Role transitions
Session transportACP-first;每 Attempt 新进程/新 sessionHarness-specific session provider,可有 native escape hatch
HandoffMarkdown + 完整 Effective Work State JSON + latest reportProvider-neutral durable continuation package
Work State调用时动态投影为 dict/JSON多 source-of-truth 的统一读取模型
External refsJSON value/ref,没有独立 ExternalRef 实体Core 不复制 provider-owned state
Environmentenvironment_refs + permission intent;复用 launch planResolution 时组合 System/Project/Profile/Attempt context
Artifact storeFilesystem body + SQLite ArtifactRefArtifactProvider,可替换但 v0.1 不需要 object store
Workspace resultdirty worktree + durable Git Patch Artifact代码结果可恢复,cleanup 不丢 provenance
ObservabilityAttempt/error/native log ref;trace_ref=null预留 correlation,不接 OTel platform

12. 代码入口

ConcernFile
Domain modelsrc/agent_box/work/models.py
Lifecycle servicesrc/agent_box/work/service.py
Fixed workflowsrc/agent_box/work/workflow.py
Resolution/capabilitiessrc/agent_box/work/resolution.py
Effective Work Statesrc/agent_box/work/state.py
ACP adaptersrc/agent_box/work/acp.py
Git worktree providersrc/agent_box/work/workspace.py
Artifact providersrc/agent_box/work/artifacts.py
SQLite repositorysrc/agent_box/work/repository.py
Provider contractssrc/agent_box/work/providers.py
Migrationsrc/agent_box/migrations/003_work_core.sql
CLIsrc/agent_box/cli/commands/work.py
Real E2E probescripts/work-acp-probe.py

13. What v0.1 proves

已证明

  • Work identity 可以独立于任何 native session 生存。
  • Role binding 可以从 Claude Profile revision 1 切换到 Hermes Profile revision 2,而 Role 仍是 Planner。
  • replacement 后创建的是新 Attempt、新 EffectiveResolution 和新 native session。
  • session_resume=false 时,Hermes 仍能通过 Effective Work State、Handoff、Decision、Git 和 Artifact refs 理解现状并继续规划。
  • Claude Planner → Codex Executor → Claude Reviewer → Hermes Planner → Codex Executor → Claude Reviewer 的六 Attempt 链路可真实运行。
  • Reviewer 的 needs_replan 可以持久化为 Decision,并驱动 workflow 回到 Planner。
  • Profile/harness/model/version/capabilities 可以按 Attempt 快照并用于 provenance。
  • Git worktree 可以承载多 Role 共享的代码状态。
  • 结果可以保存为带 digest 的 Git Patch Artifact,再安全 cleanup dirty worktree。
  • SQLite + filesystem + Git 足以支撑本地 v0.1,无需 workflow engine、object store 或分布式系统。

尚未证明

  • 跨机器、分布式或长时间 daemon 调度。
  • CLI 进程退出后恢复一个仍 active 的 ACP connection。
  • native transcript 的可移植性;v0.1 明确不依赖它。
  • 任意 workflow/DAG、并行 Role 或动态 Role 集合。
  • mid-tool-call replacement。
  • 自动 commit、merge、冲突解决或 PR lifecycle。
  • object store、大 Artifact、远程 Workspace。
  • 完整 network policy 和强 sandbox enforcement;当前该能力被报告为 degraded。
  • OTel trace、GUI Work control surface 和生产级 operator UX。