AgentOps
AgentOps is an observability and DevTool platform for AI agents, providing tools to trace, debug, and deploy reliable AI agents and LLM applications. It offers features like session replays, LLM cost tracking, failure detection, tool usage statistics, and benchmarking, helping engineers move AI agents from prototype to production by ensuring they operate safely, efficiently, and transparently.
Warnings
- breaking The AgentOps SDK is in active development (0.x versions), and its API surface, internal architecture, and integration points (e.g., AutoGen to AG2 migration in 0.4.19) can evolve rapidly. This may necessitate updates to your code when upgrading versions.
- gotcha Failing to correctly configure the `AGENTOPS_API_KEY` (either via environment variable or directly in `agentops.init()`) will prevent data from being sent to the AgentOps dashboard. If using a `.env` file, ensure `python-dotenv.load_dotenv()` is called *before* `agentops.init()`.
- gotcha While `agentops.init()` provides automatic instrumentation for many popular LLM and agent frameworks, achieving finer-grained control and tracking custom operations, agents, or tools requires explicit use of decorators like `@agent`, `@operation`, `@trace`, and `@tool` from `agentops.sdk.decorators`. Auto-instrumentation provides a good starting point, but detailed insights often need manual tagging.
- gotcha For comprehensive and accurate trace recording, especially in single-run scripts or when explicit lifecycle management is desired, explicitly calling `agentops.end_session()` is crucial to mark the completion of an agent's run. While `agentops.init()` can auto-start a session, auto-ending might not always capture the full lifecycle details without explicit calls or decorator usage.
- gotcha Deploying AI agents introduces unique operational challenges (e.g., non-deterministic behavior, infinite loops, tool hallucinations, agent drift) that extend beyond traditional software or ML monitoring. AgentOps helps address these with observability, but developers must still design agents with robust guardrails, controlled tool access, continuous evaluation, and human oversight in mind for production readiness.
Install
-
pip install agentops python-dotenv
Imports
- init
from agentops import init
- agent
from agentops.sdk.decorators import agent
- operation
from agentops.sdk.decorators import operation
- trace
from agentops.sdk.decorators import trace
- workflow
from agentops.sdk.decorators import workflow
- end_session
from agentops import end_session
Quickstart
import agentops
import os
from dotenv import load_dotenv
# Load environment variables (recommended for API keys)
load_dotenv()
# Initialize AgentOps
# The API key can be passed directly or set as an environment variable AGENTOPS_API_KEY
# Get your API key from the AgentOps Dashboard (app.agentops.ai)
AGENTOPS_API_KEY = os.getenv("AGENTOPS_API_KEY", "")
agentops.init(AGENTOPS_API_KEY)
print("AgentOps initialized! Any supported LLM or agent framework calls will now be tracked.")
# Example with an OpenAI call (if openai is installed and configured)
# from openai import OpenAI
# client = OpenAI()
# completion = client.chat.completions.create(
# model="gpt-3.5-turbo",
# messages=[
# {"role": "system", "content": "You are a helpful assistant."},
# {"role": "user", "content": "Hello!"}
# ]
# )
# print(completion.choices.message.content)
# It's good practice to explicitly end the session, especially for single-run scripts.
agentops.end_session('Success')
print("AgentOps session ended.")