Cookbook
Every concept in these docs has a runnable example in the CARL repo. This is the index; each links to a complete, executable script.
Running examples
Section titled “Running examples”# Examples that call an LLM read OPENAI_API_KEY (and optionally OPENAI_BASE_URL,# DEFAULT_EXAMPLES_MODEL); the Makefile targets also load a .env fileexport OPENAI_API_KEY="sk-or-v1-..."
# Run one examplePYTHONPATH=$(pwd) uv run python examples/orchestration/basic_chain_example.py
# Or run them allmake examplesExamples that use a mock client run without an API key. Checked without a
key on 0.5.2: replan_deterministic, metrics, token_usage,
dataset_evaluator, reflection, map_step, chain_as_tool,
shell_session_artifacts. code_step and command_steps print a dry run
unless you provide a sandbox runtime.
Orchestration
Section titled “Orchestration”| Example | Shows |
|---|---|
| basic_chain | Core chain, dependencies, serialization. |
| parallel_branches | DAG parallelism across independent steps. |
| conditions | Conditional branching. |
| loop_until | Loop-back until a condition holds. |
| map_step | Bounded fan-out over a JSON array (no API key). |
| command_steps · command_plan_capabilities · command_llm_context | Argv commands under a host CommandPolicy; typed capability planning. |
| shell_session_artifacts | One shell process with portable artifacts. |
| execution_modes_mock / pipeline | FAST vs SELF_CRITIC. |
Tool calling
Section titled “Tool calling”| Example | Shows |
|---|---|
| tool_steps | Tool steps, memory, mixed chains. |
| structured_output | Schema-constrained JSON output. |
Agents (multi-agent)
Section titled “Agents (multi-agent)”| Example | Shows |
|---|---|
| supervisor_routing | LLM routing to specialists. |
| llm_council | N-sample voting. |
| human_in_the_loop | Pause for human input. |
| chain_as_tool | A chain embedded as an isolated tool (no API key). |
| code_step | Strict generated-Python step; needs a sandbox image (CARL_CODE_IMAGE) to execute. |
| agent_skill | AgentSkill execution. |
The Claude Code and Codex steps have their own pages with examples: Claude Code step, Codex step.
Evaluation
Section titled “Evaluation”| Example | Shows |
|---|---|
| metrics | Custom + built-in metrics (no API key). |
| dataset_evaluator | Batch evaluation + report. |
| reflection / reflection_metrics | Reflection, metric-fed reflection. |
RE-PLAN
Section titled “RE-PLAN”| Example | Shows |
|---|---|
| deterministic · llm_checker · voting · checkpoint_rollback · budget_guard | The RE-PLAN strategies. |
Skills & LLM inference
Section titled “Skills & LLM inference”| Example | Shows |
|---|---|
| chain_from_description | Generate a chain from NL. |
| skill_resolver | URI-based skill resolution. |
| openrouter · token_usage | OpenRouter, token accounting. |
Build one yourself
Section titled “Build one yourself”See the end-to-end tutorial — a multi-step agent built from scratch, combining LLM, tool, memory, and conditional steps.