skip to content

Agent Runs & Queueing

How one inbound message becomes an agent run: prompt assembly, model and tool calls, streaming and reply shaping, plus what happens when a second message arrives mid-run.

part ofAI coding toolsread it →
on this pageshow

explore

questions

5

In OpenClaw, what happens between an inbound chat message reaching the Gateway and the agent's reply going back out?

level: middleimportance: must knowfreq 12%

answer

  1. one run per session at a time
  2. lane wait before any model call
  3. base prompt, skills, bootstrap files
  4. assistant, tool and lifecycle streams
  5. silent token filtered at shaping

basics

~20 s

OpenClaw turns each inbound message into a serialized agent run: it resolves the session, waits for that session's lane, builds the prompt from its base prompt, skills and workspace files, calls the model and tools, then shapes and delivers the reply.

solid answer

~40 s

Each inbound message becomes one serialized **agent run** inside the Gateway. The run resolves its session, model and skills snapshot, then waits on that session's lane, so only one run touches a session at a time, and on the global `main` lane capped by `agents.defaults.maxConcurrent`. Once admitted, it assembles the system prompt from OpenClaw's base prompt, the skills prompt, workspace bootstrap files such as `AGENTS.md`, `SOUL.md` and `USER.md`, and per-run overrides. The model call and tool calls stream as `assistant`, `tool` and `lifecycle` events. Reply shaping drops the silent token `NO_REPLY` and removes text a messaging tool already sent, then the reply is delivered. On a context overflow, auto-compaction summarizes older turns and the request is retried; the whole run is bounded by `agents.defaults.timeoutSeconds`, 48 hours by default.

go deeper

for a junior

Recall the order: session, queue, prompt, model, tools, reply. Know that one chat is handled one run at a time and that the workspace files feed the prompt.

for a middle

Explain each stage with its real names: the session and main lanes, what goes into the system prompt, the three event streams, and how NO_REPLY and messaging-tool duplicates are filtered before delivery.

for a senior

Show you can locate a slow or silent reply by stage: lane wait in the logs, auto-compaction and retry, the provider retry budget, the idle watchdog and the 48-hour run budget versus a wait-only timeout.

for a principal

Weigh the run budget, compaction and concurrency defaults against cost and responsiveness for the people the install serves, and decide which of them the team should pin explicitly rather than inherit.

