> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agentsentinel.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Replay

> Mock tool calls with recorded outputs to debug and reduce cost.

Replay lets you run agent logic without re-calling external systems by returning **recorded outputs** for instrumented actions.

## Use replay mode

```python theme={null}
from agent_sentinel import replay_mode, guarded_action

@guarded_action(name="fetch_data", cost_usd=0.01)
def fetch_data(url: str) -> dict:
    return {"url": url, "data": "..."}

# First run: records to ledger
fetch_data("https://example.com")

# Later: replay from ledger
with replay_mode(ledger_path=None, strict=True):
    fetch_data("https://example.com")  # returns recorded output
```

## Divergence detection

In strict mode, replay raises `ReplayDivergenceError` when inputs don’t match what was recorded.

## Per-run replay (`ReplayMode.from_run_id`)

SDK 0.2.0 stamps a `run_id` onto every ledger entry (sourced from the active `ExecutionContext`). `ReplayMode.from_run_id("…")` filters a shared ledger file down to a single run before replaying — useful when one ledger file contains many runs.

```python theme={null}
from agent_sentinel import ReplayMode

with ReplayMode.from_run_id("run-2026-04-18-abc"):
    fetch_data("https://example.com")  # replays only entries from this run
```

If you'd rather not share ledgers across runs at all, set a different `AGENT_SENTINEL_HOME` per run so each run gets its own ledger file.
