
这是"每日开源项目"系列的第60期。最近在折腾 AI Agent 这块,试了几个框架下来,OpenHarness 让我觉得挺有意思的,今天把它说清楚。
之前几期聊过 OpenAI 的 Symphony(Agent 编排规范)、Addy Osmani 的 Agent Skills(工程技能集),还有 Anthropic 的金融行业 Agent 套件。这些项目传递出一个明确信号:AI Agent 正在从"聊天助手"进化成"能执行工作流的工程基础设施"。
OpenHarness 正是对标这个基础设施层的实现。它由香港大学数据科学实验室(HKUDS)用 Python 开发,提供了四个核心能力:工具调用、技能加载、记忆管理和多 Agent 协调。支持从 Claude 到 DeepSeek 再到本地运行的 Ollama,12.2k Stars 说明开发者社区对这个"轻量、可组合、模型无关"理念的认可。
OpenHarness 是一个开源 Python 框架,为 AI Agent 提供核心轻量级基础设施:工具调用、技能系统、记忆管理和多 Agent 协调。
设计哲学围绕三个关键词:
项目还自带 ohmo,一个基于 OpenHarness 的个人 Agent。它打通了飞书、Slack、Telegram、Discord,调用你现有的 Claude Code 或 GitHub Copilot 订阅,自主完成创建分支、写代码、跑测试、开 PR 全流程。
OpenHarness 在 AI Agent 领域扮演的是"操作系统内核"的角色。它不是给终端用户用的聊天界面——它给开发者提供构建 AI Agent 所需的基础、核心的运行时能力。
可以类比 Linux 内核:你不会直接使用内核,但你在上面跑的每个应用都依赖内核来完成进程调度、文件系统访问、网络通信。OpenHarness 给 AI Agent 提供等价的能力:工具执行调度、持久化记忆、权限控制、子 Agent 协调。
个人开发者工作流自动化
构建领域专属 Agent
多模型对比和切换
企业级 Agent 治理
多 Agent 协作系统
安装:
# Method 1: One-command install script
curl -fsSL https://raw.githubusercontent.com/HKUDS/OpenHarness/main/scripts/install.sh | bash # Method 2: pip install
pip install openharness-ai
初始配置:
# Interactive provider configuration (Claude / OpenAI / DeepSeek / etc.)
oh setup # Example: configure Claude
# Provider: anthropic
# API Key: sk-ant-...
# Model: claude-opus-4-6
基本用法:
# Launch interactive terminal UI
oh # Single-task execution (non-interactive)
oh -p "Analyze the Python code in the current directory and find all unhandled exceptions" # JSON output format (for pipes and script integration)
oh -p "List all TODO comments" --output-format json # Dry-run mode (preview config, execute nothing)
oh --dry-run
ohmo 个人 Agent:
# Install ohmo
pip install ohmo # Configure messaging platform (Feishu / Slack / Telegram / Discord)
ohmo setup --platform telegram # Start listening
ohmo start # Now send a message on Telegram:
# "Fix the login bug on the feature/login-fix branch and open a PR when done"
# ohmo automatically: creates branch → writes code → runs tests → opens PR
1. Agent Loop(循环引擎)
OpenHarness 的心脏——处理每次与大语言模型交互的流式工具调用循环:
# Conceptual Agent Loop structure
while not done: response = llm.stream(messages, tools=available_tools) if response.has_tool_calls: # Execute multiple tool calls in parallel
results = parallel_execute(response.tool_calls) messages.append(tool_results(results)) else: # Model delivers final response — loop ends
done = True yield response.text
核心能力:
2. Harness Toolkit(工具套件)
43+ 内置工具,覆盖日常 Agent 任务的大部分场景:
| 类别 | 示例工具 |
|---|---|
| 文件操作 | read_file, write_file, edit_file, list_dir, search_files |
| Shell 命令 | bash_execute, python_execute, node_execute |
| Web | web_search, web_fetch, web_screenshot, parse_html |
| MCP 集成 | 连接任意 MCP 服务器(HTTP/SSE 传输) |
| 按需技能 | 从 Markdown 技能文件动态加载专业知识 |
3. 上下文与记忆
OpenHarness 设计最用心的模块之一:
# Example MEMORY.md (auto-maintained by the agent)
## Project Memory ### User Preferences
- Python must run in the conda `dev_base` environment
- Commit messages should be in English
- Test coverage requirement: > 80% ### Known Issues
- `auth.py:142` has a known race condition — pending fix
- PostgreSQL connection pool needs max_conn adjustment under high concurrency
4. 治理层
在生产环境中,让 Agent 自由访问文件系统和执行 Shell 命令是危险的。OpenHarness 的治理模块提供了:
# Governance configuration example (conceptual)
governance: mode: restricted allowed_paths: read: ["./src", "./docs"] write: ["./output"] forbidden_commands: - "rm -rf" - "git push --force" hooks: pre_tool_use: - log_tool_call # Log all tool calls post_tool_use: - validate_output # Validate tool outputs require_approval: - shell_execute # Require user approval for shell execution
5. Swarm 协调
对于需要并行处理的复杂任务,单个 Agent 速度太慢。Swarm 模块支持多 Agent 协作:
# Swarm usage example (conceptual)
from openharness import Swarm, Agent swarm = Swarm() # Register a team of specialist agents
swarm.register("code_analyst", Agent(skills=["code-review"]))
swarm.register("security_auditor", Agent(skills=["security"]))
swarm.register("doc_writer", Agent(skills=["documentation"])) # Delegate tasks—execute in parallel
results = await swarm.delegate({ "code_analyst": "Analyze code quality in the src/ directory", "security_auditor": "Scan for potential security vulnerabilities", "doc_writer": "Generate an API documentation draft"
})
| 特性 | OpenHarness | LangChain / LlamaIndex | AutoGen |
|---|---|---|---|
| 学习曲线 | 低(跑个 oh 就完事) | 高(抽象层太多) | 中等 |
| 核心代码量 | 轻量 | 数十万行 | 中等 |
| 模型支持 | 10+ 提供商(含本地模型) | 多但配置复杂 | 以 OpenAI 为主 |
| 记忆机制 | 原生 MEMORY.md 持久化 | 需外部集成 | 有限 |
| 多 Agent | Swarm 原生支持 | 通过 Agent 框架 | 核心特性 |
| 治理/权限 | 内置多级 + 钩子 | 非内置 | 有限 |
| MCP 支持 | 原生(HTTP/SSE 传输) | 插件方式 | 无 |
OpenHarness 支持三个层级的模型提供商:
Anthropic 兼容(通过 Anthropic SDK):
oh setup
# Provider: anthropic → Claude 系列
# Provider: moonshot → Kimi
# Provider: glm → 智谱 GLM
# Provider: minimax → MiniMax
OpenAI 兼容(通过 OpenAI SDK):
# Provider: openai → GPT-4, GPT-4o
# Provider: openrouter → 多模型聚合器
# Provider: dashscope → 阿里云通义千问
# Provider: deepseek → DeepSeek 系列
# Provider: groq → 超快 Llama 推理
# Provider: ollama → 本地开源模型
# Provider: github → GitHub Models
订阅桥接(无需 API Key,复用现有订阅):
# Provider: claude-code → 复用 Claude Code 订阅
# Provider: codex → 复用 GitHub Copilot (Codex CLI) 订阅
这意味着:如果你已经有 Claude Code 或 GitHub Copilot 订阅,零额外成本直接用。
OpenHarness 的内置工具赋予 AI Agent 真正"干活"的能力:
File System (~10 tools): read_file, write_file, edit_file, list_dir, search_files, create_dir, delete_file, move_file, copy_file, get_file_info Shell (~5 tools): bash_execute, python_execute, node_execute, get_env, set_env Web (~8 tools): web_search, web_fetch, web_screenshot, parse_html, download_file, check_url, get_headers Code (~8 tools): lint_code, format_code, run_tests, build_project, git_status, git_commit, git_diff, git_log MCP (~5 tools): mcp_connect, mcp_list_tools, mcp_call_tool, mcp_list_resources, mcp_read_resource Other (~7 tools): token_count, cost_estimate, task_spawn, memory_read, memory_write, skill_load, context_compress
如果说 OpenHarness 是"发动机",ohmo 就是在它基础上造出的"第一辆量产车":
用户在 Telegram 发消息 ↓ ohmo 接收消息 ↓ OpenHarness Agent Loop 启动 ↓ 调用工具(git、bash、文件操作等) ↓ 自动:创建分支 → 写代码 → 跑测试 → 开 PR ↓ ohmo 在 Telegram 回复:"任务完成,PR #47 已开,等你 review。"
这个流程展示了 OpenHarness 的真正价值:它封装了"让 AI Agent 真正做事"背后那些繁琐、看起来不性感的基础设施工作,让上层应用(比如 ohmo)可以把全部精力放在业务逻辑上。
OpenHarness 干的是 AI Agent 领域最不性感、但最重要的事:把工具调用、记忆、权限、多 Agent 协调做干净、做可靠——让构建在它上面的应用可以优雅地站在肩膀上。
原文链接:https://dev.to/...