## What an agent run is In OpenClaw, an **agent run** is the unit of work that turns one inbound message into actions and a reply. Runs happen inside the **Gateway**, the single always-on process that holds every channel connection. A run is not a thread or a container; it is a serialized, per-session piece of work that owns the session's transcript while it executes. Knowing the stages lets you read the logs, guess where a slow or silent reply is stuck, and pick the right knob. ## The run sequence From the moment a WhatsApp, Telegram, Slack or Discord message reaches the Gateway, a run moves through these stages: 1. **Intake.** A redelivered message with the same id on the same route is ignored by an in-memory dedupe cache, so a reconnect does not trigger a second run. If `messages.inbound` debouncing is configured, rapid text messages from one sender can be batched into a single turn first. 2. **Session resolution.** The run resolves its session key and persists session metadata. Which session a message joins is decided by the session rules, a separate subject; the run simply uses the result. 3. **Turn setup.** Model and thinking defaults are resolved and the skills snapshot is loaded. 4. **Queueing and preparation.** The run waits on its **session lane** (`session:<key>`), which guarantees that only one run touches a session at a time, and then on the global `main` lane, capped by `agents.defaults.maxConcurrent`. Once admitted, the workspace is resolved and a writer claim on the transcript is recorded so a superseded run cannot commit stale data. 5. **Prompt assembly and inference.** The system prompt is built and the model is called. 6. **Tool execution.** Requested tools run; their start, update and end events stream out. 7. **Reply shaping and delivery.** Final payloads are assembled, filtered and sent to the channel. 8. **Persistence and settlement.** The transcript write completes and lifecycle `end` (or `error`) is emitted. ## Prompt assembly The system prompt is built from four inputs: - OpenClaw's **base prompt**; - the **skills prompt**, from the loaded skills snapshot; - **bootstrap context** from the agent's workspace: `AGENTS.md`, `SOUL.md`, `IDENTITY.md`, `USER.md`, `MEMORY.md` when present, and `BOOTSTRAP.md` only on a brand-new workspace; - **per-run overrides**. Model-specific limits and the compaction reserve are enforced at this step. Daily `memory/*.md` notes are not pasted in on ordinary turns; the model reaches them on demand through the memory tools. What each workspace file should contain belongs with the workspace material, not here. ## Tools and streaming While the model works, the Gateway exposes three event streams: | Stream | Carries | | --- | --- | | `assistant` | text deltas from the model | | `tool` | tool start, update and end events | | `lifecycle` | `start`, `finishing`, `end` and `error` phases | Tool results are sanitized for size and image payloads before they are logged or emitted. On chat channels, these deltas are not pushed token by token; block streaming and channel preview modes decide what the user actually sees. ## Reply shaping Before anything is delivered, OpenClaw cleans the payload list: - The exact silent token `NO_REPLY` is filtered out of outgoing payloads. - Text the agent already sent through a messaging tool is removed as a duplicate. - A fallback tool-error warning is added only when the run ends with a tool failure and the user would otherwise get no reply. The host, not the model, decides whether a reply is required. Direct requests require an answer by default, so a model-authored `NO_REPLY` is treated as empty output rather than permission to stay silent. ## Compaction, retries and timeouts inside a run A run can recover from several failures without the user resending anything: - **Auto-compaction** is on by default. When the session nears the context limit, or the provider returns a context-overflow error, older turns are summarized into a compact transcript entry and the request is retried. On retry, in-memory buffers and tool summaries reset to avoid duplicate output. The full history stays on disk. - **Transient provider failures** are retried inside the run: rate limits get up to 10 total attempts, and other transient failures up to eight retries within a 90-second window, with exponential backoff. When that budget is exhausted, configured fallbacks take over, which is a separate subject. - **The run budget** is `agents.defaults.timeoutSeconds`, 48 hours by default; progress does not reset it, and `0` removes it. A model request with no response chunks is also cut off by an idle watchdog (120 seconds for cloud providers, 300 for self-hosted ones). - **`agent.wait`** is only a wait: its 30-second default timeout returns `status: "timeout"` with the `runId` and leaves the run going. ## Reading it in practice When a reply is slow, the stage tells you where to look: a long `queued for ...ms` line in verbose logs means the lane, an `embedded run auto-compaction start` line means compaction, and a transient retry indicator means provider recovery. A run that ends with nothing sent usually means the payload was filtered or already delivered by a tool, not that the run was lost.

  • In OpenClaw, does an `agent.wait` call that times out stop the run it was waiting on?
    No. `agent.wait` is wait-only: after its 30-second default (or the `timeoutMs` you pass) it returns the `runId` with `status: "timeout"`, and the run keeps going. Call it again on the same `runId` to see the outcome. What actually aborts a run is its execution budget, `agents.defaults.timeoutSeconds` (48 hours by default), an explicit abort, or a Gateway disconnect.
  • What does an OpenClaw run do when the provider rejects the request with a context-overflow error?
    Auto-compaction handles it inside the run: older turns are summarized into a compact transcript entry, recent messages stay intact, and the request is retried. In-memory buffers and tool summaries reset so the user does not get duplicate output. The full history stays on disk. Setting `agents.defaults.compaction.enabled: false` turns off proactive threshold compaction, but overflow recovery and manual compaction stay available.
  • Why can an OpenClaw run finish successfully without the reply shaping step sending a new message?
    Two common reasons. The model may answer with the silent token `NO_REPLY`, which is filtered from outgoing payloads where a reply is optional, such as ambient room events. Or the agent already delivered its answer through a messaging tool, and reply shaping removes the duplicate. Direct requests still require an answer, so `NO_REPLY` does not let the model ignore a direct question.

  • Every new message in a chat starts its own parallel run on the same session.
  • A timed-out agent.wait call means the agent run was cancelled.
  • Hitting the context limit always ends the run with an error the user must fix.
  • Compaction deletes the older conversation history from disk.
  • A model reply of NO_REPLY lets the agent ignore a direct question.
  • Daily memory/YYYY-MM-DD.md logs are pasted into every prompt.
open as a page

In OpenClaw, how do the queue modes steer, followup, collect and interrupt handle messages that arrive while an agent run is active?

level: middleimportance: must knowfreq 10%

basics

~20 s

The default steer mode injects a mid-run message into the active run; followup queues each message for its own later turn; collect merges queued messages into one later turn; interrupt aborts the active run and answers the newest message.

open as a page

Why does an OpenClaw agent's reply reach a chat app as a finished message or a few blocks rather than streaming token by token?

level: juniorimportance: should knowfreq 7%

basics

~20 s

OpenClaw never streams token deltas into channel messages. Block streaming, which sends finished chunks as separate messages, is off by default, and live previews depend on each channel's streaming mode, so most replies arrive complete.

open as a page

In OpenClaw's default steer queue mode, what happens to a running tool call, and to the calls planned after it, when a new message arrives mid-run?

level: seniorimportance: should knowfreq 6%

basics

~20 s

Steering does not abort a tool that is already running. It finishes, any planned sequential calls that have not started are skipped with a synthetic result, and the new message is added before the next model call. Interrupt mode is the one that aborts.

open as a page

After an OpenClaw upgrade, a small host serving many busy chats hits provider rate limits and memory pressure; which limit governs concurrent agent runs, and how do you cap it?

level: seniorimportance: nice to knowfreq 4%

basics

~20 s

Inbound runs share the global main lane, capped by agents.defaults.maxConcurrent. Since OpenClaw 2026.9.5 the unset default is four runs per available CPU, at least eight, so a constrained host should set an explicit lower value.

open as a page