Skip to main content

ReplayAI Python SDK — record, replay, and debug AI agent executions. Instrument agents with a single decorator, scrub timelines, diff runs, export regression tests.

Project description

replayai — Python SDK

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

  • Stdlib onlypip install replayai-sdk brings no dependencies.
  • 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: CLI not found after install?

On Windows, pip installs the replayai CLI to %APPDATA%\Python\Python3XX\Scripts\ which may not be on your PATH. Fix it by adding that directory to your PATH:

# Add to PATH for the current session:
$env:PATH += ";$env:APPDATA\Python\Scripts"

# Or add permanently:
[Environment]::SetEnvironmentVariable("PATH", $env:PATH + ";$env:APPDATA\Python\Scripts", "User")

# Then verify:
replayai --help

Alternatively, invoke the CLI via python -m:

python -m replayai.cli --help
python -m replayai.cli record agent.py --project my-project
python -m replayai.cli test tests/replay/
python -m replayai.cli ui --port 3000

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.")

Open the dashboard — your run is there with a full timeline.

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_API_URL http://localhost:3000 Cloud API 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

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")

# Register mocks with flexible matching:
replay.mock("issue_refund", '{"refund_id":"ref_3391"}')
replay.mock("search_web", response, is_prefix=True)  # prefix match
replay.mock(r"search_web\(.*\)", response, is_regex=True)  # regex match
replay.mock("tool", response, input_contains="NYC")  # input-contains match

# load() fetches the recorded session (does NOT re-execute agent code)
trace_obj = replay.load()
print(trace_obj.step_count, trace_obj.status)

# compare() runs your agent function with mocks applied, then diffs vs loaded session
result = replay.compare(my_agent_fn, inputs="user message")
print(result.matches, result.divergences)

# run() is deprecated — use load() instead
# trace_obj = replay.run(agent="...", framework="...")  # ← deprecated

# Export as pytest or jest test
print(replay.export(lang="pytest"))

CLI

# Record a script
replayai record agent.py --project my-project --tags prod

# Run replay regression tests
replayai test tests/replay/ --tb=short

# Start the dashboard (no token required for local dev)
replayai ui --port 3000

Windows: CLI not on PATH?

# Use python -m as a fallback (no PATH needed)
python -m replayai ui --port 3000
python -m replayai record agent.py --project my-project

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.

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.5.4.tar.gz (35.5 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.5.4-py3-none-any.whl (38.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for replayai_sdk-0.5.4.tar.gz
Algorithm Hash digest
SHA256 9aadb82e51d4b6f048ba5c740f9e3caf94abcba69b27e21a5bfa7080c69ce130
MD5 12ca5bda2e35d6a93f1612c795f4e63a
BLAKE2b-256 c7154681523664c71d2e5b2f04e07b921b5650af53cdd3298bbc238bfc8a5a19

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for replayai_sdk-0.5.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f13ca6c973831bd966bd287227cedc80859c4f902fc2a20cd48ca91685e02892
MD5 5502994b896a3ad3615e336fe34412ff
BLAKE2b-256 6b9037b5821fe04e4c108b9027072ca6499577dcabd9b7ea3aed0b272af4f3e2

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