Skip to main content

Python SDK for ReplayAI — instrument agents, record sessions, replay in the dashboard.

Project description

replayai — Python SDK

PyPI version License: MIT

Instrument Python agents, record every step (LLM calls, tool calls, retrievals, errors), and view sessions in the built-in dashboard where you can replay them, diff runs, and export tests.

  • Stdlib onlypip install replayai-sdk brings no dependencies.
  • Built-in dashboardreplayai ui launches a self-contained dashboard server. No external app or database required.
  • Decorator + context manager@trace(...) or with trace(...) as ctx:.
  • Framework extraspip install "replayai-sdk[langchain]" for auto-instrumentation.

Install

pip install replayai-sdk
# or, with the LangChain integration:
pip install "replayai-sdk[langchain]"

Windows note: If you see a warning like "The script replayai.exe is installed in … which is not on PATH", either add that directory to your PATH or use python -m replayai instead — it works identically:

python -m replayai ui          # same as: replayai ui
python -m replayai record agent.py

30-second usage

from replayai import trace, record_step

@trace("support-agent-v3", project="support-agent", tags=["production"])
def handle_support_ticket(message: str) -> str:
    record_step(
        type="llm_call", name="classify_intent",
        model="gpt-4o-mini", tokens_in=312, tokens_out=24,
        input=f"User: {message}", output="intent: billing_dispute",
        status="success",
    )
    record_step(
        type="tool_call", name="issue_refund",
        input='{"charge_id":"ch_002"}',
        output='{"refund_id":"ref_3391"}',
        status="success",
    )
    return "Refund issued (ref_3391)."

handle_support_ticket("I was charged twice, refund me.")

Launching the dashboard

The SDK ships with a self-contained dashboard server. Record sessions locally, then launch the UI to view them:

# 1. Record a session (stored locally by default when REPLAYAI_STORAGE=local)
REPLAYAI_STORAGE=local replayai record my_agent.py

# 2. Launch the dashboard
replayai ui
# → opens http://localhost:7373 in your browser
# → shows all locally-recorded sessions with full step timelines

Options:

Flag Default Description
--port 7373 Port to listen on
--storage ./replays Local storage path
--no-browser Don't auto-open the browser

The dashboard reads sessions from {storage}/sessions/*.json and serves:

  • GET / — single-page dashboard UI (stats, sessions list, step timeline)
  • GET /api/sessions — JSON session list
  • GET /api/sessions/:id — JSON single session with steps
  • GET /api/stats — JSON aggregate stats

CLI commands

replayai record <script.py> [--project <slug>] [--tags a,b]   # Run a script under a trace
replayai test [tests/replay/] [--live-llm]                    # Run replay regression tests
replayai ui [--port 7373] [--storage ./replays]               # Launch the dashboard
replayai --version                                            # Print version

Configuration

Environment variables (all optional):

Variable Default Description
REPLAYAI_PROJECT Default project slug/id
REPLAYAI_TOKEN Cloud API token
REPLAYAI_STORAGE cloud cloud, local, or both
REPLAYAI_STORAGE_PATH ./replays Local storage directory (used when storage includes local)
REPLAYAI_API_URL http://localhost:3000 Cloud API base URL
REPLAYAI_DASHBOARD_URL http://localhost:3000 Dashboard base URL
REPLAYAI_SAMPLE_RATE 1.0 Fraction of sessions to record
REPLAYAI_STRICT false Raise on recording failures
REPLAYAI_REDACT_PATTERNS built-in set Comma-separated regexes
REPLAYAI_REDACT_STRICT true Set false to disable entropy-based secret detection
REPLAYAI_TIMEOUT 30 Per-request HTTP timeout (seconds)
REPLAYAI_MAX_STEPS 200 Hard ceiling on steps persisted per session

Programmatic override:

import replayai
replayai.configure(project="support-agent", api_url="http://localhost:3000")
replayai.strict_mode = True  # opt into hard failures

Async

import asyncio
from replayai import atrace, arecord_step

@atrace("async-agent")
async def handle(message: str) -> str:
    await arecord_step(type="llm_call", name="classify", status="success")
    return "ok"

asyncio.run(handle("hello"))

Replay & export

from replayai import ReplaySession

replay = ReplaySession("ses_8fa1")
replay.mock("issue_refund", '{"refund_id":"ref_3391"}')
with replay.trace() as trace_obj:
    replay.run(agent="support-agent-v3", framework="LangChain")
print(trace_obj.step_count, trace_obj.status)
print(replay.export(lang="pytest"))

LangChain integration

from replayai.integrations.langchain import trace_agent, ReplayCallbackHandler

@trace_agent("support-agent-v3", project="support-agent", tags=["production"])
def handle(message: str) -> str:
    return executor.invoke({"input": message})["output"]

See examples/quickstart.py and examples/langchain_demo.py for runnable demos.

License

MIT — see LICENSE.

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

replayai_sdk-0.7.0.tar.gz (41.6 kB view details)

Uploaded Source

Built Distribution

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

replayai_sdk-0.7.0-py3-none-any.whl (45.3 kB view details)

Uploaded Python 3

File details

Details for the file replayai_sdk-0.7.0.tar.gz.

File metadata

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

File hashes

Hashes for replayai_sdk-0.7.0.tar.gz
Algorithm Hash digest
SHA256 6da9542ec94fd1e19f15d4f91cae039d41a5e5ffa950ee6d17c1da73fdff0b9e
MD5 8ac62716299b9c9b4ba6a204d0a3648b
BLAKE2b-256 037bb07271471443d6c7c84ece6d7ee5a75b7184172d1beceb1437546bff4f64

See more details on using hashes here.

File details

Details for the file replayai_sdk-0.7.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for replayai_sdk-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8fc25a2ef5db5ee085be2dacd67dbd42c2ef326c723bc28dda032c697fc04d17
MD5 04320a88483c2fb085b44599c87688a0
BLAKE2b-256 d9231ada4456d7ee9444de4c5a18232a16b4fb466f42085542404cf3fcae8d21

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