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

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_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.6.1.tar.gz (32.0 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.6.1-py3-none-any.whl (35.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: replayai_sdk-0.6.1.tar.gz
  • Upload date:
  • Size: 32.0 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.6.1.tar.gz
Algorithm Hash digest
SHA256 c876cd9abf68c0f877f484bc50b1bbaf95417d1ed07c799c5fc6c489b10bcdbf
MD5 9de3ec19bde47a68e63b5a9b2ed6a68e
BLAKE2b-256 1d3d831735f14a7b61d61dacb87b35cbd2eb1c48b7a90cfdf6ec2daf029c39bf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: replayai_sdk-0.6.1-py3-none-any.whl
  • Upload date:
  • Size: 35.6 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.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e6b78643726577b31d911f25b8d3ba5832c91f8d0c81e26d3f0f1505a498664a
MD5 72220a84050a7f2ca9e9aa4a2cd73223
BLAKE2b-256 25ad3f88bc5effbc8d542b66d68c2e9684692d088c4036ce07d8638508e1e3a0

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