跪拜 Guibai
← Back to the summary

Agent Harnesses Decoded: Pi, OpenCode, Hermes, and OpenClaw Compared

A Visual Guide to Agent Harnesses: Pi, OpenCode, Hermes, and OpenClaw

Author: Juejin Anthony (涂阿燃)

✨ Tu Aran · Front-end and agent engineer · Technical author · Community KOL, 50k+ followers, monthly content exposure of millions+ 📚 Continually publishes multiple technical works, deeply involved in open source community and agent engineering practice, fully embracing AI and decentralization. 🔗 For more, follow personal blog; promotional cooperation at blogger alliance.

Maarten Grootendorst wrote "A Visual Guide to Agent Harnesses" on November 30, 2026, subtitled: A look at Pi, OpenCode, Hermes, and OpenClaw.

Agent harnesses are not all the same. Pi, OpenCode, Hermes, and OpenClaw each have their own design philosophy and capabilities. Choosing one has a big impact on your application, and it's not an easy choice.

In fact, putting the same LLM into these four frameworks yields four completely different agents:

The same LLM, placed into four different open-source harnesses

Pi is the most minimalist, OpenCode uses a shared server to serve different clients. Hermes writes skills back into memory, while OpenClaw connects to over thirty chat channels. And that's only part of the difference.

I went through the source code and used over thirty specially drawn diagrams to lay out from the bottom up how these harnesses work. My starting point was a teaching harness called TinyAgent that I authored with a coauthor for the book An Illustrated Guide to AI Agents.

These frameworks iterate quickly, so I thought it might be more useful to write against a specific snapshot. It will also be easier to update the diagrams after a year. ;)

Pinned snapshot: comparing TinyAgent, pi, OpenCode, Hermes, and OpenClaw by language, code size, first-round tokens, and focus

These are the version snapshots for comparison, you can verify them yourself:

What is a harness?

To talk about harnesses, let's start from the very beginning.

An LLM is essentially a machine that takes text in and produces text out. It reads tokens and generates tokens. To make it into something more, we add capabilities like Memory and Tools (usually to reasoning models) so it can interact with the environment.

Conceptual anatomy of an agent: connecting user and environment

Reasoning still happens in the LLM; these added capabilities connect it to the world beyond tokens. The puzzle has roughly two pieces:

This boundary is interesting and also shows the difference between LLM and harness:

Defining the harness as the software layer around the pluggable reasoning LLM

The model itself is stateless: it neither rewrites itself nor remembers what happened. The harness is everything around the model: it assembles prompts, executes tools, stores sessions, enforces guardrails, and so on.

Together, they form what we call an agent.

Agents can differ greatly. Choosing a small model usually results in worse performance than a frontier model. But the harness's influence on output is comparable, perhaps even greater.

Some harnesses are tiny. Some have many tools. Some have fewer guardrails. Some have more connectors. And so on. Once you look inside, differences abound, especially in size:

Comparing core harness code lines vs entire repo lines by actual area

On the left is first TinyAgent, a teaching framework that essentially shows what it means to build a harness yourself. It's small because it has to fit in a book. ;)

Production-grade frameworks are much larger; they handle guardrails, cross-session state, more complex memory systems, etc. Pi and OpenCode are already sizable, and OpenClaw is especially heavy. Here I separate the core application from the plugins/extensions a framework might have. I'm not sure whether counting plugins is fair, but it shows how much plugins can add to a framework.

Although they are all coding agents, Hermes and OpenClaw lean more toward "personal assistant" use cases, while the other two are more focused on coding. That's not easy, so their codebases are also larger:

Comparing the "coding harness" layer vs "personal assistant" layer across four projects

All four harnesses have a "coding" core that can read, edit, and run code. Hermes and OpenClaw additionally have a "personal assistant" layer for connecting chat channels (like Slack), saving personal memories, scheduled wake-ups, etc.

The codebase complexity adds up layer by layer, which lets me go step by step from the small TinyAgent to the complex OpenClaw.

