An agentic loop is the full “real” run of an agent: intake → context assembly → model inference → tool execution → streaming replies → persistence. It’s the authoritative path that turns a message into actions and a final reply, while keeping session state consistent.
In CoderClaw, a loop is a single, serialized run per session that emits lifecycle and stream events as the model thinks, calls tools, and streams output. This doc explains how that authentic loop is wired end-to-end.
agent and agent.wait.agent command.agent RPC validates params, resolves session (sessionKey/sessionId), persists session metadata, returns { runId, acceptedAt } immediately.agentCommand runs the agent:
runEmbeddedPiAgent (pi-agent-core runtime)runEmbeddedPiAgent:
subscribeEmbeddedPiSession bridges pi-agent-core events to CoderClaw agent stream:
stream: "tool"stream: "assistant"stream: "lifecycle" (phase: "start" | "end" | "error")agent.wait uses waitForAgentJob:
runId{ status: ok|error|timeout, startedAt, endedAt, error? }SessionManager is opened and prepared before streaming.CoderClaw has two hook systems:
agent:bootstrap: runs while building bootstrap files before the system prompt is finalized.
Use this to add/remove bootstrap context files./new, /reset, /stop, and other command events (see Hooks doc).See Hooks for setup and examples.
These run inside the agent loop or gateway pipeline:
before_model_resolve: runs pre-session (no messages) to deterministically override provider/model before model resolution.before_prompt_build: runs after session load (with messages) to inject prependContext/systemPrompt before prompt submission.before_agent_start: legacy compatibility hook that may run in either phase; prefer the explicit hooks above.agent_end: inspect the final message list and run metadata after completion.before_compaction / after_compaction: observe or annotate compaction cycles.before_tool_call / after_tool_call: intercept tool params/results.tool_result_persist: synchronously transform tool results before they are written to the session transcript.message_received / message_sending / message_sent: inbound + outbound message hooks.session_start / session_end: session lifecycle boundaries.gateway_start / gateway_stop: gateway lifecycle events.See Plugins for the hook API and registration details.
assistant events.text_end or message_end.tool stream.NO_REPLY is treated as a silent token and filtered from outgoing payloads.compaction stream events and can trigger a retry.lifecycle: emitted by subscribeEmbeddedPiSession (and as a fallback by agentCommand)assistant: streamed deltas from pi-agent-coretool: streamed tool events from pi-agent-coredelta messages.final is emitted on lifecycle end/error.agent.wait default: 30s (just the wait). timeoutMs param overrides.agents.defaults.timeoutSeconds default 600s; enforced in runEmbeddedPiAgent abort timer.agent.wait timeout (wait-only, does not stop agent)