Skip to content

The loopctl Knowledge Base

This is a complete, plain-language guide to loopctl, the Rust framework for building agents. An agent is a program where an AI model does multi-step work by calling tools you write.

This knowledge base is written for end users like you. Every concept is explained at first use, every abbreviation is decoded in the Glossary, and every claim is grounded in the source code of the crate.

If you are new to loopctl, read these four pages in order, because they build on each other. Once you finish them, you will know which section to open for any question you hit later:

  1. What is loopctl? covers the problem it solves, a working example in 20 lines, and the five ideas behind the design.
  2. The big idea covers the brain and hands split, the two buffers, and who decides what. It is the most important page here.
  3. Anatomy of a run traces one full run through every layer, step by step.
  4. The codebase map lists every folder and file, one line each.
Section What you find inside
01 Core data The vocabulary everything else uses: messages, tools, tool selection, the API client, stream events, errors, and configuration
02 The engine How a run actually works: state machine, driver loop, LLM turn, tool dispatch, cancellation, compaction, termination, model switch, context accounting, steering, and history rewind
03 Safety systems Keeping your agent alive and harmless: middleware, loop detection, convergence, model fallback, reflection and recovery, tool health, safety shield, permissions, approvals and grants, and the budget gate
04 Extensions Watching and shaping runs: observers, hooks, memory, contributors, attachments, the component bundle, and the event hub
05 Providers Real models: overview and features, the OpenAI family, Anthropic, Gemini, Bedrock, SSE, grammar, and embeddings
06 Integration Structured answers and the wider world: structured output, MCP, the derive macro, presets, testing, the manifest, and loopctl-client
07 File reference One page per source file, covering what it is, its key items, and its gotchas
08 Cookbook Every gotcha collected and 18 complete recipes
09 Principles The ideas under the hood, each explained from scratch: sans-IO, state machines, tokens and context windows, soft and hard errors, backoff and jitter, circuit breakers, windows, EWMA, and similarity, cooperative cancellation, caching and invalidation, rate limiting, parallel waves, and text matching

Read What is loopctl, then The big idea, then Tools. After that go to Recipes and start with recipes 1 through 3, then Gotchas.

Something went wrong and you want to know why

Section titled “Something went wrong and you want to know why”

Read Errors, then Termination, then the subsystem page for your symptom, whether that is compaction, fallback, or detection. Finish with Gotchas.

Read the Codebase map, then the File reference, where every file has a page.

Read The big idea, then the Principles section in order, where each page stands alone. Then go back to any engine or safety page, which will now read like an old friend.

Read The big idea, then Sans-IO, then state machines. After that take the state machine page, the driver loop, and the four mechanism pages on LLM turn, dispatch, cancellation, and compaction. Finish at Termination.

Read What is loopctl, then the whole safety section, then the Production hardening recipe, and finally Gotchas.

These pages are grounded in source. They were written against loopctl v0.4.1, so every default value, threshold, and behavior stated here comes from the code or its tests.

They are plain by design. You get no unexplained jargon, short sentences, and every diagram can be read on its own.

They are honest about limits. Where the crate drops images, where defaults surprise you with zero retries, and where heuristics are only heuristics, it is all in the open, mostly in Gotchas.

You can read these pages in any order once you know the four start-here pages. You can also cite them in your own docs, since each page names the file it describes.

For companion resources, see the crate’s API documentation on docs.rs for the item-level reference, its README for the feature matrix, and TESTING.md in the repository.