So let's start with this little baseline and see the most basic components of a harness that turns an LLM into an agent.

TinyAgent

In the book (code is fully open source), we wrote a TinyAgent from scratch in Python. It is that harness that turns a local Gemma 4 model into an agent. Compared with the four frameworks later, it is only for teaching, not production. The code is about 600 lines, demonstrating what the core loop looks like. We cover reasoning, memory, tools, planning, subagents, etc.

Meet TinyAgent: Python modules corresponding to six chapters, forming a baseline agent of about 600 lines

It has a small set of modules that connect TinyAgent to different chapters of the book, such as LLM(), Memory(), Tools(), etc. Together, they form the most streamlined agent we can think of: no server, no chat connectors, no other extras. ;)

In this small codebase, the core loop is called Reason and Act, aka ReAct. This method may seem "old" (2022!), but every framework discussed in this guide still uses it. The model doesn't give a one-shot answer; ReAct makes it go back and forth between reasoning, acting, and observing.

ReAct loop: cycling between reasoning trace, tool actions, environment, and observation

Each loop, the model first thinks about what to do next, then executes that action, and finally observes the result of the action. This continues until it feels it has enough information to answer. Modern reasoning LLMs are trained in this pattern, using special tokens to indicate when to reason, when to call tools, and when to stop.

Mapping these steps to TinyAgent's core loop makes it clearer. Each step it:

Mapping ReAct to TinyAgent's five-phase run loop, with specific artifacts labeled

The core loop in TinyAgent actually takes fewer than twenty lines of Python code:

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's enough to make a working teaching agent.

Pi

Pi has a clear philosophy:

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

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

Meet pi: minimal terminal coding harness, four default tools, JSONL session tree, and mid-run steering

Compared to TinyAgent, it adds better compaction, specialized tools, mid-run steering, and other capabilities.

Compaction

Coding sessions that browse large codebases, do research, and write code eventually hit the context limit. Old turns are not simply discarded. Pi uses a technique called compaction, which shortens part of the conversation history to free up context window. In Pi, when the context window grows to 184k tokens, it compacts the conversation history.

When compacting, earlier turns are given to an LLM for summarization. The most recent 20k tokens are kept verbatim so the model knows exactly what it was just doing.

Context compaction: summarizing early turns 1-38, keeping recent turns 39-40 verbatim

Even if you add compaction to TinyAgent, it still doesn't persist the conversation. Close the terminal and the whole conversation is gone. Pi differs: every turn is written to JSONL, linked with id and parent pointers:

Comparing TinyAgent's in-memory Python message list and pi's append-only session.jsonl lines with branchable tree

This has a big advantage: you can easily go back to an earlier turn and branch off. It's very much like git.

Tools

Tools are probably one of the most important parts of an agent. They usually target capabilities like writing files, editing files, creating files. In TinyAgent, we give it whole-file write tools. If you want to change one line, you have to rewrite the entire file. Pi has an edit tool that can make very specific single-line changes, requiring much less output from the model.

Comparing TinyAgent rewriting a whole 600-line file and pi's targeted edit of 1 line

Pi's harness also handles logs more carefully. For example, if you run pytest, you might get a large log (like pytest.log). In Pi, this information is stored locally, and only the last 2,000 lines are sent back to the model, along with the file path.

Test failures usually appear at the end of the trace, so the model can still see the error; when needed, it uses Agentic RAG to search pytest.log.

pi stores all 15,000 lines of pytest output to disk, only feeds last 2,000 lines into prompt

So, the explicit tools the model can call directly (like edit) and the things the harness does itself (like truncating logs) are both important parts of an agent harness.

Steering

Finally, Pi has an interesting capability: it can be steered while it's running.

That means, while the model is still running, you can insert a question, and it will continue from there. The mechanism is: independent tools run in parallel, and just before handing the output back to the LLM, this question is injected. The model sees the tool output and also realizes the user added something extra, perhaps something they forgot to say.

pi executes tool calls in parallel, injects steering mid-run, and queues followUp after turn ends

