Give us a star on GitHub! Your support helps us grow. ⭐
The AgentOps app is open source—explore the code in our GitHub app directory.
Prefer asking your IDE? Install the Mintlify MCP Docs Server for AgentOps to chat with the docs while you code:
npx mint-mcp add agentops
Installation
First, install the AgentOps SDK. We recommend includingpython-dotenv
for easy API key management.
Initial Setup (2 Lines of Code)
At its simplest, AgentOps can start monitoring your supported LLM and agent framework calls with just two lines of Python code.- Import AgentOps: Add
import agentops
to your script. - Initialize AgentOps: Call
agentops.init()
with your API key.
Setting Your AgentOps API Key
You need an AgentOps API key to send data to your dashboard.- Get your API key from the AgentOps Dashboard.
.env
file, make sure load_dotenv()
is called before agentops.init()
.
Running Your Agent & Viewing Traces
After adding the two lines and ensuring your API key is set up:- Run your agent application as you normally would.
- AgentOps will automatically instrument supported libraries and send trace data.
- Visit your AgentOps Dashboard to observe your agent’s operations!
Beyond Automatic Instrumentation: Decorators
While AgentOps automatically instruments many popular libraries, you can gain finer-grained control and track custom parts of your code using our powerful decorators. This allows you to define specific operations, group logic under named agents, track tool usage with costs, and create custom traces.Tracking Custom Operations with @operation
Instrument any function in your code to create spans that track its execution, parameters, and return values. These operations will appear in your session visualization alongside LLM calls.
Tracking Agent Logic with @agent
If you structure your system with specific named agents (e.g., classes), use the @agent
decorator on the class and @operation
on its methods to group all downstream operations under that agent’s context.
Tracking Tools with @tool
Track the usage of specific tools or functions, and optionally associate costs with them. This data will be aggregated in your dashboard.
Grouping with Traces (@trace
or manual)
Create custom traces to group a sequence of operations or define logical units of work. You can use the @trace
decorator or manage traces manually for more complex scenarios.
If
auto_start_session=False
in agentops.init()
, you must use @trace
or agentops.start_trace()
for any data to be recorded.Updating Trace Metadata
You can also update metadata on running traces to add context or track progress:Complete Example with Decorators
Here’s a consolidated example showcasing how these decorators can work together:Next Steps
You’ve seen how to get started with AgentOps! Explore further to leverage its full potential:Integrations
See how AgentOps automatically instruments popular LLM and agent frameworks.
Examples
Explore detailed examples for various use cases and integrations.
SDK Reference
Dive deeper into the AgentOps SDK capabilities and API.
Trace Decorator
Learn how to group operations and create custom traces using the @trace decorator.