This document details how the Loop language maps to the core concepts of Loop Engineering (specifically the 4 Loops from LangChain and the 6 Primitives from ReceiptRoller).
Loop natively implements and manages the stack of agentic loops to automate and govern AI execution:
| Loop Level | Description | Implementation in Loop DSL & Runtime |
|---|---|---|
| 1. The Agent Loop | The model calling tools in a loop to execute a task. | Enforced by the task and tools blocks. The runtime executes this cycle recursively until termination. |
| 2. The Verification Loop | A grading harness that evaluates correctness and retries. | Handled by the invariant block. The runtime acts as the grader, rolling back state transactions in sled immediately if an invariant is violated. |
| 3. The Event-Driven Loop | Connecting the agent to triggers, crons, or webhooks. | Managed by the loop run and loop switch commands. It runs headlessly in TUI/CLI modes and supports execution crons. |
| 4. The Hill-Climbing Loop | Analyzing execution traces to optimize prompts and configuration. | Managed by session metrics logged locally. Trace outputs and cost statistics are structured to let optimizer agents rewrite the prompt strategy. |
If a loop is the engine, the six primitives are the component parts that make the engine durable and production-ready:
- Concept: The scheduled triggers that wake the agent up and start the work.
- Loop Mapping: The Loop binary runs as an automated execution process, executing script workflows locally or in remote environments.
- Concept: Using isolated directories (like Git worktrees) to prevent file collisions between concurrent agent runs.
- Loop Mapping: The runtime sandbox broker restricts tool operations to a local execution sandbox (
.loop_sandbox) with path traversal check verification.
- Concept: Structuring guidelines and conventions in a markdown specification so the model doesn't have to guess or relearn them.
- Loop Mapping: Enforced by the
strategyblock. It passes explicit context instructions directly to the LLM agent prompt.
- Concept: Universal connectors (like Model Context Protocol) to pull issues, databases, or third-party APIs.
- Loop Mapping: Configured by the
toolsdeclaration block. The VM maps tool signatures dynamically to isolated environment commands.
- Concept: The agent generating code/text must not be the same agent grading it.
- Loop Mapping: Handled via the separation between the LLM generator (which operates within
strategyand drafts mutations) and the compiler VM (which evaluatesinvariantchecks independently using deterministic expressions).
- Concept: Keeping agent state outside the model's transient context window so it persists across runs.
- Loop Mapping: Managed by the State Ledger. Loop uses
sled(a transactional embedded database) to save session logs and memory variables. A mid-sessionloop switchcompletely clears LLM prompt memory but restores the exact state variables from the database, mitigating context inflation.