Messages are of two kinds: steer messages modify the direction of the next LLM call; follow-up messages wait until the model finishes completely before entering.

In Pi's engine (agent-loop.ts#L294-L308), this fork takes only 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 in the ongoing inner loop, while getFollowUpMessages() is only fetched when the agent would naturally stop. All four production harnesses absorb compaction, targeted editing, and truncation from this baseline. OpenCode takes this loop and decouples it from the terminal.

OpenCode

OpenCode has roughly the same amount of code as Pi, but it adds an HTTP server in front of the agent so that various clients (terminal, desktop, etc.) can share the same SQLite session.

Meet OpenCode: client-server coding harness, shared HTTP server, SQLite database, and Plan / Build rules

Compared to Pi, OpenCode adds this shared server, SQLite database for session tracking, special Code Mode with subagents, and more.

Server

Pi's loop stops when you close the terminal because everything runs in the terminal. OpenCode decouples that: all tracking is written to a database (like opencode.db). So you can close the terminal and resume the process with a web app.

OpenCode reloads session rows from SQLite and appends new events each step, steps are stateless, and can continue via Web after CLI closes

At each step, the server reads the session history from the database, lets the model run one turn, then writes new information back for the next step. And the next step can be initiated from anywhere.

Code Mode

When agents encounter complex scenarios, they may need to run several tools in the right order. In simpler harnesses, the LLM runs one tool per turn, waits for output, then calls the next.

OpenCode does it differently, using a mechanism they call Code Mode. In this mode, the LLM can write a short script that chains these calls together. Tools no longer need to be called one at a time: it can call them all at once, and the model sees the outputs only after they all finish.

Comparing regular three-turn JSON tool round-trips and OpenCode's Code Mode script written in one go

Code Mode is a good example of a method called CodeAct. In this pattern, the model writes executable code (like Python) to orchestrate a sequence of tool calls. As models get more capable, the orchestration of scripts can be left to them. In doing so, they not only orchestrate multiple tool calls, but can also create new tools on the fly.

Planning

While browsing the codebase, one thing surprised me: how it handles planning mode. I expected to see some kind of specialized or complex planning architecture. Instead, their approach to switching between Build Mode and Plan Mode is simple and elegant.

In this approach, the agent loop remains completely unchanged, just the same kind of ReAct loop we saw before. But once you switch to Plan Mode, the harness intercepts the edit tool, allowing only modifications to plan.md. This restriction pushes the model toward planning. It can't really do anything else.

Switching back to Build Mode allows the edit tool to modify your chosen files again.

OpenCode switches between Build mode and Plan mode with only one permission rule on the same agent loop

These small tricks feel indicative of where we're heading. As LLMs get stronger, the need for very complex systems diminishes.

Subagents

Compaction is a good way to manage overly long traces and free up context for the model. But it's not perfect. For example, if you want an agent to find a function in a new repository, just finding it might consume thousands of tokens. You can compact the conversation afterward, but that's rather wasteful.

OpenCode has a cheaper form of compression: using subagents.

When the model encounters read-type tasks (read, grep, glob), it spawns a subagent to do the work. The subagent completes the task and fills its own context window, but only returns a summary of what it did:

OpenCode spawns an isolated read-only subagent, reads 25 files, consumes 40k tokens, returns only a ~200 token summary

A large chunk of context is reduced to a summary the main agent can use. The content the subagent searched is largely discarded.

This is another example of using a simple trick to avoid a bigger problem. Spawn a subagent to do the work, and consume its context window to keep noise out of the main agent.

Hermes

Hermes is already much larger, mainly for one reason: it adds a Personal Assistant layer that does things beyond coding. So it connects to various chat apps (like Slack and WhatsApp), has more tools (over 50), and uses a wide variety of skills (also over 50).

Meet Hermes Agent: gateway from personal assistant layer, 58 self-learning skills, approval LLM, and 7 backends

Compared to coding-only harnesses, Hermes adds a multi-chat gateway, self-learning skills, an internal approval judge and parallel workers, and several pluggable sandbox backends.

