Record, replay, fork & share AI agent executions
Project description
retrace-sdk
The execution replay engine for AI agents. Record every LLM call, tool invocation, and error your AI agent makes. Replay step-by-step. Fork from any point. Share interactive traces via URL.
Install
pip install retrace-sdk
Requires Python 3.10+.
Quick Start
import retrace
retrace.configure(api_key="rt_live_...") # Get your key at retraceai.tech/settings
@retrace.record(name="my-agent")
def run_agent(prompt: str):
response = client.chat.completions.create(
model="gpt-5.5",
messages=[{"role": "user", "content": prompt}]
)
return response.choices[0].message.content
run_agent("What is quantum computing?")
Auto-Instrumentation
Retrace automatically captures LLM calls from all major providers:
# OpenAI — captured automatically
# Anthropic — captured automatically
# Google Gemini — captured automatically
No extra setup needed. Install the provider SDK alongside retrace-sdk and calls are captured.
Features
- Record — One decorator captures every LLM call, tool call, and error
- Replay — Step through executions with play/pause/speed controls
- Fork — Branch from any step, modify input, watch a new path diverge
- Share — Publish traces as shareable "tapes" with interactive playback
- Retrace AI — Built-in evaluations, memory extraction, and semantic search
Resumable Execution (Cascade Replay)
Mark a function as resumable to enable full cascade replay from the dashboard:
@retrace.record(name="my-agent", resumable=True)
def run_agent(prompt: str):
plan = call_planner(prompt)
result = call_executor(plan)
return summarize(result)
When you fork at any span in the dashboard, the SDK re-executes the entire function with modified input — all subsequent LLM calls diverge.
Error Handling
from retrace import RetraceError, RetraceAuthError, RetraceCreditsExhaustedError, RetraceRateLimitError, RetraceEnforcementError
Enforcement (Circuit Breakers)
Hard ceilings that stop a runaway agent before the next call. Local limits are enforced offline (zero network); server_enforcement=True also consults centrally-managed server policies.
import retrace
from retrace import RetraceEnforcementError
retrace.configure(
api_key="rt_live_...",
max_steps_per_run=50,
max_usd_per_run=2.0,
server_enforcement=True, # optional: also consult server policies
)
try:
run_agent("...")
except RetraceEnforcementError as e:
print(e.verdict, e.reason) # e.g. "block", "Local USD ceiling reached: ..."
Precedence: explicit arg > env var (RETRACE_MAX_STEPS_PER_RUN, RETRACE_MAX_TOKENS_PER_RUN, RETRACE_MAX_USD_PER_RUN, RETRACE_SERVER_ENFORCEMENT) > unset. If the server check is unreachable, local limits still apply.
Multi-Agent Context
Tag spans with an agent id/role so the dashboard can draw the agent topology and run inter-agent detectors (ping-pong, reasoning–action mismatch, task derailment):
import retrace
with retrace.agent("planner", role="planner"):
plan = call_planner(prompt)
with retrace.agent("executor", role="executor"):
result = call_executor(plan)
Golden Cassettes (CI Regression Gates)
Record a run as a golden cassette and gate on it offline in CI with retrace ci replay:
from retrace import write_golden_cassette
write_golden_cassette("golden.json", recorder=rec)
Sampling
retrace.configure(api_key="rt_live_...", sample_rate=0.1) # Record 10% of traces
Changelog
0.13.0
-
Multi-agent context —
retrace.agent(id, role=...)context manager tags spans for topology + inter-agent detectors -
Golden cassettes —
write_golden_cassette(path, recorder=...)records a run as a CI regression fixture -
Pre-call enforcement gate — local step/token/USD-per-run ceilings enforced offline;
RetraceEnforcementErrorraised instead of silently skipping the call -
Sessions —
session_idparameter inTraceRecorderto group multi-turn conversations -
Multi-Agent —
agent_idfield onSpanfor cross-agent tracing -
Guardrail support — SDK respects HALT commands from server-side guardrail policies
0.2.2
- Version sync with TypeScript SDK
0.6.0
- Token ID capture — Span dataclass now supports
token_idsandlogprobsfields for speculative decoding during replay - Serialization —
to_dict()includes token_ids/logprobs when present
0.2.1
- Offline buffer — stores up to 1000 messages when WebSocket disconnects, flushes on reconnect
- Dedicated listener thread — receives server 'resume' commands without needing active sends
- Cascade replay —
resumable=Trueregisters function for SDK-level re-execution - Fixed — duplicate except block in transport, proper close() cleanup
0.2.0
- Typed errors (RetraceAuthError, RetraceCreditsExhaustedError, RetraceRateLimitError)
- Trace sampling via
sample_rateconfig - Auto-instrumentation for OpenAI, Anthropic, Gemini
- WebSocket transport with auto-reconnect
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file retrace_sdk-0.13.2.tar.gz.
File metadata
- Download URL: retrace_sdk-0.13.2.tar.gz
- Upload date:
- Size: 143.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e03f13bbf7a1a6e29991754a4f0a9d3e669b0d5e72f84e11b57d0df4d133aa73
|
|
| MD5 |
623b1f52039e222bfed63aa5686de805
|
|
| BLAKE2b-256 |
d080429ef089319f1e7ccf398791b4c0d00928c6f1275118ee63f918dd29d2c9
|
File details
Details for the file retrace_sdk-0.13.2-py3-none-any.whl.
File metadata
- Download URL: retrace_sdk-0.13.2-py3-none-any.whl
- Upload date:
- Size: 56.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce461eecc081c4eed60e7a96b482c1372c7695ff457bda3fdd0f63a9e64301d4
|
|
| MD5 |
91fd81ec90d89faddcb8298da2512238
|
|
| BLAKE2b-256 |
8df51464ffd437a3253d655322c85f7ef701a9172c80c4ecc496c6479f97099f
|