Skip to main content

Monitoring SDK for AI agents built with Google ADK

Project description

AgentOps Monitor SDK

PyPI version Python 3.8+ License: MIT

A lightweight monitoring SDK for AI agents built with Google ADK. Track agent executions, tool calls, and performance metrics in real-time with minimal code changes.

Features

  • 🔍 Agent Monitoring - Automatic tracing of ADK agent executions
  • 🛠️ Tool Tracking - Capture tool calls, inputs, and outputs
  • 📊 Performance Metrics - Track execution time, token usage, and costs
  • 🎯 Custom Tracing - Add custom spans with the @traceable decorator
  • 🔄 Runner Integration - Monitor entire agent workflows
  • 🌐 A2A Support - Optional agent-to-agent communication monitoring
  • 🚀 Zero Config - Works out of the box with environment variables

Installation

pip install agentops-monitor

For agent-to-agent (A2A) monitoring support:

pip install agentops-monitor[a2a]

Quick Start

1. Set Up Environment Variables

Create a .env file in your project root:

AGENTOPS_API_KEY="your-api-key-here"
AGENTOPS_PROJECT_ID="your-project-id"
AGENTOPS_BASE_URL="http://localhost:8000"  # Optional, defaults to production

Getting Your API Key:

  1. Deploy the AgentOps Monitor backend (see Backend Setup)
  2. Register an account via the web interface
  3. Create a project in the dashboard
  4. Generate an API key for your project

2. Monitor Your Agent

from google.adk.agents import Agent
from agentops_monitor import monitor_agent
import os

# Create your agent
agent = Agent(
    name="MyAgent",
    model="gemini-2.5-flash",
    instruction="You are a helpful assistant."
)

# Wrap it with monitoring
api_key = os.getenv("AGENTOPS_API_KEY")
monitored_agent = monitor_agent(agent, api_key)

# Use normally - monitoring happens automatically!
result = monitored_agent.run("What is the weather today?")

3. View Your Traces

Open the AgentOps Monitor dashboard to see:

  • Agent execution traces
  • Tool calls and results
  • Performance metrics
  • Token usage and costs
  • Error tracking

Configuration

Environment Variables

