Examples
Annotated walkthroughs and example scripts.
Examples
All examples are in the examples/ directory.
# Run with local transport (no runtime needed)
python examples/basic_agent.py --local
# Run with HTTP transport
python examples/basic_agent.pybasic_agent.py
Demonstrates the core decorator API: @run, @step, @checkpoint.
from multirun import run, step, checkpoint
from multirun.models import Budget
@step(retry=3, retry_delay=0.1)
async def fetch_data(source: str) -> dict:
"""Step with automatic retry on transient errors."""
return {"source": source, "items": ["a", "b", "c"]}
@step
async def process_data(data: dict) -> list[str]:
"""Simple step — errors propagate immediately."""
return [item.upper() for item in data["items"]]
@checkpoint(name="after_analysis")
async def analyze_results(processed: list[str]) -> dict:
"""Creates a durable checkpoint after completion."""
return {"count": len(processed), "first": processed[0]}
@run(
name="basic_agent",
budget=Budget(max_tokens=10000, max_cost_usd=0.10, max_steps=20),
checkpoint_on_error=True,
)
async def basic_agent(source: str) -> dict:
data = await fetch_data(source)
processed = await process_data(data)
analysis = await analyze_results(processed)
return {"source": source, "analysis": analysis}Key takeaways:
@step(retry=3)retries with exponential backoff on failure@checkpointsaves state so later failures can resume from here@run(budget=...)enforces token/cost/step limitscheckpoint_on_error=Truesaves state when the run fails
langgraph_research.py
LangGraph workflow with MultiRun step tracking and checkpoints. See LangGraph adapter.
replay_demo.py
Demonstrates checkpoint creation and replay from a saved checkpoint. See Context — Checkpoint & Replay.