// python sdk

Python SDK

Add observability, fork & replay, and runtime safety to any Python agent with one decorator and a small, dependency-light package (Python 3.10+).

Start freeRead the docs →

One decorator

Decorate your agent function with @retrace.record and the whole run is captured — there's no manual instrumentation to write.

Automatic capture

Calls to the major model providers are recorded for you, including prompts, responses, token usage, and cost.

Replay-ready

Mark a run resumable=True to unlock cascade fork & replay from the dashboard later.

Multi-agent tagging

Scope spans to an agent with retrace.agent(id, role=...) so multi-agent runs build a topology graph.

Safe by default

Privacy redaction is on, an offline buffer flushes on reconnect, and typed errors — auth, credits, rate-limit, enforcement — never crash your agent.

Built-in enforcement & cassettes

Local per-run ceilings raise a typed RetraceEnforcementError instead of overspending, and write_golden_cassette records a run as a CI fixture.

shell
pip install retrace-sdk

Install from PyPI.

agent.py
import retrace

retrace.configure(api_key="rt_...")

@retrace.record(name="support-agent", resumable=True)
def run_agent(prompt: str) -> str:
    return agent.invoke(prompt)

Configure once, then record any function with a decorator.

multi_agent.py
with retrace.agent("researcher", role="research"):
    findings = research_agent.run(task)

with retrace.agent("writer", role="writer", parent="researcher"):
    draft = writer_agent.run(findings)

Tag each agent's work to build the topology graph.

More for developers