Skip to main content

agent-tx ⚡

Deterministic ACID Transaction Engine for Autonomous AI Agents in <1µs
Built in Rust with native Python bindings. Part of the next-generation agent runtime ecosystem.

CI & CD PyPI version License


🎯 The Problem

When production AI agents execute complex multi-step workflows (30+ tool invocations, code generation, external API calls):

  1. Dirty State on Failure: If a tool fails at step 28, external resources (files, database records, webhooks) remain corrupted.
  2. Punishing Token Costs: Standard frameworks abort the run and re-prefill the entire 50k–100k token context from step 1, burning latency and GPU budget.
  3. Slow State Duplication: Cloning deep context arrays in Python takes 15ms–50ms and triggers stop-the-world Garbage Collection.

🚀 The Solution: agent-tx

agent-tx brings classical ACID semantics and Copy-on-Write branching directly into the agent execution loop:

  • Sub-microsecond Checkpoints (~830 ns): Structural persistence (im::Vector) allows instantaneous context branching without copying memory.
  • Saga Pattern Rollback (LIFO): Register compensatory actions for tools and unwind external side effects in reverse order.
  • Durable Write-Ahead Log (WAL): Zero data loss across process crashes with CRC32-verified binary replay.
  • Native Python Ergonomics: Drop-in with tx.transaction(): context managers and @transactional_tool decorators.

📊 Benchmarks (Criterion, Linux x86_64)

Operation Latency Complexity
Transaction Checkpoint (50 messages) 830.62 ns $O(1)$ Copy-on-Write
Speculative Fork from Root 859.18 ns $O(1)$ Pointer clone
Rollback & Compensation Unwind < 2.5 µs $O(k)$ where $k$ = depth

📦 Installation

pip install agent-tx

🛠️ Quickstart

1. Automatic Rollback with Context Manager

from agent_tx import AgentTx

tx = AgentTx()

tx.append("system", "You are a cloud orchestration agent.", 12)
tx.append("user", "Resize cluster node pool.", 15)

try:
    with tx.transaction() as tx_id:
        tx.append("assistant", "Calling scale_nodes(pool='prod', count=10)...", 20)
        
        # Register compensating undo action
        tx.register_undo(lambda: print("-> Compensating: Reverting node pool back to 3"))
        
        # Simulate business failure / validation rejection
        raise RuntimeError("Cloud quota exceeded!")

except RuntimeError:
    print("Execution failed. Context rolled back.")

# Context automatically pruned back to safe state (system + user only)
assert len(tx.export_context()) == 2

2. Durable Recovery via Write-Ahead Log (WAL)

from agent_tx import AgentTx

# Session persists across process restarts
tx = AgentTx.open("agent_session.wal")
tx.append("system", "Mission critical agent", 10)
tx.append("user", "Execute batch job", 12)

# If process dies here, re-opening "agent_session.wal" restores exact state
del tx

recovered_tx = AgentTx.open("agent_session.wal")
assert len(recovered_tx.export_context()) == 2

📄 License

Dual-licensed under MIT or Apache 2.0.

Release files for agent-tx 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for agent-tx 0.1.0
File Size Uploaded
agent_tx-0.1.0.tar.gz 19.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for agent-tx 0.1.0
File Interpreter ABI Platform
agent_tx-0.1.0-cp38-abi3-manylinux_2_34_x86_64.whl CPython 3.8 abi3 Linux glibc 2.34+ x86-64 Details

Total release size: 390.3 kB

Release files / agent_tx-0.1.0.tar.gz

Download URL agent_tx-0.1.0.tar.gz
Size 19.5 kB
Tags Source
SHA-256 checksum
How to use checksums
5f1260e179c37eae2ecfbd5baf7d7810a5bc768f939a0953a96d8890477154a2
BLAKE2b-256 checksum
How to use checksums
daed845c3071217e5905e5046519d7b5e74fd8efe2acc76c91a6e03c9ebde87e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / agent_tx-0.1.0-cp38-abi3-manylinux_2_34_x86_64.whl

Download URL agent_tx-0.1.0-cp38-abi3-manylinux_2_34_x86_64.whl
Size 370.9 kB
Tags CPython 3.8 Linux glibc 2.34+ x86-64 abi3
SHA-256 checksum
How to use checksums
1d2bbc7c4f1c1362a459a12e29a35afeea7c294668b9c102befee76c31256ab6
BLAKE2b-256 checksum
How to use checksums
959b619d18b15573276776c4f79878263ddf71f2014240951628ac55049e35b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page