Skip to main content

Framework-agnostic transactional agent runtime with idempotent tool calls, saga compensations, and deterministic replay.

Project description

AgentRelay

AgentRelay is a framework-agnostic, transactional runtime for AI agents and tool-based workflows.

It gives you:

  • Tool-call idempotency – prevent duplicate side effects (emails, payments, DB writes) even when your code retries.
  • Saga-style compensations – register compensating tools that run automatically on failure to roll back partial work.
  • Deterministic replay – re-run an agent workflow using recorded tool outputs instead of calling external systems again.
  • Framework-agnostic SDK – plug into any LLM / agent stack (OpenAI, Gemini, your own code) using a small Python SDK.
  • SQL-backed durability – store runs and tool calls in Postgres, MySQL, or SQLite with a simple schema.
  • LLM cost and token tracking – capture prompt/completion token usage and budget caps with helper wrappers.

AgentRelay is designed for “production-style” agent workflows in domains like fintech, healthcare, and operations, where you care about not double-charging users, not sending emails twice, and being able to debug and audit what an agent actually did.


Documentation


Features

  • Idempotent tool calls

    • Each tool invocation is assigned a deterministic idempotency key based on tool name, phase, and arguments.
    • A unique index at the DB layer enforces “do not run the same tool call twice for a given run”.
    • If the same call is retried, AgentRelay returns the previously persisted output instead of re-invoking the tool.
  • Saga-style compensations

    • Tools can register a corresponding “compensation” tool.
    • On failure, AgentRelay walks executed steps in reverse order and triggers compensation calls.
    • Best-effort reversals: compensation failures are logged but do not crash the process again.
  • Deterministic replay

    • You can replay a past run by opening a session in replay mode.
    • Forward-phase tool calls are served from the tool_calls table instead of calling external APIs or LLMs again.
    • This makes debugging and auditing easier and avoids re-running side effects.
  • Framework-agnostic

    • AgentRelay does not depend on any specific LLM or agent framework.
    • You bring your own agent code and LLM client (OpenAI, Gemini, etc.).
    • AgentRelay just wraps tool calls and persists the workflow state.
  • LLM usage tracking

    • Wrap LLM calls to store provider, model, token counts, and costs.
    • Enforce a per-run budget limit that raises a BudgetExceededError before spend grows unbounded.

Installation

Once published to PyPI:

pip install agentrelay

Quickstart

from agent_relay.runtime import AgentRuntime
from agent_relay.tooling import tool

runtime = AgentRuntime.from_env()

@tool(runtime, name="charge_card", compensation="refund_card")
def charge_card(amount_cents: int, card_id: str) -> str:
    # call your payment provider
    return "payment-id-123"

@tool(runtime, name="refund_card")
def refund_card(amount_cents: int, card_id: str) -> None:
    # undo the charge
    return None


def billing_agent(event: dict) -> dict:
    payment_id = charge_card(amount_cents=event["amount_cents"], card_id=event["card_id"])
    return {"payment_id": payment_id}


with runtime.agent_session(name="billing", input_payload={"amount_cents": 2500, "card_id": "card-1"}) as session:
    result = billing_agent({"amount_cents": 2500, "card_id": "card-1"})
    session.set_output(result)

Database setup

AgentRelay will connect to the database specified in AGENTTRAIL_DB_URL, AGENTTRAIL_DATABASE_URL, or DATABASE_URL. If none are set, it defaults to a local SQLite file (./agenttrail.db).

You can also build connection strings manually:

from agent_relay.db import sqlite_connection_string, mysql_connection_string

sqlite_url = sqlite_connection_string("./agenttrail.db")
mysql_url = mysql_connection_string(user="agenttrail", password="agenttrail", host="localhost", database="agenttrail")

Budget limits

with runtime.agent_session(
    name="support_agent",
    budget_limit=2.00,
    compensate_on_budget_exceeded=False,
) as session:
    ...

LLM wrappers

from agent_relay.llm import wrap_openai_call

response = wrap_openai_call(
    model="gpt-4o-mini",
    input_cost_per_1k=0.15,
    output_cost_per_1k=0.60,
    request_payload={"messages": [{"role": "user", "content": "Hello"}]},
    call=lambda: client.responses.create(model="gpt-4o-mini", input="Hello"),
)

Replay and exports

exported = runtime.export_run(run_id)
replayed = runtime.replay_exported_json(exported, billing_agent, {"amount_cents": 2500, "card_id": "card-1"})

Demos

The demo/agent.py script shows saga compensation, idempotency, and replay patterns.


Cloud version

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

agentrelay-0.1.2.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

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

agentrelay-0.1.2-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file agentrelay-0.1.2.tar.gz.

File metadata

  • Download URL: agentrelay-0.1.2.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for agentrelay-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f489886c28d7d0a4e31029a7453206d9c8836d7f283dbd8049cf1a03646468d7
MD5 84262106539b06c0c71dce59eb9c8e36
BLAKE2b-256 c5631b0313b11481f284944063e4c0a5388363d024dfd532868d03a45a1445f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for agentrelay-0.1.2.tar.gz:

Publisher: release.yml on YalmanchiliTejas/agentTrail

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file agentrelay-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: agentrelay-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 15.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for agentrelay-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c5107091b20946b5b646d0d6a78cbc3d4d37f9a22a39659524beb1181046c664
MD5 666b7dc5ebcf77ab88a4cff0842b737d
BLAKE2b-256 98e2a4e7834006fbc67d29e64f0c59b742e891244a04f8834abfea8d786525e6

See more details on using hashes here.

Provenance

The following attestation bundles were made for agentrelay-0.1.2-py3-none-any.whl:

Publisher: release.yml on YalmanchiliTejas/agentTrail

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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