可视化解读 OpenHarness:用 3% 代码复刻 Claude Code 的 Agent 架构

OpenHarness 是香港大学 HKUDS 团队开源的项目,核心定位是用纯 Python 复刻 Claude Code 的 Agent Harness 架构

什么是 Agent Harness?

The model is the agent. The code is the harness.

模型提供智能,Harness 提供“手、眼、记忆和安全边界”。本质就是把一个 LLM 变成可用 Agent 所需的全部基础设施。

架构全景

Interactive · Architecture Diagram
OpenHarness (oh) — Agent Harness 架构全景
用 3% 的代码量实现 Claude Code 80% 的核心能力
Harness = Tools + Knowledge + Observation + Action + PermissionsAgent Loop(核心循环)Query → LLM Stream → Tool Call → Permission Check→ Hook → Execute → Result → LooploopTools (43+)File, Shell, Web, MCPSkills(按需知识)40+ .md 技能文件Plugins(插件)兼容 claude-codePermissionsDefault / Auto / PlanHooks(生命周期)Pre/Post ToolUseCommands (54)/help /commit /plan …MCP 协议外部工具集成Memory(记忆)跨会话持久化Coordinator多 Agent 协作Config(配置)多层级设置迁移React TUIInk 终端交互界面能力层安全 / 控制层协作 / 扩展层基础设施层

核心循环很简洁:Query → LLM 流式响应 → 检测到 tool_use → 权限检查 → Hook → 执行 → 结果回传 → 继续循环,直到模型决定停止。

这个架构把 Agent 的能力分成了四个层次——能力层提供工具和技能,安全层控制权限和生命周期,协作层处理外部集成和多 Agent 协作,基础设施层负责配置和 UI。

代码量对比

Interactive · Code Comparison
代码量对比:44x 更轻量
Claude Code
512,664 行 · 1,884 文件 · TypeScript
OpenHarness
11,733 行 · 163 文件 · Python
98%
工具覆盖率
44x
代码精简倍数
114
单元测试通过
54
CLI 命令
The model is the agent. The code is the harness.
by HKUDS · MIT License · Python ≥3.11

这组数据相当惊人。OpenHarness 只用了 11,733 行 Python 代码(Claude Code 有 512,664 行 TypeScript),做到了 43/44 个工具的覆盖。这对于想理解“AI Agent 底层到底怎么跑起来的”非常有价值——去掉了企业级的遥测、OAuth、数百个 React 组件等 overhead,只保留了 Harness 的骨架。

10 大子系统详解

Interactive · Subsystem Explorer
10 大子系统 · 4 层架构
点击层级和子系统查看详细说明
能力层3 个子系统
Tools (43+)File, Shell, Web, MCP
Skills(按需知识)40+ .md 技能文件
Plugins(插件)兼容 claude-code
安全 / 控制层3 个子系统
协作 / 扩展层3 个子系统
基础设施层2 个子系统

为什么值得关注?

  1. 学习价值极高:想理解 Claude Code 内部架构,读 OpenHarness 的 11K 行 Python 比读 500K 行 TypeScript 高效得多
  2. 架构思维:清晰展示了一个 Agent Harness 需要哪些子系统,以及它们如何协作
  3. 可扩展:MIT License,Python ≥3.11,可以作为自己构建 Agent 系统的起点

核心 takeaway:模型是 Agent,代码是 Harness。LLM 本身已经具备推理能力,Harness 做的是给它接上工具、记忆、权限和协作能力,让它能真正“做事”。

Comments

0 comments