文章首发链接:2aran.com/s/mJL07E0
✨ 涂阿燃 · 前端与智能体工程师 · 技术作者 · 社区 KOL,粉丝 5 万+,内容月曝光百万+ 📚 持续出版多部技术作品,深度参与开源社区与智能体工程实践,全面拥抱 AI 与去中心化。 🔗 更多请关注个人网络日志;推广合作在博主联盟。
Maarten Grootendorst 在 2026 年 11 月 30 日写了 A Visual Guide to Agent Harnesses,副题是:探看 Pi、OpenCode、Hermes 和 OpenClaw。
智能体的运行框架(harness)并不都一样。Pi、OpenCode、Hermes 和 OpenClaw 各自有一套思路,能力也不相同。选哪一个,对应用的影响会很大,而且并不是那么好选。
其实,把同一只 LLM 放进这四个框架,得到的会是四个完全不同的智能体:
Pi 是最极简的那一个,OpenCode 用共享服务器来承接不同客户端。Hermes 会把技能再写回记忆,OpenClaw 则接了三十多个聊天通道。而这还只是差异里的一部分。
我把源码翻了一遍,用三十多张专门画的图,从底层把这些运行框架是怎么工作的摊开来看。起点是我和合著者为书 An Illustrated Guide to AI Agents 写的一个教学用运行框架,叫 TinyAgent。
这些框架迭代很快,所以我想针对某一个快照来写,也许会更有用。一年后再更新这份图解,也会容易一些。;)
这些是对照用的版本快照,你可以自己去核对:
运行框架是什么?
要讲运行框架,还是从最前面说起。
LLM 本身不过是一个文本进、文本出的机器。它读 token,再生成 token。要想让它变成更多东西,我们会给它(通常是推理模型)补上**记忆(Memory)和工具(Tools)**这类能力,好让它能跟环境打交道。
推理还是 LLM 在做,这些附加能力则把它接到 token 之外的世界。拼图大概就两块:
- 模型权重: LLM 本身
- 运行框架(Agent Harness): 增强 LLM、并把它的 token 变成动作的那一层
这条分界挺有意思,也正好说明 LLM 和运行框架差在哪里:
模型本身是无状态的,既不会改写自己,也不记得过去发生过什么。运行框架是围在模型周围的一切:它拼提示、执行工具、存会话、落实护栏,诸如此类。
两者合在一起,才是我们说的智能体。
智能体之间可以差得很远。选一个小模型,表现一般会比不上前沿模型。不过运行框架对输出的影响,可以说不相上下,也许还更大一些。
有的运行框架很小。有的工具很多。有的护栏更少。有的连接器更多。诸如此类。一旦往框架里面看,差别就不少,尤其是体量:
左边先是 TinyAgent,一个教学框架,本质是告诉你自己动手做一个运行框架是什么意思。它小,是因为得塞进书里。;)
生产级框架会大不少,要处理护栏、跨会话状态、更复杂的记忆系统等等。Pi 和 OpenCode 的代码量已经不小,OpenClaw 尤其厚重。这里我把核心应用和框架可能带的插件、扩展分开来算。把插件也算进去公不公平,我不太确定,不过可以从中看出插件能给一个框架添上多少东西。
它们虽然都是编程智能体,Hermes 和 OpenClaw 更偏向「个人助理」这类用法,另外两个则更专注编程。这件事并不容易,所以它们的代码库也会更大一些:
四个运行框架都有一层「编程」核心,能读、改、跑代码。Hermes 和 OpenClaw 另外还有一层「个人助理」,用来接聊天通道(比如 Slack)、保存个人记忆、定时唤醒,等等。
代码库复杂程度这样一层层加上去,正好让我可以从小的 TinyAgent,一步步讲到复杂的 OpenClaw。
那我们就从这条小小的基线开始,看看把 LLM 变成智能体的运行框架,最基本的部件是什么。
TinyAgent
在书里(代码当然全部开源),我们用 Python 从零写了一个 TinyAgent。它就是那个运行框架,把本地的 Gemma 4 模型变成智能体。跟后面四个框架比,它只做教学,不面向生产。代码大约只有 600 行,用来演示循环的核心长什么样。推理、记忆、工具、规划、子智能体这些,我们都覆盖到了。
它有一组很小的模块,把 TinyAgent 跟书里不同章节连起来,比如 LLM()、Memory()、Tools() 等等。合在一起,就是我们能想到的最精简的智能体:没有服务器,没有聊天连接器,也没有别的花活。;)
这小小的代码库里,核心循环叫 Reason and Act,也就是 ReAct。这套方法看起来已经「老」了(2022 年!),可这份图解里讲到的每一个框架,用的还是它。模型不会一遍就给出答案,ReAct 会让它在推理、行动、观察之间来回转。
每一圈,模型先想下一步该做什么,再执行那个动作,最后观察动作带来的结果。这样一直转,直到它觉得信息已经够用来回答问题。现在的推理 LLM 就是按这个模式训练的,还会用特定的 token 标明何时推理、何时调工具、何时停下来。
我们把这些步骤映射到 TinyAgent 的核心循环上,会更清楚。每一步它会:
- 推理: 模型思考下一步最好怎么走。
- 调用工具: 输出一次工具调用,由运行框架去执行。
- 观察: 把工具调用的输出写进记忆。
TinyAgent 里的这段核心循环,其实写不满二十行 Python:
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
要做一个能跑起来的教学智能体,这些就够了。
Pi
Pi 的理念很清楚:
“Pi is a minimal, extensible agent harness that you can make your own.” 「Pi 是一个极简、可扩展的智能体运行框架,你可以把它改成自己的。」
这是我们对比里第一个生产级运行框架,代码量略多于 100K 行。它跑在终端里,没有服务器,默认只有四个工具(read、write、edit 和 bash)。
跟 TinyAgent 比,它多了更好的压缩、专门的工具、可以在运行中转向,还有别的能力。
压缩
编程会话翻大型代码库、做调研、自己写代码,迟早会顶到上下文上限。旧轮次不会被直接丢掉。Pi 用一种叫压缩(compaction)的做法,把一部分对话历史剪短,给上下文窗口腾地方。在 Pi 里,上下文窗口涨到 184k token 时,就会压缩对话历史。
压缩时,较早的轮次会交给一个 LLM 做摘要。最近的 20k token 则原样保留,好让模型准确知道自己刚才在干什么。
就算给 TinyAgent 也加上压缩,它也不会把对话存下来。终端一关,整段对话就没了。Pi 则不同,每一轮都会写进 JSONL,用 id 和 parent 指针串起来:
这套做法有个很大的好处:你可以轻松回到对话里更早的一轮,再开出一条新分支。跟用 git 很像。
工具
工具大概算智能体最要紧的部件之一。它们通常瞄准写文件、改文件、创建文件这类能力。在 TinyAgent 里,我们给它的是整文件写入的工具。你若只想改一行代码,也得把整个文件重写一遍。Pi 则有一个 edit 工具,可以只改非常具体的一行,模型要写的量会少很多。
Pi 的运行框架对日志的处理也更讲究。比方你跑一次 pytest,可能会拿到一份很大的日志(比如 pytest.log)。在 Pi 里,这些信息会先存在本地,回给模型的只有最后 2,000 行,外加文件路径。
测试失败通常出现在追踪的末尾,模型因此仍能看到报错;需要的时候,再用 Agentic RAG 去搜 pytest.log。
所以,模型能直接调用的显式工具(比如 edit),和运行框架自己做的那些事(比如截断日志),都是智能体运行框架里重要的组成部分。
转向
最后,Pi 还有一个挺有意思的能力:可以在它正在跑的时候转向。
也就是说,模型还在运行时,你就能插入一句询问,它会接着往下走。做法是:独立的工具并行执行,就在把输出交回给 LLM 之前,把这句询问注入进去。模型会看到工具输出,同时意识到用户又补了一句,也许是刚才忘了说的。
消息大致分两种:转向(steer) 消息会改写下一次 LLM 调用的方向;跟进(follow-up) 消息会等到模型彻底做完再进入。
在 Pi 的引擎里(agent-loop.ts#L294-L308),这个分叉只需要几行:
while (hasMoreToolCalls || pendingMessages.length > 0) {
// ... run turn and execute tools ...
explicitContinuation = decision?.action === "continue";
pendingMessages = (await config.getSteeringMessages?.()) || [];
if (hasMoreToolCalls || pendingMessages.length > 0) {
explicitContinuation = false;
}
}
// Agent would stop here. Check for follow-up messages.
const followUp = (await config.getFollowUpMessages?.()) || [];
if (followUp.length > 0) {
explicitContinuation = false;
pendingMessages = followUp;
continue;
}
getSteeringMessages() 跑在正在进行的内循环里,getFollowUpMessages() 则等到智能体本来就要停下来的时候才取。四个生产级运行框架都从这条基线里吸收了压缩、定点编辑和截断。OpenCode 则把这个循环从终端里拆了出来。
OpenCode
OpenCode 的代码量跟 Pi 大致相当,不过它在智能体前面加了一层 HTTP 服务器,好让各种客户端(终端、桌面端等)共用同一个 SQLite 会话。
跟 Pi 比,OpenCode 多了这套共享服务器、用来追踪会话的 SQLite 数据库、带有子智能体的特殊 Code Mode,还有别的。
服务器
Pi 的终端一关,循环就会停,因为一切都在终端里执行。OpenCode 把这层解耦了:所有追踪都会写进数据库(比如 opencode.db)。所以你关掉终端,还可以用 Web 应用把进程接下去。
每一步,服务器都从数据库读出会话历史,让模型跑一轮,再把新信息存回去,供下一步查询。而下一步可以从任何地方发起。
Code Mode
智能体碰到复杂场景时,可能需要按正确的顺序跑好几个工具。更简单的运行框架里,LLM 每轮只跑一个工具,等输出回来再调下一个。
OpenCode 的做法不太一样,用的是他们称为 Code Mode 的机制。在这个模式里,LLM 可以写一段短脚本,把这些调用串起来。工具不必再一步调一次:它可以一次全部调用,等它们都跑完,模型才看到输出。
Code Mode 是一种叫 CodeAct 的方法的好例子。按这个模式,模型会写可执行代码(比如 Python)来编排一串工具调用。模型越来越能干,编排脚本这件事可以交给它们自己。这样一来,它们不但能编排多次工具调用,还能顺便造出新的工具。
规划
翻代码库的时候,有一件事让我挺意外:它处理规划模式的方式。我本以为会看到某种专门或复杂的规划架构。结果他们在 Build Mode 和 Plan Mode 之间切换的办法很简单,也很漂亮。
这个办法里,智能体循环完全不变,还是我们前面见过的那种类 ReAct 循环。可一旦切到 Plan Mode,运行框架会拦住 edit 工具,只允许改 plan.md。这道限制会把模型往规划上推。它反正也做不了别的。
切回 Build Mode,edit 工具又能改你选定的文件了。
这类小技巧,感觉正好说明我们正在往哪个方向走。LLM 越来越强,那些特别复杂的系统,需要得也越来越少。
子智能体
压缩是管理过长追踪、给模型上下文腾地方的好办法。但它并不完美。比方你想让智能体去一个新仓库里找某个函数,光是找到它,就可能花掉几千 token。之后固然可以再压缩对话历史,可这样其实挺不划算。
OpenCode 有一种更省的压缩办法:用子智能体。
模型一遇到读类任务(read、grep、glob),就会让子智能体去干。子智能体完成任务,把自己的上下文窗口填满,但交回来的只有一份它做过什么的摘要:
一大段上下文就这样收成一份摘要,主智能体拿来用就行。子智能体搜索过的那些内容,基本都被扔掉了。
这又是一个用简单办法挡住更大麻烦的例子。拉起一个子智能体去办事,再用掉它的上下文窗口,免得噪音进到主智能体里。
Hermes
Hermes 已经大了不少,主要就为一个原因:它加了一层个人助理(Personal Assistant),能做编程之外的事。于是它接上了各种聊天应用(比如 Slack 和 WhatsApp),工具更多(超过 50 个),还能用到种类很多的技能(也超过 50 个)。
跟只做编程的运行框架比,Hermes 多了多聊天网关、会自我学习的技能、内部的审批裁判和并行工作者,以及好几种可插拔的沙箱后端。
记忆
以编程为主的运行框架,和面向个人助理的运行框架,记忆得不太一样。做编程,一份 AGENTS.md 通常就够用,多半也能走得很远。要做个人助理,往往还得学会你的偏好。
Hermes 是一个很好的例子,说明可以怎样用 markdown 文件来做个性化。它有 USER.md 和 MEMORY.md,智能体可以往里面写,并更新它关于你和你偏好的了解。
这些 markdown 文件里装着不同类型、还会一直变化的信息:
- MEMORY.md:环境事实、项目结构、工具的怪癖,以及智能体发现的技术经验。
- USER.md:关于用户的事实,比如角色、沟通风格、工作习惯和偏好(例如总是用 pytest)。
于是,技术环境和结构(MEMORY.md)跟用户(USER.md)被分开了。这种模块化让模型很容易分清项目信息和用户偏好。
技能
Hermes 内置了五十多种技能,用途各不相同:
- 生产力: obsidian、notion、google-workspace 等。
- 软件: github-pr-workflow、test-driven-development、docker-management 等。
- 安全: 1password、oss-forensics 等。
- 外部智能体: claude-code、codex 等。
这些技能都跟 Hermes 打包在一起,不用用户自己去装很多不同的技能,就能做各种各样的事。
跟技能的常见做法一样,Hermes 一开始只加载它们的页头,好知道有哪些技能可用。智能体要读完整技能时,可以用 skill_view("...") 这个工具按需加载。
智能体开始工作时,看到的只是小小的 YAML 页头,里面是技能的名称和描述。
技能学习
前面已经看到,跟别的运行框架比,Hermes 更看重学习流程(以及用户)。MEMORY.md 和 USER.md 是其中一部分,可要是智能体想学会某个具体模式呢?把这些东西全倒进那两份 markdown,文件很快就会很吵。
它的办法很直接:新建技能。
具体是靠一个审查智能体(review agent),在会话结束时启动,判断要不要新建一项技能,或更新已有的技能:
一个会话里调用工具超过 10 次后,审查智能体就会启动。它会看完整段追踪,想一想这件事能不能收成一个模式。比方说,模型本来用 3 次工具调用就够了,却用了 10 次以上。把这个模式记下,以后的运行会高效得多。
这个思路挺有意思,像是把 Voyager 里不断增长的技能库,和 Reflexion 里对自身行为的反思,合在了一起。
子智能体
跟 OpenCode 类似,Hermes 也可以拉起子智能体来分担工作。不过跟 OpenCode 不同,Hermes 能并行拉起它们,再把这些子智能体的输出合成一组摘要,交给主智能体看:
这些子智能体被要求只盯拼图里的一块(一个文件或一个文件夹),并交回结果摘要。摘要再传回主智能体。
Hermes 是个人助理层的一个很好的例子,不过功能总还可以再多。体量最大的那个框架,是 OpenClaw。
OpenClaw
OpenClaw 是最广为人知的运行框架之一,也绝对是这里面最大的。很大一部分原因,是它要接的聊天通道、工具和后端非常多,几乎想把事情都做了。
前面那些运行框架能做的,它基本上都能做,另外还有一些差别和额外能力。
多通道网关
Hermes 已经有一个网关,把聊天应用路由到 LLM。OpenClaw 更进一步,做了一个多通道网关,把私人聊天和群聊分开,中间立了一道隐私边界。
它拆成两个会话:主会话(Main Session) 和 群组会话(Group Session)。主会话装着你所有的私人私信,群组会话则是各自独立的群聊,避免个人内容漏进去。
心跳
OpenClaw 让人记住的一件事,是它引入了心跳(heartbeat)。心跳其实就是一个每隔 30 分钟触发一次的机制,会把智能体唤醒,让它看看有没有新消息、该不该开始一项新任务。
如果智能体觉得没什么要做,它就保持安静。要是看到一封重要邮件,就可以在某个聊天通道里通知用户。规则写在 HEARTBEAT.md 里,所以它每 30 分钟都知道该盯什么。
在这个例子里,有一个 cron 任务每天早上 08:00 启动,整理并发送新邮件摘要。8:30(第一次心跳)和 9:00(第二次心跳),智能体检查要不要行动。如果不用,就什么都不发生。到了 9:30,一封重要邮件进来了,智能体就通知用户。
记忆
OpenClaw 被设计成一直在线。可会话一跑就是好几天,甚至好几周,压缩终究会把追踪里的重要信息清掉。
于是 OpenClaw 会在压缩之前先做一次所谓的记忆冲刷(memory flush),说白了就是把记忆写到磁盘上:
要查询这些信息,OpenClaw 用 Agentic RAG,需要时就能方便地查到。它用的是一种混合 RAG:既用经典方法(BM25),也用更现代的方法(embeddings):
然后它会加上 30 天的新近衰减,降低较旧文件的相关性。再用 Maximal Marginal Relevance(MMR)去重并重新排序。排好的信息再喂给 LLM,让它对重要事情保持更新。
还没完。
日日志过上几周,仍可能堆积很多噪音。为了挡住这件事,OpenClaw 还会跑第二遍,叫做 Scheduled Dreaming(定时做梦):
每天夜里,智能体会走过三阶段的「睡眠」:浅睡(light)、深睡(deep) 和 REM。它会像前面那样给日日志打分(浅睡),搜索并抽出重要事实(深睡),最后写进长期记忆,也就是 MEMORY.md(REM)。
我挺喜欢框架试图模仿我们自己在做的事。反正用户也在睡觉,为什么不趁这个机会,把白天发生的事情整理一下呢?
对比这些运行框架
这份图解快结束时,我想把这些运行框架并排放在一起,看看它们差在哪里,先从系统提示开始。
你还一个字都没打,每个运行框架已经用系统指令、工作区文件和工具 schema,把上下文窗口占掉一部分了。
Hermes 和 OpenClaw 看起来挺有意思。它们花掉的 token 几乎一样多,原因却很不一样。Hermes 侧重工具 schema(21 个默认工具),OpenClaw 默认只暴露 7 个核心工具,把重心放在工作区文件上(SOUL.md、MEMORY.md、规则)。
然后,当会话朝着某个上下文窗口往上长时,每个运行框架的压缩机制也不一样:
跟其他运行框架比,Hermes 压缩得比较早;OpenClaw 则会把不少上下文存进日日志,方便追踪。
最后,还可以并排看看这五个运行框架怎样管理会话存储、持久文件,以及跨会话回想:
可以看到,运行框架越复杂,记忆是怎么一步步演化的。比如 OpenCode 用数据库来追踪会话,OpenClaw 则保存每日文件,这就挺有意思。
这也说明,不同的运行框架可以差出多大一截。
不过要选哪一个,并没有那么直截了当。很大程度上取决于你在找什么。适用场景和主要取舍,大致可以这样看:
完整解剖
Jay 和我花了不少时间,想把「智能体是什么」收成一个总的想法。用这个想法回头去接这里讲过的所有内容,就可以把运行框架语境里的一些原则,收成一张挺清楚的总图:
LLM 在运行框架的正中,可运行框架并不会改动它。把一个出色的聊天机器人变成能与世界互动的东西的,是围在 LLM 周围的那一切。
过去几年里,AI 的世界变成现在这样,其实挺美的:
「从词语走向行动,从 LLM 走向智能体。」
结语
开源智能体运行框架的这场图解之旅,就到这里。
希望把这些框架并排放在一起看过之后,你在选择一个运行框架、甚至自己设计一个时,脑子里能有一张更清楚的地图。如果你想从零把这些基础做出来,带着完整代码和另外几百张图,可以看看我们的书 An Illustrated Guide to AI Agents。
书的官方网站。可以在 Amazon 上购买。全部代码都放在 GitHub 上。
信息来源与说明
- 一手来源:Maarten Grootendorst,A Visual Guide to Agent Harnesses,2026-11-30。
- 文中代码、命令、路径、函数名、工具名、版本快照和指标名称保持原文。配图沿用原页地址。
- 资料截至 2026-12-01。英文正文或框架版本若有更新,以原页和各项目仓库为准。
- 版权归 Maarten Grootendorst 所有。中文稿供阅读与讨论,不替代原文授权。
本文由 AI图鉴自动抓取并翻译,版权归原作者所有;如需查看原文请点下方链接。
First-published link: 2aran.com/s/mJL07E0
✨ Tu Aran · Front-end and AI Agent engineer · Technical author · Community KOL, 50,000+ followers, million+ monthly content views 📚 Continuously publishing multiple technical works, deeply involved in open-source communities and AI Agent engineering practice, fully embracing AI and decentralization. 🔗 Follow the personal web log for more; promotional partnerships via the blogger affiliate network.
Maarten Grootendorst wrote A Visual Guide to Agent Harnesses on November 30, 2026, subtitled: Exploring Pi, OpenCode, Hermes, and OpenClaw.
The harnesses (the frameworks that run AI agents) are not all the same. Pi, OpenCode, Hermes, and OpenClaw each have their own approach, and their capabilities differ. Which one you pick can have a significant impact on the application, and it is not an easy choice.
In fact, putting the same LLM into these four harnesses would yield four completely different AI agents:
Pi is the most minimal one; OpenCode uses shared servers to serve different clients. Hermes writes skills back into memory; OpenClaw connects to over thirty chat channels. And that is only part of the differences.
I went through the source code and used over thirty specially drawn diagrams to break down how these harnesses work from the ground up. The starting point is a teaching harness that my co-author and I wrote for the book An Illustrated Guide to AI Agents, called TinyAgent.
These frameworks iterate quickly, so I think writing against a specific snapshot might actually be more useful. It will also be easier to update this visual guide a year from now. ;)
Here are the version snapshots for reference — you can verify them yourself:
What is a harness?
To talk about harnesses, let's start from the very beginning.
An LLM, at its core, is simply a text-in, text-out machine. It reads tokens and generates tokens. To make it into something more, we equip it (typically a reasoning model) with capabilities like **Memory and Tools**, so it can interact with its environment.
The LLM still does the reasoning; these added capabilities connect it to the world beyond tokens. The puzzle has roughly two pieces:
- Model weights: the LLM itself
- Agent Harness: the layer that augments the LLM and turns its tokens into actions
This boundary is quite interesting, and it neatly shows where the LLM and the harness differ:
The model itself is stateless — it neither rewrites itself nor remembers what happened before. The harness is everything around the model: it assembles prompts, executes tools, stores conversations, enforces guardrails, and so on.
Together, the two are what we call an AI Agent.
AI agents can differ enormously. Choosing a smaller model generally will not match the performance of a frontier model. But the harness's impact on output can be comparable, or even greater.
Some harnesses are very small. Some have lots of tools. Some have fewer guardrails. Some have more connectors. And so on. Once you look inside a harness, the differences add up — especially in size:
On the left is TinyAgent first — a teaching harness that essentially shows you what it means to build a harness yourself. It is small because it has to fit in a book. ;)
Production-grade harnesses are considerably larger, needing to handle guardrails, cross-session state, more complex memory systems, and so on. Pi and OpenCode already have a substantial codebase; OpenClaw is especially heavy. Here I am counting the core application and the plugins/extensions a harness might ship with separately. Whether including plugins is fair, I am not entirely sure, but it does show how much a plugin can add to a harness.
Although they are all coding AI agents, Hermes and OpenClaw lean more toward the "personal assistant" use case, while the other two focus more on coding. That is not a trivial thing, so their codebases are also a bit larger:
All four harnesses have a "coding" core that can read, modify, and run code. Hermes and OpenClaw additionally have a "personal assistant" layer for connecting to chat channels (like Slack), storing personal memories, scheduled wake-ups, and so on.
The codebase complexity builds up layer by layer, which lets me walk through from the small TinyAgent step by step to the complex OpenClaw.
So let's start with this small baseline and look at the most basic components of a harness that turns an LLM into an AI Agent.
TinyAgent
In the book (all the code is, of course, open source), we built a TinyAgent from scratch in Python. It is the harness that turns a local Gemma 4 model into an AI Agent. Compared to the four harnesses that follow, it is purely for teaching, not production-ready. The code is only about 600 lines, used to demonstrate what the core loop looks like. Reasoning, memory, tools, planning, and sub-AI agents — we covered all of them.
It has a set of small modules that link TinyAgent to different chapters in the book, such as LLM(), Memory(), Tools(), and so on. Put together, it is the most minimal AI agent we can imagine: no server, no chat connector, and no other frills. ;).
In this tiny codebase, the core loop is called Reason and Act, also known as ReAct. The approach may look "old" (2022!), but every framework covered in this illustration still uses it. The model does not simply produce an answer in one shot; ReAct has it cycle through reasoning, acting, and observing.
Each loop, the model first thinks about what the next step should be, then executes that action, and finally observes the result of the action. It keeps cycling like this until it decides there is enough information to answer the question. Today's reasoning LLMs are trained in exactly this pattern, using specific tokens to mark when to reason, when to call tools, and when to stop.
Mapping these steps onto TinyAgent's core loop makes it clearer. At each step it:
- Reasoning: The model thinks about the best next step.
- Tool call: It outputs a tool call, which the runtime harness executes.
- Observation: The output of the tool call is written into memory.
This core loop in TinyAgent is actually less than twenty lines of Python:
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
That is all you need to build a working instructional AI agent.
Pi
Pi's philosophy is clear:
"Pi is a minimal, extensible agent harness that you can make your own."
This is the first production-grade harness in our comparison, with just over 100K lines of code. It runs in the terminal, no server, and ships with only four tools by default (read, write, edit, and bash).
Compared to TinyAgent, it adds better compaction, specialized tools, the ability to pivot mid-run, and other capabilities.
Compaction
Programming sessions that browse large codebases, do research, and write code will eventually hit the context limit. Old turns are not simply discarded. Pi uses an approach called compaction to trim part of the conversation history and free up space in the context window. In Pi, when the context window reaches 184k tokens, the conversation history gets compacted.
During compaction, earlier turns are handed to an LLM for a summary. The most recent 20k tokens are kept as-is, so the model knows precisely what it was just doing.
Even if you added compaction to TinyAgent, it still would not persist the conversation. Close the terminal and the entire conversation is gone. Pi is different: every turn is written to JSONL, linked by id and parent pointers:
This approach has a big advantage: you can easily go back to an earlier turn in the conversation and branch off into a new path. It is a lot like using git.
Tools
Tools are probably one of the most critical components of an AI agent. They typically target capabilities like writing files, modifying files, and creating files. In TinyAgent, we gave it a whole-file write tool. If you only want to change one line of code, you still have to rewrite the entire file. Pi, on the other hand, has an edit tool that can modify a very specific single line, so the model has to write far less.
Pi's harness also handles logs more thoughtfully. For example, if you run pytest, you might get a very large log (say, pytest.log). In Pi, that information is stored locally first, and only the last 2,000 lines are sent back to the model, along with the file path.
Test failures typically appear at the end of the trace, so the model can still see the errors; when needed, it can use Agentic RAG to search pytest.log.
So, both the explicit tools the model can invoke directly (like edit) and the things the harness does on its own (like truncating logs) are important components of an AI agent harness.
Pivoting
Finally, Pi has another interesting capability: you can steer it while it's running.
In other words, while the model is still executing, you can insert a query and it will carry on from there. The approach: independent tools run in parallel, and just before the output is handed back to the LLM, the query is injected. The model sees the tool outputs while also realizing the user added another line, perhaps something they forgot to mention earlier.
Messages broadly fall into two types: steer messages redirect the direction of the next LLM call; follow-up messages wait until the model is completely finished before entering.
In Pi's engine (agent-loop.ts#L294-L308), this branch only takes a few lines:
while (hasMoreToolCalls || pendingMessages.length > 0) {
// ... run turn and execute tools ...
explicitContinuation = decision?.action === "continue";
pendingMessages = (await config.getSteeringMessages?.()) || [];
if (hasMoreToolCalls || pendingMessages.length > 0) {
explicitContinuation = false;
}
}
// Agent would stop here. Check for follow-up messages.
const followUp = (await config.getFollowUpMessages?.()) || [];
if (followUp.length > 0) {
explicitContinuation = false;
pendingMessages = followUp;
continue;
}
getSteeringMessages() runs inside the ongoing inner loop, while getFollowUpMessages() is only fetched when the AI agent is about to stop anyway. All four production-grade runtime frameworks have absorbed compaction, targeted editing, and truncation from this baseline. OpenCode, on the other hand, decoupled this loop from the terminal.
OpenCode
OpenCode has roughly the same amount of code as Pi, but it adds an HTTP server layer in front of the AI agent so that various clients (terminal, desktop, etc.) can share the same SQLite session.
Compared to Pi, OpenCode adds this shared server, a SQLite database for tracking sessions, a special Code Mode with subagents, and more.
Server
The moment Pi's terminal closes, the loop stops, because everything runs inside the terminal. OpenCode decouples this layer: all tracking is written to a database (e.g., opencode.db). So even if you close the terminal, you can pick up the process with a web app.
At each step, the server reads the conversation history from the database, lets the model run a turn, then stores the new information back for the next step to query. And the next step can be initiated from anywhere.
Code Mode
When the AI agent encounters complex scenarios, it may need to run several tools in the correct order. In simpler runtime frameworks, the LLM runs only one tool per turn, waiting for the output before calling the next one.
OpenCode does things differently, using a mechanism they call Code Mode. In this mode, the LLM can write a short script to chain the calls together. Tools no longer need to be called one at a time: it can call them all at once, and only after they have all finished does the model see the outputs.
Code Mode is a great example of a method called CodeAct. In this pattern, the model writes executable code (e.g., Python) to orchestrate a sequence of tool calls. As models become more capable, writing orchestration scripts can be left to them. This way, they can not only orchestrate multiple tool calls but also create new tools along the way.
Planning
While going through the codebase, one thing surprised me: how it handles planning mode. I expected to see some dedicated or complex planning architecture. Instead, the way they switch between Build Mode and Plan Mode is both simple and elegant.
In this approach, the AI agent loop remains completely unchanged—it is still the same ReAct-style loop we saw earlier. But once switched to Plan Mode, the runtime framework blocks the edit tool, only allowing changes to plan.md. This constraint pushes the model toward planning. It cannot do anything else anyway.
Switch back to Build Mode, and the edit tool can modify your chosen files again.
These kinds of tricks feel like they perfectly illustrate where we are heading. As LLMs get stronger, those extremely complex systems become less and less necessary.
Subagents
Compression is a good way to manage overly long traces and free up context for the model. But it's not perfect. For instance, if you want an AI agent to find a particular function in a new repository, just locating it could burn through thousands of tokens. Sure, you can compress the conversation history afterward, but that's really not cost-effective.
OpenCode has a more efficient compression method: using sub-AI agents.
When the model encounters read-type tasks (read, grep, glob), it delegates them to a sub-AI agent. The sub-AI agent completes the task, fills up its own context window, but hands back only a summary of what it did:
A large chunk of context is thus condensed into a single summary, which the main AI agent can simply use. The content the sub-AI agents searched through is essentially discarded.
This is another example of using a simple approach to prevent a bigger problem. Spin up a sub-AI agent to do the job, let it consume its context window, so that noise doesn't leak into the main AI agent.
Hermes
Hermes has grown quite a bit, mainly for one reason: it added a personal assistant (Personal Assistant) layer that can handle things beyond coding. As a result, it connects to various chat applications (such as Slack and WhatsApp), has more tools (over 50), and can use a wide variety of skills (also over 50).
Compared to coding-only runtimes, Hermes adds multi-chat gateways, self-learning skills, internal approval judges and parallel workers, as well as several pluggable sandbox backends.
Memory
Coding-focused runtimes and personal-assistant-oriented runtimes handle memory quite differently. For coding, an AGENTS.md is usually enough and often goes a long way. For a personal assistant, you often need to learn about your preferences.
Hermes is a good example of how markdown files can be used for personalization. It has USER.md and MEMORY.md, which AI agents can write to and use to update their understanding of you and your preferences.
These markdown files hold different types of information that keep changing:
- MEMORY.md: environmental facts, project structure, tool quirks, and technical knowledge discovered by AI agents.
- USER.md: facts about the user, such as role, communication style, work habits, and preferences (e.g., always using pytest).
Thus, the technical environment and structure (MEMORY.md) is separated from the user (USER.md). This modularity makes it easy for the model to distinguish between project information and user preferences.
Skills
Hermes has over 50 built-in skills, each serving different purposes:
- Productivity: obsidian, notion, google-workspace, and more.
- Software: github-pr-workflow, test-driven-development, docker-management, and more.
- Security: 1password, oss-forensics, and more.
- External AI agents: claude-code, codex, and more.
All of these skills are bundled with Hermes, so users don't need to install many different skills themselves to accomplish a wide range of tasks.
As is common with skills, Hermes initially loads only their headers to know which skills are available. When an AI agent needs to read a full skill, it can use the skill_view("...") tool to load on demand.
When an AI agent starts working, it sees only a small YAML header containing the skill's name and description.
Skill Learning
As mentioned earlier, compared to other runtimes, Hermes places more emphasis on the learning process (and the user). MEMORY.md and USER.md are part of that, but what if an AI agent wants to learn a specific pattern? Dumping everything into those two markdown files would quickly make them noisy.
Its approach is straightforward: create a new skill.
Specifically, it uses a review agent that is triggered at the end of a session to decide whether to create a new skill or update an existing one:
After more than 10 tool calls in a session, the review AI agent is triggered. It examines the full trace and considers whether the task can be condensed into a pattern. For example, if the model could have done it with 3 tool calls but used more than 10, it records that pattern, making future runs much more efficient.
This is an interesting idea, combining Voyager's ever-growing skill library with Reflexion's self-reflection on its own behavior.
Sub-AI Agents
Similar to OpenCode, Hermes can also spin up sub-AI agents to share the workload. However, unlike OpenCode, Hermes can launch them in parallel, then synthesize their outputs into a set of summaries for the main AI agent:
These sub-AI agents are asked to focus on just one piece of the puzzle (a file or a folder) and return a summary of results. The summary is then passed back to the main AI agent.
Hermes is a great example of a personal assistant layer, though it could always have more features. The largest framework in terms of scale is OpenClaw.
OpenClaw
OpenClaw is one of the most well-known runtime frameworks, and definitely the biggest among them. A large part of the reason is that it connects to a huge number of chat channels, tools, and backends — it practically tries to do everything.
It can do basically everything the earlier runtime frameworks can, plus some differences and extra capabilities.
Multi-channel Gateway
Hermes already has a gateway that routes chat applications to LLM. OpenClaw goes further, building a multi-channel gateway that separates private chats from group chats, with a privacy boundary in between.
It splits into two sessions: Main Session and Group Session. The Main Session holds all your private direct messages, while Group Session consists of independent group chats, preventing personal content from leaking in.
Heartbeat
One thing that makes OpenClaw memorable is that it introduced heartbeat. A heartbeat is essentially a mechanism that triggers every 30 minutes, waking up the AI agent to check for new messages and whether it should start a new task.
If the AI agent thinks there's nothing to do, it stays quiet. If it sees an important email, it can notify the user in a chat channel. The rules are written in HEARTBEAT.md, so it knows what to watch for every 30 minutes.
In this example, a cron job starts at 08:00 every morning, organizing and sending a summary of new emails. At 8:30 (first heartbeat) and 9:00 (second heartbeat), the AI agent checks whether action is needed. If not, nothing happens. At 9:30, an important email arrives, and the AI agent notifies the user.
Memory
OpenClaw is designed to stay online all the time. But sessions can run for days, even weeks, and compression will eventually wipe out important information in the tracking.
So OpenClaw performs a so-called memory flush before compression — in plain terms, writing memory to disk:
To query this information, OpenClaw uses Agentic RAG, making it easy to look things up when needed. It uses a hybrid RAG: both the classic approach (BM25) and a more modern one (embeddings):
It then adds a 30-day recency decay to reduce the relevance of older files. It uses Maximal Marginal Relevance (MMR) to deduplicate and re-rank. The ranked information is then fed to the LLM to keep it updated on important things.
And that's not all.
Over a few weeks, daily logs can still accumulate a lot of noise. To prevent this, OpenClaw runs a second pass called Scheduled Dreaming:
Every night, the AI agent goes through a three-stage "sleep": light, deep, and REM. It scores daily logs as before (light sleep), searches and extracts important facts (deep sleep), and finally writes them into long-term memory, which is MEMORY.md (REM).
I really like how the framework tries to mimic what we ourselves do. The user is sleeping anyway, so why not take this opportunity to organize what happened during the day?
Comparing These Runtime Frameworks
Near the end of this walkthrough, I want to put these runtime frameworks side by side to see where they differ, starting with the system prompt.
Before you've even typed a single word, each runtime framework has already taken up part of the context window with system instructions, workspace files, and tool schemas.
Hermes and OpenClaw look interesting. They burn almost the same number of tokens, but for very different reasons. Hermes focuses on tool schemas (21 default tools), while OpenClaw exposes only 7 core tools by default, putting its emphasis on workspace files (SOUL.md, MEMORY.md, rules).
Then, as a session grows toward a context window limit, each runtime framework's compression mechanism is different:
Compared to other runtime frameworks, Hermes compresses earlier; OpenClaw saves a lot of context into daily logs for easy tracking.
Finally, you can also compare how these five runtime frameworks manage session storage, persistent files, and cross-session recall:
You can see how, the more complex the runtime framework, the more memory has evolved step by step. For example, OpenCode uses a database to track sessions, while OpenClaw saves daily files — which is quite interesting.
This also shows just how much different runtime frameworks can vary.
However, choosing which one isn't that straightforward. It largely depends on what you're looking for. Use cases and key trade-offs can roughly be seen like this:
Full Dissection
Jay and I spent a lot of time trying to distill "what an AI agent is" into a single unifying idea. Using this idea to tie together everything covered here, you can condense some of the principles in the runtime framework context into a fairly clear big picture:
The LLM sits right at the center of the runtime framework, but the framework doesn't modify it. What turns a great chatbot into something that can interact with the world is everything surrounding the LLM.
The fact that the AI world has evolved into what it is today over the past few years is actually quite beautiful:
"From words to actions, from LLM to AI agent."
Conclusion
This illustrated journey through open-source AI Agent running frameworks ends here.
I hope that after seeing these frameworks laid out side by side, you'll have a clearer mental map when choosing a running framework or even designing one yourself. If you'd like to build these foundations from scratch, with complete code and several hundred additional illustrations, check out our book An Illustrated Guide to AI Agents.
The book's official website. Available for purchase on Amazon. All code is on GitHub.
Sources and Notes
- Primary source: Maarten Grootendorst, A Visual Guide to Agent Harnesses, 2026-11-30.
- Code, commands, paths, function names, tool names, version snapshots, and metric names in the text are kept in the original language. Illustrations reference the original page URLs.
- Materials are current as of 2026-12-01. If the English text or framework versions have been updated, refer to the original pages and project repositories.
- Copyright belongs to Maarten Grootendorst. The Chinese version is for reading and discussion purposes only and does not supersede the original's licensing.
Auto-fetched and translated by AI Atlas. All rights belong to the original author.