Catalog PyPI
PACKAGE EXPLORERView in registry

agent-tx

PyPI

Deterministic ACID transaction and rollback engine for AI agents in <1µs

Versions collected1
Direct dependencies0From release 0.1.0
Last observed20 Oct, 23:36 UTC

README

Version 0.1.0 documentation

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)

OperationLatencyComplexity
Transaction Checkpoint (50 messages)830.62 ns$O(1)$ Copy-on-Write
Speculative Fork from Root859.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.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
0.1.07 Sept 20260

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 23:36 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:0efaa48064346f0e090ec78a93124dab68bb12588737d23a6979276c0a12c2ef