跳到主内容
@wquguru
精选75Hacker News Best(web_list)技巧与观点

Agent Harnesses可视化指南:对比Pi、OpenCode等框架架构

A Visual Guide to Agent Harnesses

原文
发到 X

A Visual Guide to Agent Harnesses

Agent Harnesses 可视化指南

Exploring Pi, OpenCode, Hermes, and OpenClaw.

探索 Pi、OpenCode、Hermes 和 OpenClaw。

Maarten Grootendorst

Nov 30, 2026

2026年11月30日

97

5

10

Share

分享

Not all agent harnesses are created equally. Harnesses like Pi, OpenCode, Hermes, and OpenClaw each have their own philosophy and give you different capabilities. Choosing one over the other can have a significant impact on your application and choosing which one to use isn’t all that straightforward.

并非所有的 Agent Harnesses 都生而平等。Pi、OpenCode、Hermes 和 OpenClaw 等 Harness 各有其哲学理念,并提供不同的能力。选择其中一个会对你的应用产生重大影响,而决定使用哪一个也并非易事。

In fact, if we place the exact same LLM inside each of them, we get four completely different agents:

事实上,如果我们将完全相同的 LLM 放入其中每一个,我们会得到四个完全不同的智能体:

Pi is your most minimalistic agent whereas OpenCode uses a shared server to handle different clients. Hermes loops skills back into its memory while OpenClaw has over 30 chat channels. And these are only some of the differences...

Pi 是最极简的智能体,而 OpenCode 使用共享服务器来处理不同的客户端。Hermes 将技能循环回储到其记忆中,而 OpenClaw 拥有超过 30 个聊天频道。而这些仅仅是部分差异……

Subscribe to receive new posts on AI and the books: Hands-On LLMs & An Illustrated Guide to AI Agents

订阅以获取关于 AI 的新文章以及书籍《Hands-On LLMs》和《An Illustrated Guide to AI Agents》的内容

Subscribe

订阅

I dove into the source code and explored in more than 30 custom visuals how these harnesses work from the ground up. To do so, we start from an educational harness that my co-author and I created called TinyAgent for our book An Illustrated Guide to AI Agents.

我深入研究了源代码,并通过 30 多个自定义可视化图表探讨了这些 Harness 如何从零构建。为此,我们从我和合著者为我们书籍《An Illustrated Guide to AI Agents》创建的教育性 Harness TinyAgent 开始。

Because these frameworks update quickly, I thought it might be helpful if I focused on a specific snapshot. That will also make it easier to update this guide in a year ;)

由于这些框架更新迅速,我认为专注于特定快照可能会有所帮助。这也将使我在一年后更容易更新本指南 ;)

Here are the snapshots for you to inspect them yourself:

以下是供你自行检查的快照:

  • TinyAgent v0.1.1
  • pi v1.2.0
  • OpenCode v2.0.29
  • Hermes 0e427d7
  • OpenClaw v2026.10.3

What Are Agent Harnesses?

什么是 Agent Harnesses?

To explore agent harnesses, let’s start from the beginning!

为了探索 Agent Harnesses,让我们从头开始!

By itself, an LLM is nothing more than a text-in -> text-out machine. It reads tokens and it generates tokens. To have it become something more, we augment the LLM (typically a reasoning model) with additional capabilities like Memory and Tools so that it can interact with the environment.

单独来看,LLM 不过是一个文本输入 -> 文本输出的机器。它读取 token 并生成 token。为了让它变得更有用,我们通过增加记忆(Memory)和工具(Tools)等额外能力来增强 LLM(通常是推理模型),使其能够与环境交互。

While the LLM does the reasoning, these augmentations connect it to the world outside of tokens. This essentially gives us two pieces of the puzzle:

当 LLM 进行推理时,这些增强功能将其连接到 token 之外的世界。这本质上为我们提供了拼图的两块:

  • Model Weights: The LLM itself
  • Agent Harness: What augments the LLM and converts its tokens into actions
  • 模型权重:LLM 本身
  • Agent Harness:增强 LLM 并将其 token 转换为操作的部分

It’s an interesting boundary to draw and neatly explains what the difference then is between an LLM and a Harness:

这是一个有趣的界限划分,清晰地解释了 LLM 与 Harness 之间的区别:

The model itself is stateless (which means it doesn’t change or remember what happened in the past). The agent harness is everything around the model and creates the prompts, executes tools, stores sessions, enforces guardrails, etc.

模型本身是无状态的(这意味着它不会改变或记住过去发生的事件)。Agent harness 是围绕模型的一切事物,负责创建提示词、执行工具、存储会话、实施护栏等。