Memory

Coding-focused harnesses and personal-assistant-focused harnesses remember differently. For coding, an AGENTS.md file is usually enough and can go a long way. For a personal assistant, you often need to learn user preferences.

Hermes is a good example of using markdown files for personalization. It has USER.md and MEMORY.md, which the agent can write to and update its knowledge about you and your preferences.

Comparing human-edited project memory in pi and OpenCode and agent-self-rewritten personal memory in Hermes

These markdown files hold different types of constantly changing information:

So the technical environment and structure (MEMORY.md) and the user (USER.md) are separated. This modularity makes it easy for the model to distinguish project information from user preferences.

Skills

Hermes comes with over fifty built-in skills, for different purposes:

These skills are bundled with Hermes, so users don't have to install many different skills to do a variety of things.

As is common with skills, Hermes initially loads only their headers to know which skills are available. When the agent wants to read a full skill, it can load it on demand with the skill_view("...") tool.

Hermes loads only ~30 token YAML skill index in first turn, fetches 1,200 token instructions only when called

When an agent starts working, it only sees a small YAML header with the skill's name and description.

Skill learning

We've already seen that compared to other harnesses, Hermes places more emphasis on learning processes (and users). MEMORY.md and USER.md are part of it, but what if the agent wants to learn a specific pattern? Dumping everything into those two markdown files would quickly become noisy.

Its approach is direct: create new skills.

Specifically, a review agent runs at the end of a session and decides whether to create a new skill or update an existing one:

Hermes sends the final answer first, then background review agent distills tool calls over 10 times into reusable SKILL.md

After a session has more than 10 tool calls, the review agent activates. It looks at the entire trace and thinks about whether this can be condensed into a pattern. For example, if the model used 10+ tool calls when 3 would have sufficed. Recording this pattern will make future runs much more efficient.

This idea is interesting, like combining the growing skill library from Voyager with the self-reflection of Reflexion.

Subagents

Similar to OpenCode, Hermes can spawn subagents to share work. But unlike OpenCode, Hermes can spawn them in parallel, and then synthesizes their outputs into a set of summaries for the main agent:

Hermes's parent agent distributes auth.py, jwt.py, and tests/ to parallel depth-1 workers, then combines into summaries

These subagents are asked to focus on one piece of the puzzle (a file or a folder) and return a summary of what they did. The summaries are then passed back to the main agent.

Hermes is a good example of a personal assistant layer, but functionality can always be increased. The largest framework is OpenClaw.

OpenClaw

OpenClaw is one of the most well-known harnesses, and definitely the largest here. A big reason is the sheer number of chat channels, tools, and backends it connects, almost trying to do everything.

Meet OpenClaw: always-on gateway, over thirty chat channels, 30-minute heartbeat, memory flush, and nightly dreaming

It can basically do what the previous harnesses can, plus some differences and extra capabilities.

Multi-channel gateway

Hermes already has a gateway that routes chat apps to the LLM. OpenClaw goes further with a multi-channel gateway that separates private chats and group chats, with a privacy boundary in between.

OpenClaw routes all private DMs into one main session with MEMORY.md, and isolates team group chats

It splits into two sessions: Main Session and Group Session. The main session holds all your private DMs, and the group sessions are separate group chats, keeping personal content from leaking in.

Heartbeat

One memorable thing about OpenClaw is its heartbeat. A heartbeat is a mechanism that triggers every 30 minutes, waking the agent to check for new messages or whether to start a new task.

If the agent decides 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 every 30 minutes it knows what to look for.

OpenClaw's clock timeline: comparing scheduled Cron tasks and heartbeat that reads HEARTBEAT.md every 30 minutes, silently returns NO_REPLY, and one alert

In this example, a cron task starts at 08:00 every day, composes and sends a new email digest. At 8:30 (first heartbeat) and 9:00 (second heartbeat), the agent checks for action. If none, nothing happens. At 9:30, an important email arrives, and the agent notifies the user.

Memory

