# agentops

> MCP Server

AI Agent monitoring & cost tracking SDK. Benchmarking, LLM integration (Langchain, OpenAI, CrewAI & more). AgentOps.

## Overview

- **Category:** AI
- **Language:** Python
- **Stars:** 5781
- **Forks:** 427
- **Owner:** AgentOps-AI
- **GitHub:** https://github.com/AgentOps-AI/agentops
- **Homepage:** https://agentops.ai
- **Created:** 2023-08-15T23:26:23+00:00
- **Updated:** 2025-07-07T09:57:53+00:00
- **Source:** https://model-context-protocol.com/servers/agentops

## Setup

## Setup

### Installation

```bash
pip install agentops
```

### Prerequisites

*   Python 3.7+

### Configuration

1.  **Get an API Key:** Sign up for an AgentOps account and create a project to obtain your API key. You can find your API key in the [AgentOps dashboard](https://app.agentops.ai/settings/projects).

### Quick Start

1.  **Initialize AgentOps:** Add the following code to the beginning of your Python script (e.g., `main.py`, `__init__.py`), replacing `<INSERT YOUR API KEY HERE>` with your actual AgentOps API key:

    ```python
    import agentops

    # Beginning of your program
    agentops.init("<INSERT YOUR API KEY HERE>")

    # Your agent code here
    ```

2.  **End the Session:** Add the following code to the end of your Python script to properly close the AgentOps session:

    ```python
    # End of program
    agentops.end_session('Success')
    ```

### Environment Variables (Optional)

Some integrations, like CrewAI and AG2, rely on the `AGENTOPS_API_KEY` environment variable.  You can set this instead of passing the API key directly to `agentops.init()`.

```bash
export AGENTOPS_API_KEY="YOUR_API_KEY"
```

Alternatively, you can set it in your `.env` file:

```
AGENTOPS_API_KEY="YOUR_API_KEY"
```

Then load the environment variables in your Python code:

```python
import os
import agentops
from dotenv import load_dotenv

load_dotenv()  # Load environment variables from .env file

agentops.init(os.getenv("AGENTOPS_API_KEY"))

# Your agent code here
```

## Tools

## Available Tools

AgentOps provides a comprehensive suite of tools and features for building, evaluating, and monitoring AI agents, from prototype to production. These include:

*   **Replay Analytics and Debugging:** Provides step-by-step agent execution graphs for in-depth analysis and debugging.
*   **LLM Cost Management:** Tracks spending with LLM foundation model providers to help manage and optimize costs.
*   **Agent Benchmarking:** Allows testing agents against 1,000+ evaluations to ensure performance and reliability.
*   **Compliance and Security:** Detects common prompt injection and data exfiltration exploits to ensure agent security.
*   **Framework Integrations:** Offers native integrations with popular frameworks like CrewAI, AG2 (AutoGen), Camel AI, LangChain, OpenAI Agents SDK, LlamaIndex, Cohere, Anthropic, Mistral, LiteLLM, Llama Stack and SwarmZero AI.

**Key Features & Usage:**

*   **Comprehensive Observability:** Track agent performance, user interactions, and API usage.
*   **Real-Time Monitoring:** Gain instant insights with session replays, metrics, and live monitoring tools.
*   **Cost Control:** Monitor and manage spending on LLM and API calls.
*   **Failure Detection:** Quickly identify and respond to agent failures and multi-agent interaction issues.
*   **Tool Usage Statistics:** Understand how agents utilize external tools with detailed analytics.
*   **Session-Wide Metrics:** Gain a holistic view of agent sessions with comprehensive statistics.

**Quick Start (Session Replays):**

```python
import agentops

# Beginning of your program (i.e. main.py, __init__.py)
agentops.init( < INSERT YOUR API KEY HERE >)

...

# End of program
agentops.end_session('Success')
```

**Developer Experience (Decorators):**

```python
# Create a session span (root for all other spans)
from agentops.sdk.decorators import session

@session
def my_workflow():
    # Your session code here
    return result
```

```python
# Create an agent span for tracking agent operations
from agentops.sdk.decorators import agent

@agent
class MyAgent:
    def __init__(self, name):
        self.name = name
        
    # Agent methods here
```

```python
# Create operation/task spans for tracking specific operations
from agentops.sdk.decorators import operation, task

@operation  # or @task
def process_data(data):
    # Process the data
    return result
```

```python
# Create workflow spans for tracking multi-operation workflows
from agentops.sdk.decorators import workflow

@workflow
def my_workflow(data):
    # Workflow implementation
    return result
```

```python
# Nest decorators for proper span hierarchy
from agentops.sdk.decorators import session, agent, operation

@agent
class MyAgent:
    @operation
    def nested_operation(self, message):
        return f"Processed: {message}"
        
    @operation
    def main_operation(self):
        result = self.nested_operation("test message")
        return result

@session
def my_session():
    agent = MyAgent()
    return agent.main_operation()
```

**Integrations:**

AgentOps offers integrations with various frameworks and platforms:

*   **OpenAI Agents SDK:** Build multi-agent systems with tools, handoffs, and guardrails.
*   **CrewAI:** Build Crew agents with observability in just 2 lines of code.
*   **AG2 (AutoGen):** Add full observability and monitoring to AG2 agents.
*   **Camel AI:** Track and analyze CAMEL agents with full observability.
*   **Langchain:** Seamlessly integrate with applications built using Langchain.
*   **Cohere:** First class support for Cohere(>=5.4.0).
*   **Anthropic:** Track agents built with the Anthropic Python SDK (>=0.32.0).
*   **Mistral:** Track agents built with the Mistral Python SDK (>=0.32.0).
*   **LiteLLM:** Support for LiteLLM(>=1.3.1), allowing you to call 100+ LLMs using the same Input/Output Format.
*   **LlamaIndex:** Seamlessly integrate with applications built using LlamaIndex.
*   **Llama Stack:** Support for Llama Stack Python Client(>=0.0.53), allowing you to monitor your Agentic applications.
*   **SwarmZero AI:** Track and analyze SwarmZero agents with full observability.

**Example Integrations:**

See the original documentation for integration examples with each framework.
