OpenClaw Deep Dive — Local Agent Pipeline Design Through the Lens of ReAct Loops, Context Assembly, and the Lobster DAG
When I first encountered OpenClaw, I honestly thought, "Just another AI agent framework." LangChain, AutoGPT, CrewAI... there are so many similar things out there. But when I actually dug into it, it was a bit different. In particular, once you understand how the tool call chain connects internally and what elements the context is assembled from on each request, you can see why this framework is worth using for designing production automation pipelines.
For a quick bit of background: as the local LLM ecosystem has matured — with Ollama officially integrated as a provider, and models like Qwen3 and Llama 3.x delivering practical performance even on laptop-grade hardware — it's become possible to run agent pipelines without sending data to external services. OpenClaw has established itself as the framework that fills the layer needed at that point. Specific metrics like GitHub star counts vary widely depending on when you look, and I haven't been able to verify primary sources, so I'll omit citations on that in this article.
In this post, I'll focus on how the ReAct loop actually works, what elements make up the context package, and how to build deterministic multi-agent pipelines using the Lobster workflow engine. The focus is on understanding the internal architecture from a pipeline design perspective, not installation and Hello World.
Why the Three-Layer Separation Matters
OpenClaw's architecture is separated into three layers. At first glance it can feel excessive, but once you've operated real automation pipelines, you'll see how practical this separation is.
The Cognitive Layer is where the LLM actually reasons. How efficiently the context window is assembled is determined here. The Execution Layer runs the model's chosen tools in isolation inside Docker containers. This isolation matters because it prevents the skills chosen by the agent from directly accessing the host system. The Persistence Layer, backed by SQLite or PostgreSQL, stores conversation history and memory, providing context continuity across sessions. The reason the diagram shows text responses also passing through the Persistence Layer before termination is this — the final response must also be saved if you want to continue from where you left off in the next session.
Because these three layers are separated, replacing just the LLM provider from Ollama to another model, or switching just the memory backend from SQLite to PostgreSQL, can be done relatively independently.
For reference, MCClaw, which appears later in this article, is the subcomponent within the Cognitive Layer that actually handles local LLM inference. OpenClaw doesn't isolate it as a separate layer, but it acts as an adapter that connects directly to local runtimes like Ollama and llama.cpp.
The ReAct Loop — How It Actually Works
ReAct is a portmanteau of Reasoning + Acting, as defined in the original paper (Yao et al., 2022). The principle itself is simple, but looking at how OpenClaw implements it makes the design decisions clearly visible.
The key is the loop termination condition. The loop ends when the model returns a text-only response rather than a tool call. Once you understand this, it makes sense why tool definitions need to be precise. If the model can't distinguish between situations where it should use a tool versus answer with text, the loop may terminate unexpectedly early or, conversely, run for too long.
The flow of the tool call chain expressed in pseudocode looks like this (a conceptual example).
def react_loop(message, context_package):
while True:
response = llm.invoke(context_package + [message])
if response.type == "text":
return response.content
elif response.type == "tool_call":
tool_result = gateway.invoke({
"node": response.tool_name,
"args": response.tool_args,
})
context_package = update_context(context_package, tool_result)The actual OpenClaw code is far more complex than this, but the core flow of the design is like this. In particular, because tool results are appended to the context before resubmission, the context grows linearly as the tool chain gets longer. I'll return to this point later.
The Context Package — What Gets Injected Each Session
OpenClaw assembles several pieces into a single context package at the start of a session.
SOUL.md defines the agent's identity. Since this file is injected every session, what you write here directly affects token costs.
# Agent Persona
You are a backend infrastructure monitoring agent.
Primary roles: CI/CD pipeline monitoring, build failure analysis, automated PR creation
## Boundary Values
- No direct write operations to production databases
- Approval gate required before external API calls
- Never output sensitive environment variables to logsAGENTS.md contains project-level behavioral guidelines, and TOOLS.md contains the list of available skills.
Semantic Memory Search
The interesting part here is that relevant past sessions are retrieved via semantic search and injected into the context. It's known to work by chunking Markdown files in units of a few hundred tokens, embedding them with some overlap, and storing them in SQLite. A file watcher incrementally updates changes. The exact chunk size and overlap values can vary depending on the version and configuration, so before putting this into production, it's safer to check the OpenClaw Sessions & Context Management docs or the actual source code.
Rather than simply injecting the entire history, it selects only past sessions that are semantically relevant to the current request, making efficient use of context tokens. There are reports that this approach has inspired other projects, but since I haven't been able to verify primary sources, I won't cite that here.
Local LLM Integration — Common Pitfalls in Ollama Configuration
MCClaw, as briefly introduced earlier, is the subcomponent within the Cognitive Layer responsible for local LLM inference. It connects directly to Ollama's /api/chat endpoint, and this is where many people fall into a common trap.
# Incorrect configuration — tool calls silently dropped
mcclaw:
base_url: "http://localhost:11434/v1" # tool calls dropped when using /v1 suffix
# Correct configuration
mcclaw:
base_url: "http://localhost:11434" # direct connection to /api/chat endpoint
model: "qwen3:27b"The key names may differ from what's actually used in the OpenClaw config file, so it's worth checking the official schema when setting things up. In this article, component names are written as MCClaw and config keys use snake_case consistently.
When the /v1 suffix is added, Ollama routes to the OpenAI-compatible endpoint, which has a known issue where tool_calls delta chunks aren't properly emitted during streaming. Tool calls just disappear without any error message. If tool calls aren't working as expected with your local LLM setup, start by checking this.
As of 2026, the local models frequently mentioned in the OpenClaw community are the Qwen3 and Llama 3.x families. Benchmark rankings vary considerably between reports, and performance claims on the framework's own blog are difficult to verify, so running your own A/B tests with your actual tasks is far more reliable before adopting anything. On Apple Silicon unified memory environments and recent-generation GPUs, local operation of 70B-class models is increasingly common. For detailed configuration examples, refer to the OpenClaw + Ollama Setup Guide.
Building Deterministic Multi-Agent Pipelines with Lobster
Why You Need a Deterministic Workflow Engine
A single-agent ReAct loop is versatile, but in complex automation pipelines, predictability matters. A structure that says "the agent will figure it out" is hard to debug and difficult to trust in production.
For this, the OpenClaw ecosystem has the Lobster workflow engine (openclaw/lobster). It's a deterministic DAG workflow engine written in TypeScript that supports JSON data flow between steps, approval gates, and resume tokens. The npm package name and organization name may change with releases, so when actually installing, check the package.json in the GitHub repository or the npm registry to import using the actual name. The examples below use @openclaw/lobster as the organization scope.
CI/CD Build Failure Auto-Recovery Pipeline
As a practical example, here's how a build failure detection → error analysis → automated PR creation pipeline looks when built with Lobster (a conceptual example).
import { Workflow, Step, ApprovalGate } from '@openclaw/lobster';
const buildRecoveryPipeline = new Workflow({
name: 'build-failure-recovery',
steps: [
new Step({
id: 'detect-failure',
agent: 'ci-monitor-agent',
input: (ctx) => ({ buildId: ctx.trigger.buildId }),
}),
new Step({
id: 'analyze-error',
agent: 'log-analyzer-agent',
input: (ctx) => ({ logs: ctx.steps['detect-failure'].output.errorLogs }),
}),
new ApprovalGate({
id: 'pr-approval',
message: (ctx) =>
`Root cause: ${ctx.steps['analyze-error'].output.summary}. Would you like to approve PR creation?`,
}),
new Step({
id: 'create-fix-pr',
agent: 'code-fix-agent',
input: (ctx) => ({ rootCause: ctx.steps['analyze-error'].output.rootCause }),
}),
],
});An earlier draft had an inconsistency where step outputs were registered with a separate alias (output: 'failureReport') but accessed by step id; here the approach is unified — steps are accessed by their id and return values are referenced via .output. Be sure to consult the Lobster repository documentation to confirm which API style actually exists.
The key to this structure is that each step calls an independent agent, but the overall flow is controlled deterministically by the DAG. Resume tokens are also useful in practice. When a pipeline is paused at an approval gate, an external system (Slack bot, webhook, etc.) can pass a token to resume execution from where it left off.
A team case study showing significant reduction in build failure recovery time with this kind of pipeline is introduced in Context Studios' production adoption write-up. Keep in mind that it's a first-party account.
Tradeoffs — Honestly Speaking
OpenClaw isn't the right fit for every automation scenario. The comparison table below is an impressionistic assessment of OpenClaw including Lobster. Looking at ReAct alone would shift the "open-ended tasks" and "predictability" axes, so I've distinguished them in footnotes below.
| Criterion | OpenClaw (+ Lobster) | n8n | AutoGPT | LangGraph |
|---|---|---|---|---|
| Execution Style | LLM reasoning-based | Fixed flow | Autonomous agent | Graph-based |
| Data Locality | Fully supported | Config-dependent | Config-dependent | Config-dependent |
| Predictability | High with Lobster¹ | High | Low | Medium |
| Operational Complexity | High | Low | Medium | Medium |
| Open-ended Tasks | Requires explicit DAG design² | Not possible | Strong | Medium |
| Token Cost | High | None | High | Medium |
| Auditability | High (local Markdown + JSONL) | Medium | Low | Medium |
¹ Using ReAct alone has a level of non-determinism similar to other LLM agent frameworks. ² Unlike fully autonomous approaches like AutoGPT, high-freedom goals need to be broken down into explicit steps in a DAG to work reliably.
Common Problems You'll Encounter in Practice
Context explosion. SOUL.md, AGENTS.md, past conversation summaries, and the skills list are all injected into the context on every request. If your config files become bloated, token costs will spike sharply. Keep SOUL.md as concise as possible, and include only the skills you actually need in TOOLS.md.
Open-ended tasks. For high-freedom goals like "find and fix performance issues in this codebase," OpenClaw is more constrained than AutoGPT-class autonomous agents. In these cases, it's better to explicitly break down the steps into a Lobster DAG.
Ollama streaming issues. The /v1 streaming bug mentioned earlier applies here too. If tool calls aren't behaving as expected, check this first.
High-volume event-driven automation. Since the LLM reasons on every interaction, costs rise quickly in systems with large event volumes. If most of your automation is simple branching logic, a fixed-flow tool like n8n is more economical.
ReAct Alone vs. Lobster DAG — How to Divide Them
In the end, the practical takeaway from this article comes down to one thing: use ReAct alone versus Lobster DAG based on the nature of the workload.
- Exploratory / investigative tasks — Tasks like codebase analysis, tracing a root cause from logs, or research-style summarization where the next step depends on the previous result are a good fit for the ReAct loop. Keep TOOLS.md lean, and frequently review the text response patterns that serve as termination conditions.
- Operational / recovery tasks — Flows where audit and reproducibility matter, like CI/CD recovery, deployment automation, and on-call response, should have their skeleton built with a Lobster DAG, using ReAct only in a limited capacity within each step. Figuring out where to insert approval gates is half the design work.
- Borderline tasks — Cases like automated code review are a good fit for a hybrid: capture the top-level flow in a DAG (receive diff → analyze → post comment) and leave only the analysis step to ReAct.
Conversely, for work with clearly defined "if A then B" structures, like simple notification pipelines or data transformations, there's no reason to bring in OpenClaw. n8n or a custom worker is sufficient.
Once you understand the internal structure, it becomes much clearer how far to trim SOUL.md, which steps need approval gates, and where the context can explode. Knowing versus not knowing the internal flow of a framework makes a real difference when you're the one designing and operating pipelines.
References
- What is OpenClaw: Self-Hosted AI Agent Guide — Contabo Blog
- OpenClaw: The AI Agent Framework Explained (2026 Update) — clawbot.blog (framework's own blog; performance claims should be independently verified)
- Sessions & Context Management — OpenClaw Docs (DeepWiki)
- OpenClaw Memory System, Fully Explained — ai-coding.wiselychen.com
- GitHub - openclaw/lobster
- OpenClaw + Ollama Setup Guide — codersera.com
- OpenClaw vs. n8n — decodo.com
- OpenClaw vs AutoGPT vs CrewAI vs LangGraph
- How I Built a Deterministic Multi-Agent Dev Pipeline Inside OpenClaw — DEV Community
- The Complete OpenClaw Guide: How We Run an AI Agent in Production (2026) — Context Studios (first-party account)
- Reference Architecture: OpenClaw (Early Feb 2026 Edition) — robotpaper.ai
- ReAct: Synergizing Reasoning and Acting in Language Models — Yao et al., 2022