Recording Operations
Instrument your code with decorators to track operations, tasks, and workflows.
To get the most out of AgentOps, it’s important to properly instrument your code to track operations. AgentOps provides a set of decorators that make this easy.
Using Decorators for Instrumentation
AgentOps provides several decorators that allow you to easily instrument your code:
@operation
/ @task
Decorator
The @operation
and @task
decorators are aliases that create operation/task spans for tracking specific operations.
You can also use these decorators with parameters:
When used within an agent class, operations are automatically nested under the agent:
@workflow
Decorator
The @workflow
decorator creates workflow spans for tracking workflows, which can contain multiple operations.
@agent
Decorator
The @agent
decorator creates an agent span for tracking agent operations.
@session
Decorator
The @session
decorator creates a session span, which serves as the root for all other spans.
Automatic Instrumentation
AgentOps automatically instruments calls to popular LLM providers (OpenAI, Anthropic, etc.). These calls are automatically tracked as LLM spans and are properly nested within your agent and operation spans.
Best Practices
-
Use the Right Decorator: Choose the appropriate decorator based on what you’re instrumenting:
@session
for the root of your application@agent
for agent classes@operation
for specific operations@workflow
for sequences of operations
-
Proper Nesting: Ensure that your spans are properly nested:
- Session spans should be at the top
- Agent spans should be children of session spans
- Operation spans should be children of agent spans
-
Meaningful Names: Use meaningful names for your spans to make them easier to identify in the dashboard.
-
Record Important Data: The decorators automatically record function parameters and return values, but you can also add custom attributes to spans for additional context.