Together, they create what we call the agent!

它们共同构成了我们所说的 agent!

These agents can be quite different from each other. If we choose a small LLM then we can expect worse performance over a frontier model. However, the harness arguably has an equal and perhaps even greater influence on the output.

这些 agent 之间可能存在显著差异。如果我们选择一个小型 LLM,那么其性能预期会低于前沿模型。然而,harness 对输出的影响 arguably 相当甚至更大。

Some harnesses are small. Some use many tools. Some have fewer guardrails. Some have more connectors. Etc. Once we look inside the harness, we can see many differences between frameworks, especially regarding their scale:

有些 harness 很小。有些使用许多工具。有些护栏较少。有些连接器较多。等等。一旦我们深入观察 harness,就能看到不同框架之间的诸多差异,尤其是在规模方面:

On the left, we start with the TinyAgent, an educational framework that essentially shows you what it means to build a harness by yourself. It’s small because it has to fit in the book ;)

在左侧,我们从 TinyAgent 开始,这是一个教育性框架,基本上向你展示如何自行构建一个 harness。它之所以小巧,是因为它必须能塞进书里 ;)

Production-grade frameworks are quite a bit bigger to handle things like guardrails, states over multiple sessions, more complex memory systems, etc. Pi and OpenCode have a decently sized codebase whereas especially OpenClaw is quite hefty. Note that I differentiate here between the core app and whatever plugins/extensions a framework might have. I’m not sure it’s fair to count those, but it gives you an idea of how much plugins can add to a framework.

生产级框架要大得多,以处理诸如护栏、跨多个会话的状态、更复杂的记忆系统等问题。Pi 和 OpenCode 的代码库规模适中,而尤其是 OpenClaw 则相当庞大。请注意,我在这里区分了核心应用程序以及框架可能拥有的任何插件/扩展。我不确定是否应该将这些计入,但这能让你了解插件能为框架增加多少内容。

Although they are all coding agents, Hermes and OpenClaw focus more on the “personal assistant” use case rather than the other two frameworks. That’s not an easy thing to do which makes their codebases a bit bigger:

虽然它们都是编码 agent,但 Hermes 和 OpenClaw 更侧重于“个人助理”用例,而非另外两个框架。这并非易事,因此它们的代码库稍大一些:

As such, all four harnesses share a “Coding“ core that can read/edit/execute code. Hermes and OpenClaw have an additional “Personal Assistant“ layer that allows for chat connectors (like Slack), personal memory, scheduled wake-ups, etc.

因此,所有四个 harness 都共享一个“Coding”核心,能够读取/编辑/执行代码。Hermes 和 OpenClaw 还有一个额外的“Personal Assistant”层,支持聊天连接器(如 Slack)、个人记忆、定时唤醒等功能。

This increase in complexity of their codebases allows me to nicely build up from small (TinyAgent) all the way to complex (OpenClaw) one step at a time.

这种代码库复杂度的提升,使我能够很好地从简单(TinyAgent)逐步构建到复杂(OpenClaw),一步一个脚印。

So... let’s explore each framework starting with our tiny baseline to understand the fundamental components of an agent harness that turns the LLM into an agent.

所以……让我们从我们微小的基线开始探索每个框架,以理解将 LLM 转变为 agent 的 agent harness 的基本组件。

TinyAgent

In the book (and all code is of course open-source), we create a TinyAgent entirely from scratch in Python. TinyAgent is the harness that converts a local Gemma 4 model into an agent. Compared to the other four frameworks, this is not meant for production but is purely educational. It only has around 600 lines of code to demonstrate what the core of the loop looks like. We cover things like reasoning, memory, tools, planning, subagents, and more!

在本书中(所有代码当然都是开源的),我们完全从零开始在 Python 中创建了一个 TinyAgent。TinyAgent 是一个框架,可将本地 Gemma 4 模型转换为智能体。与其他四个框架相比,它并非用于生产环境,而是纯粹用于教育目的。其代码仅约 600 行,旨在展示核心循环的结构。我们涵盖了推理、记忆、工具、规划、子智能体等内容!

Meet TinyAgent: six chapter-mapped Python modules composing a 600-line baseline agent

认识 TinyAgent:六个按章节映射的 Python 模块组成一个 600 行的基线智能体

It has a number of small modules that connect the TinyAgent to different chapters, like LLM(), Memory(), Tools(), and more. Together, they form the most minimal agent we could think of with no server, chat connectors, or anything else fancy ;)