OpenClaw is designed to be always online. But sessions can run for days or even weeks, and compaction eventually clears important information from the trace.

So OpenClaw performs a memory flush before compaction, which simply writes memory to disk:

OpenClaw inserts a silent memory flush before compaction, writing daily markdown notes to disk

To query this information, OpenClaw uses Agentic RAG, making it easy to look up when needed. It uses a hybrid RAG: both classic methods (BM25) and more modern methods (embeddings):

OpenClaw's hybrid retrieval at query time: merging 0.7 dense vector score and 0.3 BM25 keyword score, then 30-day decay and MMR

Then it adds a 30-day recency decay to reduce the relevance of older files. Then uses Maximal Marginal Relevance (MMR) for deduplication and re-ranking. The ranked information is then fed to the LLM to keep it updated on important things.

Not done yet.

Daily logs still accumulate noise over weeks. To prevent this, OpenClaw runs a second pass, called Scheduled Dreaming:

OpenClaw's nightly scheduled dreaming: sequentially runs light, deep, and REM, promoting daily notes into MEMORY.md

Every night, the agent goes through a three-stage "sleep": light, deep, and REM. It scores daily logs as before (light), searches and extracts important facts (deep), and finally writes to long-term memory, MEMORY.md (REM).

I like that the framework tries to mimic what we ourselves do. Since users are sleeping anyway, why not use the time to organize the day's events?

Comparing the harnesses

Near the end of this guide, I want to put these harnesses side by side to see how they differ, starting with the system prompt.

Before you've typed a single character, each harness has already occupied part of the context window with system instructions, workspace files, and tool schemas.

Comparing token counts for prompt/files vs tool schemas in first-turn initial context across five projects, to scale

Hermes and OpenClaw look interesting. They spend almost the same number of tokens, but for very different reasons. Hermes leans on tool schemas (21 default tools), while OpenClaw only exposes 7 core tools by default, focusing on workspace files (SOUL.md, MEMORY.md, rules).

Then, as sessions grow toward a context window, each harness has a different compaction mechanism:

Comparing compaction thresholds across TinyAgent, pi, OpenCode, Hermes, and OpenClaw under a 200k context window

Compared with other harnesses, Hermes compacts early; OpenClaw stores a lot of context in daily logs for tracking.

Finally, we can also compare how these five harnesses manage session storage, persistent files, and cross-session recall:

Comparing session storage, persistent files, and cross-session recall across TinyAgent, pi, OpenCode, Hermes, and OpenClaw

It can be seen that the more complex the harness, the more memory evolves step by step. For example, OpenCode uses a database to track sessions, while OpenClaw saves daily files, which is interesting.

This also shows how widely different harnesses can be.

But choosing one is not straightforward. It largely depends on what you're looking for. The applicable scenarios and main trade-offs can be roughly seen like this:

Summary table of applicable scenarios and main trade-offs for five open-source harnesses

Complete anatomy

Jay and I spent a lot of time trying to condense "what is an agent" into one overall idea. Using this idea to connect everything discussed here, you can fold the principles from the harness context into a fairly clear overall diagram:

Complete harness anatomy: mapping interfaces (Ch 10), multi-agent (Ch 8), memory (Ch 4), tools (Ch 5), and planning (Ch 6) back to book anchors

The LLM sits in the center of the harness, yet the harness doesn't modify it. What turns a great chatbot into something that can interact with the world is everything around the LLM.

Over the past few years, the AI world has become what it is now, and that's quite beautiful:

"From words to actions, from LLM to agent."

Conclusion

That concludes this diagrammatic journey through open-source agent harnesses.

I hope that after seeing these frameworks side by side, you'll have a clearer map in your head when choosing a harness or even designing your own. If you want to build these fundamentals from scratch, with complete code and several hundred additional diagrams, check out our book An Illustrated Guide to AI Agents.

Cover of An Illustrated Guide to AI Agents with a leaping dolphin

The book's official website is at. It's available on Amazon. All code is on GitHub.

Sources and notes