A simple decorator for tracking and reverting agent actions
Project description
Agent Revert
A lightweight package to govern and track agent actions. It allows you to register agents, track their actions via decorators, and monitor affected applications.
- PyPI Package: agent-revert
- Companion Gateway: gateagent
Installation
pip install agent-revert
Usage
Basic Usage
- Register your agent with the gateway.
- Decorate your functions with
@track_actionto monitor execution and affected apps.
from agent_revert import register_agent, track_action
# Register the agent
register_agent("MyAwesomeAgent")
@track_action(agent_name="MyAwesomeAgent", affected_apps=["Database"])
def my_function():
# Do something
pass
LangChain Example
Here is an example of how to integrate agent-revert with a basic LangChain agent that fetches weather data and updates a Google Document.
Prerequisites:
import os
from langchain.agents import initialize_agent, Tool, AgentType
from langchain.llms import OpenAI
from agent_revert import register_agent, track_action
# Ensure you have OPENAI_API_KEY set
# os.environ["OPENAI_API_KEY"] = "..."
# 1. Register the Agent
AGENT_NAME = "DailyReporter"
register_agent(AGENT_NAME)
# 2. Define Tools with Tracking
@track_action(agent_name=AGENT_NAME, affected_apps=["Weather API"])
def get_weather(location: str) -> str:
"""Mock weather function."""
# In a real app, call a weather API here
return f"The weather in {location} is Sunny, 25°C."
@track_action(agent_name=AGENT_NAME, affected_apps=["Google Docs"])
def update_google_doc(text: str) -> str:
"""Mock Google Doc update."""
# In a real app, use Google Docs API here
# See: https://developers.google.com/docs/api/quickstart/python
print(f"Updating Google Doc with: {text}")
return "Document updated successfully."
tools = [
Tool(
name="GetWeather",
func=get_weather,
description="Useful for getting the weather for a specific location."
),
Tool(
name="UpdateGoogleDoc",
func=update_google_doc,
description="Useful for updating the daily report Google Document."
)
]
# 3. Initialize LangChain Agent
llm = OpenAI(temperature=0)
agent = initialize_agent(
tools,
llm,
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
verbose=True
)
# 4. Run the Agent
query = "Check the weather in San Francisco and update the daily report document with the forecast."
agent.run(query)
Features
- Agent Registration: Keep track of all active agents in your system.
- Action Tracking: Monitor start/end times and success/failure of agent actions.
- Affected Apps: Explicitly declare which external applications (e.g., Google Docs, Jira, Salesforce) are modified by an action.
- Gateway Integration: Sends events to a local or remote gateway for visualization.
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 agent_revert-0.1.5.tar.gz.
File metadata
- Download URL: agent_revert-0.1.5.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
165b3b5c78ac319b6fa0ba6e9dd71cf5d5146d04c9c29a2f6fc8ffdb7d0aff59
|
|
| MD5 |
2c28e0b4eeb554b91e612d97591ad07a
|
|
| BLAKE2b-256 |
7efa970762a95799d982aba5eb85b6f3f711978c28b0cfc67e5c3bd1682f5d66
|
File details
Details for the file agent_revert-0.1.5-py3-none-any.whl.
File metadata
- Download URL: agent_revert-0.1.5-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88714cf004c933762062ecb77584ccb7ec9a4068e91d8228c0557d830180e78b
|
|
| MD5 |
0568b4c282c372b8d40ac2383557e440
|
|
| BLAKE2b-256 |
f0842a4f5825258b55bc5836dcfbb9c5d5a458fca35d77d35387bf318d5cbb0b
|