Variable Required Default Description
AGENTOPS_API_KEY Yes - Your API key from the dashboard
AGENTOPS_PROJECT_ID Yes - Project ID from the dashboard
AGENTOPS_BASE_URL No Production URL Backend URL (use http://localhost:8000 for local)

Programmatic Configuration

from agentops_monitor.client import AgentOpsClient

client = AgentOpsClient(
    api_key="your-api-key",
    project_id="your-project-id",
    base_url="http://localhost:8000"
)

Usage Examples

Monitor ADK Agents

from google.adk.agents import Agent
from agentops_monitor import monitor_agent

agent = Agent(name="SearchAgent", model="gemini-2.5-flash")
monitored_agent = monitor_agent(agent, api_key="your-key")

# All agent calls are now traced
response = monitored_agent.run("Search for Python tutorials")

Monitor Runners

from google.adk.runners import Runner
from agentops_monitor import monitor_runner

runner = Runner(app=app, session_service=session_service)
monitored_runner = monitor_runner(runner, api_key="your-key")

# Runner execution is now traced
for event in monitored_runner.run(user_id="user123", session_id="session456", new_message=message):
    print(event)

Wrap Custom Tools

from google.adk.tools import google_search
from agentops_monitor import wrap_tool

# Wrap individual tools to track their usage
wrapped_search = wrap_tool(google_search)

agent = Agent(
    name="SearchAgent",
    tools=[wrapped_search],  # Use wrapped tool
    model="gemini-2.5-flash"
)

Custom Tracing with @traceable

from agentops_monitor import traceable

@traceable(name="data_processing")
def process_data(data):
    # Your custom logic here
    result = transform(data)
    return result

# Function calls are automatically traced
result = process_data(my_data)

Complete Example

from google.adk.agents import Agent
from google.adk.apps import App
from google.adk.runners import Runner
from google.adk.sessions import InMemorySessionService
from google.adk.tools import google_search
from google.genai import types
from agentops_monitor import monitor_agent, monitor_runner, wrap_tool
import os
from dotenv import load_dotenv

load_dotenv()

# Wrap tools
wrapped_search = wrap_tool(google_search)

# Create and monitor agent
agent = Agent(
    name="SearchAgent",
    model="gemini-2.5-flash",
    tools=[wrapped_search],
    instruction="You are a search specialist."
)
agent = monitor_agent(agent, os.getenv("AGENTOPS_API_KEY"))

# Create app and runner
app = App(name="SearchApp", root_agent=agent)
session_service = InMemorySessionService()
runner = Runner(app=app, session_service=session_service)
runner = monitor_runner(runner, os.getenv("AGENTOPS_API_KEY"))

# Run with monitoring
message = types.Content(parts=[types.Part(text="What is AI?")], role="user")
for event in runner.run(user_id="user123", session_id="session456", new_message=message):
    if hasattr(event, "content") and event.content:
        print(event.content)

Backend Setup

The SDK requires a backend server to store and visualize traces. You have two deployment options:

Option 1: Docker (Recommended)

# Clone the repository
git clone https://github.com/yourusername/agentops-monitor.git
cd agentops-monitor

# Start with Docker Compose
docker-compose up -d

This starts:

  • Backend API on http://localhost:8000
  • Frontend dashboard on http://localhost:3000
  • PostgreSQL database

Option 2: Manual Deployment

# Install dependencies
cd backend
pip install -r requirements.txt

# Set up database
export DATABASE_URL="postgresql://user:pass@localhost:5432/agentops"

# Run migrations
alembic upgrade head

# Start server
uvicorn main:app --host 0.0.0.0 --port 8000

See the Backend Documentation for detailed deployment instructions.

Requirements

  • Python 3.8 or higher
  • Google ADK (google-adk>=1.13.0)
  • Active AgentOps Monitor backend instance

API Reference

monitor_agent(agent, api_key, project_id=None, base_url=None)

Wraps an ADK agent with monitoring capabilities.

Parameters:

  • agent (Agent): The ADK agent to monitor
  • api_key (str): Your AgentOps API key
  • project_id (str, optional): Project ID (defaults to env var)
  • base_url (str, optional): Backend URL (defaults to env var)

Returns: Monitored agent instance

monitor_runner(runner, api_key, project_id=None, base_url=None)

Wraps an ADK runner with monitoring capabilities.

Parameters:

  • runner (Runner): The ADK runner to monitor
  • api_key (str): Your AgentOps API key
  • project_id (str, optional): Project ID (defaults to env var)
  • base_url (str, optional): Backend URL (defaults to env var)

Returns: Monitored runner instance

wrap_tool(tool)

Wraps an ADK tool to track its usage.

Parameters:

  • tool: The ADK tool to wrap

Returns: Wrapped tool instance

@traceable(name=None, **kwargs)

Decorator for custom function tracing.

Parameters:

  • name (str, optional): Custom span name (defaults to function name)
  • **kwargs: Additional metadata to attach to the trace

Example:

@traceable(name="custom_operation", category="data")
def my_function(x):
    return x * 2

Troubleshooting

"AGENTOPS_API_KEY environment variable is required"

Make sure you've set the API key in your .env file or environment:

export AGENTOPS_API_KEY="your-key-here"

"Connection refused" or network errors

Verify your backend is running and accessible:

curl http://localhost:8000/health

Traces not appearing in dashboard

  1. Check that your API key is valid
  2. Verify the project ID matches your dashboard project
  3. Check backend logs for authentication errors
  4. Ensure AGENTOPS_BASE_URL points to the correct backend

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

Changelog

v0.1.0 (Initial Release)

  • ✨ Agent monitoring for Google ADK
  • ✨ Runner monitoring support
  • ✨ Tool wrapping and tracking
  • ✨ Custom tracing with @traceable decorator
  • ✨ Environment variable configuration
  • ✨ Optional A2A monitoring support
  • 📚 Comprehensive documentation and examples

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

agentops_monitor-0.1.0.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

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

agentops_monitor-0.1.0-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for agentops_monitor-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2e12303924deadc7dfb2e7107a6581296d800e35c057c5cde8925cd646eea77d
MD5 f9bfe4665c3322e6679db210f4e815a0
BLAKE2b-256 b6d56f6d71e8310039ae26fd8b7b707ea74cd2d72ef4fd4a6e4dc5a922fee15a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agentops_monitor-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9d3b028f3588069aeb03635a77eb5d8048ad5c5a9909340b34a9d854c98d0f49
MD5 b55416ca66a264c179f5cee9176487aa
BLAKE2b-256 dc7dc3f3f4da0328cb1a4c74441307eea4e8051d0611ad1412083adcb14ff63c

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