Basic Setup
The simplest way to get started with AgentOps is to initialize it at the beginning of your application:- Automatically create a session for tracking your application run
- Intercept and track all LLM calls to supported providers (OpenAI, Anthropic, etc.)
- Record relevant metrics such as token counts, costs, and response times
Automatic Instrumentation
AgentOps automatically instruments calls to popular LLM providers without requiring any additional code:- OpenAI
- Anthropic
- Google (Gemini)
- Cohere
- And more
Advanced: Using Decorators for Detailed Instrumentation
For more detailed tracking, AgentOps provides decorators that allow you to explicitly instrument your code. This is optional but can provide more context in the dashboard.@operation Decorator
The @operation decorator helps track specific operations in your application:
@agent Decorator
If you use agent classes, you can track them with the @agent decorator:
@tool Decorator
Track tool usage and costs with the @tool decorator. You can specify costs to get total cost tracking directly in your dashboard summary:
@trace Decorator
Create custom traces to group related operations using the @trace decorator. This is the recommended approach for most applications:
Best Practices
-
Keep it Simple: For most applications, just initializing AgentOps with
agentops.init()is sufficient. -
Use @trace for Custom Workflows: When you need to group operations, use the
@tracedecorator instead of manual trace management. - Meaningful Names and Tags: When using decorators, choose descriptive names and relevant tags to make them easier to identify in the dashboard.
-
Cost Tracking: Use the
@tooldecorator with cost parameters to track tool usage costs in your dashboard.

