Skip to content

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.

Terminal window
# Examples that call an LLM read OPENAI_API_KEY (and optionally OPENAI_BASE_URL,
# DEFAULT_EXAMPLES_MODEL); the Makefile targets also load a .env file
export OPENAI_API_KEY="sk-or-v1-..."
# Run one example
PYTHONPATH=$(pwd) uv run python examples/orchestration/basic_chain_example.py
# Or run them all
make examples

Examples 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.

ExampleShows
basic_chainCore chain, dependencies, serialization.
parallel_branchesDAG parallelism across independent steps.
conditionsConditional branching.
loop_untilLoop-back until a condition holds.
map_stepBounded fan-out over a JSON array (no API key).
command_steps · command_plan_capabilities · command_llm_contextArgv commands under a host CommandPolicy; typed capability planning.
shell_session_artifactsOne shell process with portable artifacts.
execution_modes_mock / pipelineFAST vs SELF_CRITIC.
ExampleShows
tool_stepsTool steps, memory, mixed chains.
structured_outputSchema-constrained JSON output.
ExampleShows
supervisor_routingLLM routing to specialists.
llm_councilN-sample voting.
human_in_the_loopPause for human input.
chain_as_toolA chain embedded as an isolated tool (no API key).
code_stepStrict generated-Python step; needs a sandbox image (CARL_CODE_IMAGE) to execute.
agent_skillAgentSkill execution.

The Claude Code and Codex steps have their own pages with examples: Claude Code step, Codex step.

ExampleShows
metricsCustom + built-in metrics (no API key).
dataset_evaluatorBatch evaluation + report.
reflection / reflection_metricsReflection, metric-fed reflection.
ExampleShows
deterministic · llm_checker · voting · checkpoint_rollback · budget_guardThe RE-PLAN strategies.
ExampleShows
chain_from_descriptionGenerate a chain from NL.
skill_resolverURI-based skill resolution.
openrouter · token_usageOpenRouter, token accounting.

See the end-to-end tutorial — a multi-step agent built from scratch, combining LLM, tool, memory, and conditional steps.