Skip to main content

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.

Installation

pip install agent-revert

Usage

Basic Usage

  1. Register your agent with the gateway.
  2. Decorate your functions with @track_action to 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

agent_revert-0.1.4.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

agent_revert-0.1.4-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file agent_revert-0.1.4.tar.gz.

File metadata

  • Download URL: agent_revert-0.1.4.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

Hashes for agent_revert-0.1.4.tar.gz
Algorithm Hash digest
SHA256 7f0804ff46dca015d4e2d3fbf185bfdb8f394adc615d5c0c2eb7f68014e8c9de
MD5 02d9057719005cf1b575bb0f31a473e6
BLAKE2b-256 97fd5dc76af1474bd55fd03f749ba84dc5ba0402acaabbdb65c6ccc17330338b

See more details on using hashes here.

File details

Details for the file agent_revert-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: agent_revert-0.1.4-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

Hashes for agent_revert-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f6e4e1a9603cb1d0ef1809c89aa6da56d40f6a7394b53ee5c7499af989be035d
MD5 c5135d466e90c5046ad47ef480404410
BLAKE2b-256 2317d35b11b68df78f911ba2ea334991a74b65814c92512f384d72f67727a802

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