Skip to main content

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 retrace.yashbogam.me/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

Sampling

retrace.configure(api_key="rt_live_...", sample_rate=0.1)  # Record 10% of traces

Changelog

0.3.0

  • Sessionssession_id parameter in TraceRecorder to group multi-turn conversations
  • Multi-Agentagent_id field on Span for 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_ids and logprobs fields for speculative decoding during replay
  • Serializationto_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 replayresumable=True registers 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_rate config
  • Auto-instrumentation for OpenAI, Anthropic, Gemini
  • WebSocket transport with auto-reconnect

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

retrace_sdk-0.11.7.tar.gz (47.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

retrace_sdk-0.11.7-py3-none-any.whl (51.5 kB view details)

Uploaded Python 3

File details

Details for the file retrace_sdk-0.11.7.tar.gz.

File metadata

  • Download URL: retrace_sdk-0.11.7.tar.gz
  • Upload date:
  • Size: 47.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for retrace_sdk-0.11.7.tar.gz
Algorithm Hash digest
SHA256 216cb49413816aefde8307434c1ce976178a441bf925f14cfd78dcab3ea0f51d
MD5 479f956a0eaa6cf4848b0ee3a0def0c9
BLAKE2b-256 81a9dad2964ff102d2c89f2426c3f54e0a0e9c34811c998ddcaa7ea826c1cfee

See more details on using hashes here.

File details

Details for the file retrace_sdk-0.11.7-py3-none-any.whl.

File metadata

  • Download URL: retrace_sdk-0.11.7-py3-none-any.whl
  • Upload date:
  • Size: 51.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for retrace_sdk-0.11.7-py3-none-any.whl
Algorithm Hash digest
SHA256 ef27cd44afa1ddfc2b85be79b918f6a9a9f93574cfbadb075224bbb348937ed3
MD5 a0fa6061b6b178114c36a9254a3794d6
BLAKE2b-256 29d5b7536621287293c33197f6fc425ebe4456250b1c81ef555e2a88a4caa7ee

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page