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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8da9eb580def9abf094995fbec513bf108c8a46a966ea346fdddf8f5583f8975
|
|
| MD5 |
1a781e5e3aebda81366c87212890dfc7
|
|
| BLAKE2b-256 |
4f0f32f4af32b8d3acaebcc0b52e96ab1d8dccb3badc93b99804d1d49d228305
|
File details
Details for the file react_agent_compensation-0.1.0-py3-none-any.whl.
File metadata
- Download URL: react_agent_compensation-0.1.0-py3-none-any.whl
- Upload date:
- Size: 71.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e4bb9030e15ce45ac5668565893d7eaee7d25e5542a1fd53287f99838e72275a
|
|
| MD5 |
69fcce9975e789814f0fb167b95976ad
|
|
| BLAKE2b-256 |
a1ec7dfdb2cb97ae8cec8d0a98b4902e8351093beab2f05a2f7b1c087154bb4e
|