Use decorators to track activities in your agent system
Decorator | Purpose | Creates |
---|---|---|
@session | Track an entire user interaction | SESSION span |
@agent | Track agent classes and their lifecycle | AGENT span |
@operation | Track discrete operations performed by agents | OPERATION span |
@workflow | Track a sequence of operations | WORKFLOW span |
@task | Track smaller units of work (similar to operations) | TASK span |
@tool | Track tool usage and cost in agent operations | TOOL span |
@guardrail | Track guardrail input and output | GUARDRAIL span |
@session
decorator tracks an entire user interaction from start to finish:
@session
function call creates a new session span that contains all the agents, operations, and workflows used during that interaction.
@agent
decorator instruments a class to track its lifecycle and operations:
@operation
decorator tracks discrete functions performed by an agent:
@workflow
decorator tracks a sequence of operations that work together:
@task
decorator is similar to @operation
but can be used for smaller units of work:
@task
and @operation
decorators function identically (they are aliases in the codebase), and you can choose the one that best fits your semantic needs.
@tool
decorator tracks tool usage within agent operations and supports cost tracking. It works with all function types: synchronous, asynchronous, generator, and async generator.
@guardrail
decorator tracks guardrail input and output. You can specify the guardrail type ("input"
or "output"
) with the spec
parameter.
Attribute | Description | Example |
---|---|---|
name | Custom name for the span | name="weather_forecast" |
attributes | Dictionary of custom attributes | attributes={"model": "gpt-4"} |
@session
decorator wraps the entire interaction@agent
decorator defines multiple agent classes@workflow
decorator creates a workflow that coordinates agents@operation
and @task
decorators track individual operations