它包含多个小型模块,将 TinyAgent 与不同章节连接起来,例如 LLM()、Memory()、Tools() 等。它们共同构成了我们能想到的最简智能体,没有服务器、聊天连接器或其他花哨的功能 ;)

Inside that tiny codebase, the core loop that is being used is called Reason and Act or ReAct. Although it seems like an “old” technique (2022!), it is the loop that is still being used in every framework that we talk about in this guide. Instead of answering in one pass, ReAct instructs the model to go through loops of reasoning, acting, and observing.

在这个微小的代码库中,所使用的核心循环被称为“推理与行动”(Reason and Act)或 ReAct。尽管这看起来是一种“古老”的技术(2022 年!),但它仍然是本指南中讨论的每个框架仍在使用的循环。ReAct 不是一次性回答,而是指导模型经历推理、行动和观察的循环。

At every single loop the model first reasons about what it should do next, then it executes that particular action, and finally observes the consequence of taking that action. This repeats until the model decides it has gathered enough information to answer the question. Modern reasoning LLMs are trained specifically for this pattern and will use specific tokens to indicate when to reason, call a tool, and stop.

在每一次循环中,模型首先推理下一步该做什么,然后执行该特定操作,最后观察采取该操作的后果。这一过程会重复进行,直到模型认为已收集到足够信息来回答问题为止。现代推理型大语言模型专门针对此模式进行了训练,并使用特定标记来指示何时进行推理、调用工具以及停止。

Let’s visualize these steps by mapping it onto the core loop of TinyAgent. At each step, it will:

让我们通过将步骤映射到 TinyAgent 的核心循环来可视化这些步骤。在每个步骤中,它将:

  • Reason: The model will think about the next best step to take.
  • Call a tool: It will output a tool call that the harness will execute.
  • Observe: Add the output of the tool call to its memory.
  • 推理:模型会思考接下来要采取的最佳步骤。
  • 调用工具:它将输出一个工具调用,由框架执行。
  • 观察:将工具调用的输出添加到其记忆中。

This core loop in TinyAgent actually fits in fewer than twenty lines of Python:

TinyAgent 中的这个核心循环实际上可以压缩在不到二十行的 Python 代码中:

代码 · 13 行
def _step(self) -> str | None:
    response = self.llm.generate(
        self.memory.get_messages(), tools=self.tools.schemas
    )
    self.memory.add(
        "assistant", response.content, tool_call=response.tool_call
    )
    if self.tools.is_done(response):
        return response.content
    result = self.tools.execute(response)
    role, observation = self.tools.observation(result)
    self.memory.add(role, observation)
    return None

And that is more than enough to build a working educational agent!

这就足以构建一个可工作的教育用智能体了!

Pi

Pi has a great philosophy:

Pi 拥有出色的理念:

“Pi is a minimal, extensible agent harness that you can make your own.”

“Pi 是一个最小化、可扩展的智能体框架,你可以将其打造为自己的。”

It is the first production-grade harness in our comparison with a bit more than 100K lines of code. It runs in your terminal with no server and just four default tools (read, write, edit, and bash).

它是我们在对比中第一个达到生产级别的框架,拥有略多于 10 万行的代码。它在终端中运行,无需服务器,仅提供四种默认工具(read、write、edit 和 bash)。

Compared to TinyAgent, it adds better compaction, specific tools, can be steered during a run, and more!

与 TinyAgent 相比,它增加了更好的上下文压缩、专用工具、可在运行过程中进行引导等功能!

Compaction

上下文压缩

Coding sessions will eventually reach context limits as it goes through large codebases, does research, writes code itself, etc. Rather than dropping old turns, Pi uses a technique called compaction. In compaction, a part of the conversation history is trimmed to free up this context window. In Pi, when the context window fills up to 184k tokens, its conversation history is compacted.

随着模型处理大型代码库、进行研究、自行编写代码等操作,编码会话最终会达到上下文限制。Pi 不会丢弃旧的对话轮次,而是采用一种称为压缩(compaction)的技术。在压缩过程中,部分对话历史会被裁剪以释放上下文窗口。在 Pi 中,当上下文窗口填满至 184k tokens 时,其对话历史将被压缩。

During compaction older turns are put through an LLM to summarize its history. Meanwhile, the most recent 20k tokens stay exactly the same so the model has an accurate understanding of what it was doing.

在压缩期间,较旧的对话轮次会通过大语言模型(LLM)进行摘要总结。同时,最近的 20k tokens 保持不变,以确保模型对其当前操作有准确的理解。

更进一步:量化金融体系

看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力

进入量化体系 →

关联讨论

同一事件的更多信源

相似阅读

关联信息,但可能不是同一事件