Einstein-Harness
English | 中文
全球首个「组织化」AI 智能体运行框架 —— 33 项冒烟全绿(接口层 18-24 + 生态 25-31 + 通道/兼容层 32-33)、四项硬压测有数据。 版本:0.3.0(VERSION 文件+init.version+pyproject 三处同步单一事实源) 设计文档:
docs/DESIGN-全量合成版.md红线:不复制任何框架代码,只吸收思想(Pi / Kosong / OpenHands / Letta / Muse Sentinel / DSH / LangGraph / OpenAI Agents SDK)。
一图看懂六层架构
你(老板·手机)
│ 目标下达 · steer插话 · 批准/驳回 · 战报阅读
▼
┌─────────────────────────────────────────────────────────────────┐
│ L5 cockpit/ 指挥层(本轮新增) │
│ dashboard.py 任务看板:实体状态/运行中任务/审批队列/组织脉搏 │
│ → 一个 markdown 文件,手机直接读 │
│ remote.py 远程干预四动词:steer / approve / deny / cancel │
│ (每个动作落 remote_audit.jsonl,可追溯) │
│ briefing.py 定时战报:总线 seq 游标增量 + 动作/数字/坑 三要素 │
├─────────────────────────────────────────────────────────────────┤
│ L4 org/ + bus/ 组织层(全球独有维度) │
│ registry.py 多形态实体注册表(A常驻/B团队/C端点/D服务) │
│ T0 注册法则 + 法定代理解析(sector→主Agent代行) │
│ locks.py 写锁互斥 + 过期死锁自动清理 │
│ proxy.py 法定代理执行域:锁/错误/对外协作三代行,全留痕 │
│ events_bus.py 主题 pub/sub + JSONL append-only + 扇出隔离 │
├─────────────────────────────────────────────────────────────────┤
│ L3 orchestrate/ 编排层 │
│ graph.py Pregel 式大图:super-step barrier + 逐步 checkpoint │
│ + time-travel(从任意 checkpoint 分叉重跑) │
│ interrupts.py 图级 human-in-the-loop:pause/inspect/edit/resume │
│ modes.py Handoffs(整体移交)vs Agents-as-tools(子任务委托) │
├─────────────────────────────────────────────────────────────────┤
│ L2 session/ + core/ 运行时 │
│ jsonl_session.py JSONL 分支会话:fork/rollback/subsession │
│ compaction.py 无损上下文协议:压缩=零删除只加指针📎 │
│ 全量快照+锚点索引+抽样校验(全球唯一无损方案) │
│ core/loop.py gather→act→verify 极简核(Kosong 机制/策略分离)│
│ core/events.py 类型化 Action/Observation 事件链 append-only │
│ core/agent.py 声明式 AgentSpec + EchoBackend(离线确定性) │
│ core/tools.py 类型化工具注册表 + 4 真实内置工具 │
├─────────────────────────────────────────────────────────────────┤
│ L1 生态接入三大件(0.2.1 B路新增) │
│ mcptools/ MCP 工具池:server_registry.yaml 声明式接入 │
│ stdio(npx/uvx 子进程 JSON-RPC)+streamable HTTP │
│ 加载≠放行:MCP 工具同走 guard 三档守门 │
│ browser/ Playwright 浏览器子代理:只读(navigate/screenshot/ │
│ read_dom/read_text)+接管(click/type/press)双模式 │
│ 截图落盘留路径;选择器注入策略过滤;每动作过守门 │
│ sandbox_docker/ Docker 沙箱信任边界:cpus/mem/pids 限制+网络关闭 │
│ +非-root+任务结束销毁;docker 不可用诚实降级 Process │
├─────────────────────────────────────────────────────────────────┤
│ L0 memory/ 亿忆引擎 │
│ tiers.py 四级阶梯 blocks→files→rag→archival + 跨层晋升 │
│ memfs.py git 化记忆:blob 内容寻址+提交历史+diff+revert │
│ 历史只增不减 + 双写备份 │
├─────────────────────────────────────────────────────────────────┤
│ 横向 guard/ 守门层(Muse Sentinel 开源化) │
│ 提议≠放行:agent 提议,独立守门 allow/deny/ask │
│ 三档权限 + shell 注入防护 + 路径逃逸检查 + 审批卡片 + 审计轨迹 │
├─────────────────────────────────────────────────────────────────┤
│ 横向 observe/ 观测层 │
│ tracing.py trace+span 两级(OpenAI SDK 标准) │
│ replay.py 轨迹重放/步进/分叉/对比(DSH Trajectory 思想) │
├─────────────────────────────────────────────────────────────────┤
├─────────────────────────────────────────────────────────────────┤
│ interfaces/ 接口层五大件(0.2.x C路新增) │
│ acp_server ACP 服务端:stdio JSON-RPC(agent-client-protocol) │
│ initialize/session/new/load/prompt + update 事件流 │
│ → JetBrains/Zed 直连(每行一消息 ndjson) │
│ wire.py Wire 协议:soul↔UI 事件流(Kimi Wire 思想) │
│ print(人类可读)/ json(JSONL)双模式 + seq 游标重放 │
│ multimodal 图像输入:base64/路径→ImageBlock→消息流 │
│ vision API 走 providers;无 API 确定性降级占位 │
│ bundles.py Bundle→Profile→Patch→Overlay 四级叠加(DSH 思想) │
│ 插件=apply(ctx) 注册工具/技能/AgentSpec;合并可审计 │
│ web_server Web UI 零依赖(http.server :8901) │
│ 看板页/任务页/审批页 + JSON API + 四动词干预 │
│ cli.py eh serve/run/dashboard/install-bundle(pip 入口) │
│ channels/ 通讯通道层(0.3.0 新增) │
│ feishu_channel 飞书:事件订阅 webhook + AES 加密回调 + challenge │
│ 群聊@触发/私聊直答 + event_id 幂等 + 出站加签 │
│ dingtalk_channel 钉钉:加签验签 + 时间戳新鲜度 + 群@剥离(同构) │
│ webhook_registry.yaml 通道声明式配置(值=环境变量名,密钥零入库) │
│ 纪律:外发 = workspace_write 级动作,统一过守门+审计,默认 fail-closed│
├─────────────────────────────────────────────────────────────────┤
│ compat/ 生态兼容层(0.3.0 新增) │
│ dsh_converter DSH cordis.patch.yml → EH bundle 骨架 │
│ 声明层可装可 resolve;TS 逻辑 external 标注待人工 │
│ +MCP 桥接建议;!!js 容错降级字符串,永不执行 │
├─────────────────────────────────────────────────────────────────┤
│ 横向 bench/ 压测层(本轮新增) │
│ 四项硬压测:并发会话/事件链10万/50节点大图/千条无损压缩 │
│ 框架不能当第二个黑盒——性能也必须可测量 │
├─────────────────────────────────────────────────────────────────┤
│ workload/ 真实负载:写作天团 7 智能体(L3+L4 联合验证 SOP) │
│ providers/ 真实 LLM 后端:Zhipu / DeepSeek / OpenAI 兼容层 │
└─────────────────────────────────────────────────────────────────┘
六层能力一览
| 层 | 模块 | 核心主张 | 冒烟 |
|---|---|---|---|
| L5 指挥 | cockpit/ |
老板一屏总览 + 四动词遥控 + 定时战报 | #16 |
| L4 组织 | org/ bus/ |
多形态实体注册 + 写锁互斥 + 法定代理 + 事件总线 | #13 #14 #15 |
| L3 编排 | orchestrate/ |
checkpoint 大图 + time-travel + 双编排模式 | #9 #10 #11 |
| L2 运行时 | session/ core/ |
分支会话 + 无损压缩 + 极简核 | #2 #4 #5 |
| L0 记忆 | memory/ |
四级阶梯 + git 化 MemFS + 双写备份 | #6 #7 |
| 守门 | guard/ |
提议≠放行 + 三档权限 + 审批卡片 | #3 #8 |
| 观测 | observe/ |
trace/span + 轨迹重放分叉 | #12 |
| 压测 | bench/ |
四项硬数据,拒绝黑盒 | #17 |
| 通道 | channels/ |
飞书/钉钉 webhook 双通道 + 外发过守门 | #32 |
| 兼容 | compat/ |
DSH cordis 补丁 → EH bundle(声明层可装) | #33 |
系统要求
| 项目 | 要求 | 说明 |
|---|---|---|
| Python | >= 3.10 | 唯一硬性依赖 |
| 操作系统 | macOS / Linux / Windows / 鸿蒙 PC* | 纯 Python 实现,全系统行为一致 |
| 依赖包 | pyyaml, pydantic | 均为纯 Python 包,无 C 扩展,pip 全平台可装 |
可选增强(缺失时自动优雅降级,核心功能 100% 可用):
- Node.js + npx:MCP 工具池的 stdio server(如官方 filesystem server)
- uvx:fetch 类 MCP server
- Docker:容器沙箱执行(缺失自动降级为本地 Process 沙箱,
degraded=True如实标注) - Playwright + Chromium:浏览器子代理
Windows 注意:建议在 PowerShell 或 WSL 中使用;路径处理已全量使用 pathlib/tempfile,无 Unix-only 硬编码。
鸿蒙:HarmonyOS PC(提供 Python 3.10+ 运行时)可直接安装(待真机验证,ARM64 纯 Python 兼容性极高);鸿蒙手机/平板走服务端模式——EH 跑在云端或 PC,鸿蒙 App 通过 Web UI (:8901) 或 ACP 协议远程连接(架构原生支持)。
快速上手
cd einstein-harness(本仓库)
python3 smoke.py # 33 项冒烟,全绿即健康(<90s)
python3 -m bench.bench # 标准档压测,出 markdown 报告
python3 -m bench.bench --quick # 快速档(冒烟内嵌同款)
python3 -m pytest tests/ -q # 单元测试 66 项
python3 workload/run_crew_demo.py # 真实 LLM 跑写作天团(需 API key)
MCP 工具池:两分钟接入(生态 B路)
mkdir -p /tmp/einstein-mcp-ws && echo hello > /tmp/einstein-mcp-ws/a.txt
cd einstein-harness(本仓库)
python3 -m mcptools.client list --registry mcptools/server_registry.yaml
# → filesystem: 16 tools -> read_file, read_text_file, …(npx 真实拉起官方 server)
python3 -m mcptools.client call --registry mcptools/server_registry.yaml \
filesystem read_text_file '{"path": "/tmp/einstein-mcp-ws/a.txt"}'
# → hello
# 纪律:加载≠放行——所有 mcp__* 工具的 Tool.danger 已标注,同走 guard 三档守门
浏览器子代理 / Docker 沙箱(生态 B路)
import sys; sys.path.insert(0, ".")
from core.tools import Toolbox
from browser import BrowserAgent
from sandbox_docker import create_sandbox
box = Toolbox()
with BrowserAgent(box, artifacts_dir="/tmp/shots", mode="take_over") as ba: # 只读模式去掉 take_over
box.call("navigate", {"url": "https://example.com"})
print(box.call("screenshot", {"label": "demo"}).content) # PNG 落盘返回路径
prov, real, why = create_sandbox() # docker 不可用时诚实降级 (real=False)
h = prov.start(image="alpine:latest", cpus=0.5, memory_mb=128)
print(prov.exec(h, "echo hi && id -u").stdout) # 非-root、无网络、可销毁
prov.stop(h)
通讯通道:飞书 / 钉钉双通道(0.3.0)
import sys; sys.path.insert(0, ".")
from channels import load_channel_registry, ChannelManager
from channels.feishu_channel import FeishuChannel
from channels.dingtalk_channel import DingtalkChannel
from core.loop import GateDecision, AgentLoop
from core.agent import Agent, AgentSpec, EchoBackend
from core.tools import default_toolbox
from core.events import EventLog
reg = load_channel_registry("channels/webhook_registry.yaml")
feishu_cfg = reg["channels"]["feishu"] # 密钥从环境变量读:EH_FEISHU_WEBHOOK_URL / EH_FEISHU_SECRET / …
# EH loop 是唯一回答者(EchoBackend 离线示例;生产换 providers 真模型)
def responder(msg):
agent = Agent(spec=AgentSpec(name="im-bot", instructions="答复用户"),
backend=EchoBackend([{"text": f"收到: {msg.text}"}]),
toolbox=default_toolbox(), workspace=".")
return AgentLoop(agent, EventLog("runs/channel.jsonl")).run(msg.text).final_text
sent = []
mgr = ChannelManager(
transports={"feishu": lambda url, p: (sent.append(p), __import__("channels.base", fromlist=["TransportResult"]).TransportResult(True, 200, "{}", url))[1]},
gate=lambda a, g, c: GateDecision(verdict="allow", reason="workspace_write 放行"),
audit_path="channels/channel_audit.jsonl")
feishu = FeishuChannel(feishu_cfg, mgr, responder)
print(feishu.handle_callback({"type": "url_verification", "challenge": "abc"})) # → {"challenge": "abc"}
# 消息事件(群聊被 @ 触发 / 私聊直答 / event_id 幂等 / AES 加密回调可选)
r = feishu.handle_callback({"header": {"event_type": "im.message.receive_v1", "event_id": "e1", "token": ""},
"event": {"sender": {"sender_id": {"open_id": "ou_x"}},
"message": {"chat_type": "p2p", "chat_id": "oc_x",
"content": '{"text":"你好EH"}'}}})
# → {"ok": True, "reply": {"ok": True, "sent": True, ...}} 外发已过守门+审计
dingtalk = DingtalkChannel(reg["channels"]["dingtalk"], mgr, responder) # 同构:加签验签+时间戳新鲜度
纪律:外发消息 = workspace_write 级动作——统一过 guard 守门(默认 fail-closed ASK,审批后放行),
决策落 channels/channel_audit.jsonl;密钥只从环境变量读,注册表里只有变量名。
DSH 补丁转换器:cordis.patch.yml → EH bundle(0.3.0)
import sys; sys.path.insert(0, ".")
from compat.dsh_converter import convert_file
bundle_dir = convert_file("cordis.patch.yml", bundle_name="my-dsh", out_dir="./bundles")
# → bundles/my-dsh/bundle.yaml 声明层:BundleRegistry.add_dir 直接可装可 resolve 可 apply
# → bundles/my-dsh/external_logic.md 逻辑层:external 标注 + MCP 桥接建议(TS 逻辑不翻译不复制)
30 行跑通「任务 → 守门 ASK → 老板放行 → 看板 + 战报」
import sys; sys.path.insert(0, ".")
from core.agent import Agent, AgentSpec, EchoBackend
from core.loop import AgentLoop
from core.tools import default_toolbox
from core.events import EventLog
from guard.permissions import PermissionPolicy
from guard.gatekeeper import PolicyGatekeeper
from cockpit.dashboard import TaskBoard, TaskRecord, CockpitDashboard
from cockpit.remote import RemoteControl
tasks = TaskBoard("/tmp/demo/runs.jsonl")
tasks.upsert(TaskRecord(task_id="t-1", title="写终稿", status="running"))
gate = PolicyGatekeeper(PermissionPolicy.read_only(), audit_path="/tmp/demo/audit.jsonl")
agent = Agent(spec=AgentSpec(name="wenxin", instructions="write", include_tools=("write_file",)),
backend=EchoBackend([{"tool_calls": [{"name": "write_file",
"arguments": {"path": "/tmp/demo/final.md", "content": "终稿"}}]}]),
toolbox=default_toolbox(), workspace="/tmp/demo")
loop = AgentLoop(agent, EventLog("/tmp/demo/t.jsonl"), gate=gate)
r = loop.run("交终稿") # → paused_ask(守门拦下)
tasks.upsert(TaskRecord(task_id="t-1", title="写终稿", status="paused_ask",
pending_action_id=r.pending_action_id, pending_reason="写文件需审批"))
print(CockpitDashboard(tasks).render_board()) # 老板手机看到待审批卡
remote = RemoteControl(tasks, audit_path="/tmp/demo/remote_audit.jsonl", loops={"t-1": loop})
remote.approve("t-1") # 老板手机点「批准」
loop.resume() # 动作放行,文件落盘
tasks.upsert(TaskRecord(task_id="t-1", title="写终稿", status="done", detail="已交付"))
压测数据(2026-12-02 · macOS arm64 · CPython 3.15.2 · 标准档)
| 压测 | 规模 | 结果 | 结论 |
|---|---|---|---|
| B1 并发会话 | 10 会话同时跑完整 loop | 总耗时 0.009s,吞吐 1140 会话/s,全部结果正确 | 调度开销可忽略,瓶颈在模型不在 harness |
| B2 事件链吞吐 | 100,000 事件 append-only 写入 | 写 25,826 事件/s,重放 313,365 事件/s,17.67MB 日志 | 全轨迹审计的成本底价 ≈ 39µs/事件 |
| B3 大图执行 | 50 节点串行图 × 5 轮 | 17,323 super-step/s,checkpoint 放大仅 1.04×,0.058ms/步 | 逐步 checkpoint 几乎零代价 |
| B4 无损压缩 | 1,000 条消息 | 压缩 78.6 万条/s,锚点索引比 0.263,抽样 10 锚点零失配,字节守恒 ✅ | 无损主张规模化成立:索引 26% 体积换 100% 可恢复 |
快速档(冒烟 #17 内嵌)同样四项全绿;报告全文:
bench/压测报告-20261202.md。 单机参考值,量级与比值是结论重点。
与竞品对照(为什么全球唯一)
| 维度 | LangGraph | OpenAI Agents SDK | DSH 扣子 | Letta | Manus | Einstein-Harness |
|---|---|---|---|---|---|---|
| 压缩 | 有损 summary | server-side 有损 | 有损 pipeline | 有损 | 有损 compact | 零删除📎锚点(唯一无损) |
| 组织 | 无 | 无 | 多 Agent 画布 | 单体记忆 | 项目空间 | 多形态实体注册+法定代理+写锁 |
| 守门 | 无内建 | guardrails 并行校验 | 权限模板 | 无 | 外置工程层 | Sentinel 提议≠放行+审批卡片 |
| 记忆 | 无内建 | memory 工具 | 变量槽 | 四级阶梯(云) | 文件系统 | 四级阶梯+git 化 MemFS 本地+双写 |
| 人管 | interrupts | 无 | 审批节点 | 无 | 人工接管 | L5 四动词手机遥控+战报 |
| 审计 | checkpoint | tracing | 轨迹回放 | 内部状态 | 任务回放 | 事件链 append-only+无损压缩=全轨迹可恢复 |
| 许可 | MIT | MIT | 私有 | 私有云 | 私有 | MIT 许可已备(仓库托管待定) |
核心不变量(设计哲学的工程化)
- 事件链 append-only——任何记录不修改不删除;审计/重放/分叉全部免费获得。
- 压缩无损——全量快照先行,上下文只换成 📎 锚点;一跳恢复原文,抽样校验机器执行。
- 提议 ≠ 放行——agent 提议动作,守门独立 allow/deny/ask;ASK 上审批卡片,老板手机决策。
- 记忆零丢失——四级阶梯晋升不改写历史;MemFS revert 也是新增提交;双写备份兜底。
- 机制/策略分离——loop 不含业务策略;守门、权限、编排策略全部可热插拔。
- 老板在环——L5 看板是只读投影,四动词是唯一写入口;每个干预落审计。
目录结构
einstein-harness/
├── core/ # L2 内核:loop/events/agent/tools
├── session/ # L2 运行时:分支会话 + 无损压缩
├── memory/ # L0 亿忆:四级阶梯 + MemFS
├── guard/ # 横向守门:策略守门 + LLM 守门 + 审批卡片
├── orchestrate/ # L3 编排:大图 + 中断 + 双模式
├── observe/ # 横向观测:tracing + 轨迹重放
├── org/ + bus/ # L4 组织:注册表/锁/代理 + 事件总线
├── cockpit/ # L5 指挥:看板 + 四动词遥控 + 战报
├── bench/ # 压测:四项硬数据 + 报告生成
├── workload/ # 真实负载:写作天团 7 智能体
├── mcptools/ # L1 生态:MCP 工具池(stdio + streamable HTTP,加载≠放行)
├── browser/ # L1 生态:Playwright 浏览器子代理(只读/接管双模式)
├── sandbox_docker/ # L1 生态:Docker 沙箱信任边界(不可用诚实降级 Process)
├── providers/ # 真实 LLM 后端(智谱/DeepSeek/OpenAI 兼容)
├── channels/ # 0.3.0 通道层:飞书/钉钉 webhook 双通道(签名/加密/@触发/守门外发)
├── compat/ # 0.3.0 兼容层:DSH cordis.patch.yml → EH bundle 转换器
├── tests/ # pytest 单元测试(指挥层/红队/调度/并行/通道/转换器 66 项)
├── smoke.py # 33 项冒烟(exit 0 = 全绿)
└── DESIGN.md # 设计决策记录(ADR 式)
路线图
- ✅ D2-D3:L2 运行时 + L0 亿忆 v0(round 1)
- ✅ D4-D5:横向守门 + 观测层 + L3 编排(round 2)
- ✅ D6-D7:L4 组织层 + 写作天团真实负载(round 3)
- ✅ 本轮:L5 指挥层 + 硬压测 + 文档化(round 4)
- ✅ 0.2.0(C路):接口层五大件——ACP 服务端/Wire 协议/多模态/Bundle 四级叠加/WebUI + pip 打包(eh CLI)
- ✅ 0.2.1(B路):生态接入三大件——mcptools MCP 工具池(stdio+streamable HTTP)/ browser Playwright 子代理 / sandbox_docker Docker 沙箱(诚实降级)
- ✅ 0.2.2(B路):时间层与主动性三大件——schedule 调度器(heartbeat/cron/触发器三层全过守门)/ orchestrate.parallel Send 动态并行 / core.code_mode CodeAct(AST 白名单)
- ✅ 0.3.0:通讯通道层(channels/ 飞书+钉钉 webhook 双通道:签名/加密回调/群聊@触发/外发过守门)+ 生态兼容层(compat/dsh_converter:DSH cordis.patch → EH bundle,声明层可装逻辑层 external 待人工)+ PyPI 0.3.0 发包就绪
- ⏭ 下一步:A2A 远程实体、OTel 导出、Scheduled Dreaming、通道层更多平台(Slack/WhatsApp)
Metadata
Release files for einstein-harness 0.3.0
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 |
|---|---|---|---|---|
| einstein_harness-0.3.0.tar.gz | 183.8 kB | Without provenance | Details for einstein_harness-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| einstein_harness-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for einstein_harness-0.3.0-py3-none-any.whl |
Total release size: 373.5 kB
Release files / einstein_harness-0.3.0.tar.gz
| Download URL | einstein_harness-0.3.0.tar.gz |
|---|---|
| Size | 183.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bc606c0bcc6a7252aebd69f03cf8afeb3b4a221830d08d2488b37d7268577935
|
|
BLAKE2b-256 checksum How to use checksums |
62c8882dcf158e0978185e25f1d9aee549b9e8264ff91f50c70738ccc09bee28
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.15.2
|
Release files / einstein_harness-0.3.0-py3-none-any.whl
| Download URL | einstein_harness-0.3.0-py3-none-any.whl |
|---|---|
| Size | 189.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5408aa05d20fe4841dcb37bd1887d0217e1a33f7567f1d158275b58aee5eee0d
|
|
BLAKE2b-256 checksum How to use checksums |
035d5d14394a2ef20a7d0f41beadfb900712de35110249587aaee0b379d0d75b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.15.2
|
Security for einstein-harness 0.3.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.