Skip to main content

Framework-agnostic compensation/rollback library for ReAct agents

Project description

react-agent-compensation

A framework-agnostic compensation/rollback library for ReAct agents.

Features

  • Framework-agnostic Core: Works with any agent framework
  • LangChain Adaptor: First-class LangChain/LangGraph integration
  • Compensation Patterns: Automatic rollback on failures
  • Retry Strategies: Exponential backoff with jitter
  • Dependency Tracking: Topological sort for correct rollback order
  • MCP Integration: Auto-discover compensation pairs from tool schemas

Installation

pip install react-agent-compensation

With LangChain support:

pip install react-agent-compensation[langchain]

With LLM-based extraction:

pip install react-agent-compensation[llm]

Quick Start

from react_agent_compensation.langchain_adaptor import create_compensated_agent

agent = create_compensated_agent(
    model="gpt-4",
    tools=[book_flight, cancel_flight],
    compensation_mapping={"book_flight": "cancel_flight"},
)

result = agent.invoke({"messages": [("user", "Book me a flight to NYC")]})

Core Components

RecoveryManager

The brain of the compensation system:

from react_agent_compensation.core import RecoveryManager

manager = RecoveryManager(
    compensation_pairs={"book_flight": "cancel_flight"},
    alternative_map={"book_flight": ["book_flight_backup"]},
)

# Record before execution
record = manager.record_action("book_flight", {"dest": "NYC"})

# Mark complete on success
manager.mark_completed(record.id, result={"booking_id": "123"})

# Rollback on failure
manager.rollback()

Extraction Strategies

Multiple strategies for extracting compensation parameters:

  • State Mappers: Custom lambda functions
  • Schema-based: Declarative path mappings
  • Heuristic: Auto-detect common ID fields
  • LLM-based: Use LLM for complex extraction

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

react_agent_compensation-0.1.0.tar.gz (80.3 kB view details)

Uploaded Source

Built Distribution

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

react_agent_compensation-0.1.0-py3-none-any.whl (71.1 kB view details)

Uploaded Python 3

File details

Details for the file react_agent_compensation-0.1.0.tar.gz.

File metadata

  • Download URL: react_agent_compensation-0.1.0.tar.gz
  • Upload date:
  • Size: 80.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for react_agent_compensation-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8da9eb580def9abf094995fbec513bf108c8a46a966ea346fdddf8f5583f8975
MD5 1a781e5e3aebda81366c87212890dfc7
BLAKE2b-256 4f0f32f4af32b8d3acaebcc0b52e96ab1d8dccb3badc93b99804d1d49d228305

See more details on using hashes here.

File details

Details for the file react_agent_compensation-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for react_agent_compensation-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e4bb9030e15ce45ac5668565893d7eaee7d25e5542a1fd53287f99838e72275a
MD5 69fcce9975e789814f0fb167b95976ad
BLAKE2b-256 a1ec7dfdb2cb97ae8cec8d0a98b4902e8351093beab2f05a2f7b1c087154bb4e

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