Tracing
any_agent.tracing.agent_trace.AgentTrace
Bases: BaseModel
A trace that can be exported to JSON or printed to the console.
Source code in src/any_agent/tracing/agent_trace.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
|
cost
cached
property
The CostInfo
for this trace. Cached after first computation.
duration
property
Duration of the parent invoke_agent
span as a datetime.timedelta object.
The duration is computed from the span's start and end time (in nanoseconds).
Raises ValueError if
- There are no spans.
- The invoke_agent span is not the last span.
- Any of the start/end times are missing.
final_output = Field(default=None)
class-attribute
instance-attribute
Contains the final output message returned by the agent.
spans = Field(default_factory=list)
class-attribute
instance-attribute
A list of AgentSpan
that form the trace.
tokens
cached
property
The TokenInfo
for this trace. Cached after first computation.
add_span(span)
Add an AgentSpan to the trace and clear the tokens_and_cost cache if present.
Source code in src/any_agent/tracing/agent_trace.py
add_spans(spans)
Add a list of AgentSpans to the trace and clear the tokens_and_cost cache if present.
spans_to_messages()
Convert spans to standard message format.
Returns:
Type | Description |
---|---|
list[AgentMessage]
|
List of message dicts with 'role' and 'content' keys. |
Source code in src/any_agent/tracing/agent_trace.py
any_agent.tracing.agent_trace.AgentSpan
Bases: BaseModel
A span that can be exported to JSON or printed to the console.
Source code in src/any_agent/tracing/agent_trace.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
|
from_otel(otel_span)
classmethod
Create an AgentSpan from an OTEL Span.
Source code in src/any_agent/tracing/agent_trace.py
get_input_messages()
Extract input messages from an LLM call span.
Returns:
Type | Description |
---|---|
list[AgentMessage] | None
|
List of message dicts with 'role' and 'content' keys, or None if not available. |
Source code in src/any_agent/tracing/agent_trace.py
get_output_content()
Extract output content from an LLM call or tool execution span.
Returns:
Type | Description |
---|---|
str | None
|
The output content as a string, or None if not available. |
Source code in src/any_agent/tracing/agent_trace.py
is_agent_invocation()
Check whether this span is an agent invocation (the very first span).
is_llm_call()
is_tool_execution()
set_attributes(attributes)
Set attributes for the span.
Source code in src/any_agent/tracing/agent_trace.py
to_readable_span()
Create an ReadableSpan from the AgentSpan.
Source code in src/any_agent/tracing/agent_trace.py
any_agent.tracing.agent_trace.CostInfo
Bases: BaseModel
Cost information.
Source code in src/any_agent/tracing/agent_trace.py
input_cost
instance-attribute
Cost associated to the input tokens.
output_cost
instance-attribute
Cost associated to the output tokens.
total_cost
property
Total cost.
any_agent.tracing.agent_trace.TokenInfo
Bases: BaseModel
Token Count information.
Source code in src/any_agent/tracing/agent_trace.py
input_tokens
instance-attribute
Number of input tokens.
output_tokens
instance-attribute
Number of output tokens.
total_tokens
property
Total number of tokens.
any_agent.tracing.attributes.GenAI
Constants exported for convenience to access span attributes.
Trying to follow OpenTelemetry's Semantic Conventions for Generative AI.
We import the constants from opentelemetry.semconv._incubating.attributes.gen_ai_attributes
whenever is possible.
We only expose the keys that we currently use in any-agent
.
Source code in src/any_agent/tracing/attributes.py
AGENT_DESCRIPTION = GEN_AI_AGENT_DESCRIPTION
class-attribute
instance-attribute
Free-form description of the GenAI agent provided by the application.
AGENT_NAME = GEN_AI_AGENT_NAME
class-attribute
instance-attribute
Human-readable name of the GenAI agent provided by the application.
INPUT_MESSAGES = 'gen_ai.input.messages'
class-attribute
instance-attribute
System prompt and user input.
OPERATION_NAME = GEN_AI_OPERATION_NAME
class-attribute
instance-attribute
The name of the operation being performed.
OUTPUT = 'gen_ai.output'
class-attribute
instance-attribute
Used in both LLM Calls and Tool Executions for holding their respective outputs.
OUTPUT_TYPE = GEN_AI_OUTPUT_TYPE
class-attribute
instance-attribute
Represents the content type requested by the client.
REQUEST_MODEL = GEN_AI_REQUEST_MODEL
class-attribute
instance-attribute
The name of the GenAI model a request is being made to.
TOOL_ARGS = 'gen_ai.tool.args'
class-attribute
instance-attribute
Arguments passed to the executed tool.
TOOL_DESCRIPTION = GEN_AI_TOOL_DESCRIPTION
class-attribute
instance-attribute
The tool description.
TOOL_NAME = GEN_AI_TOOL_NAME
class-attribute
instance-attribute
Name of the tool utilized by the agent.
USAGE_INPUT_COST = 'gen_ai.usage.input_cost'
class-attribute
instance-attribute
Dollars spent for the input of the LLM.
USAGE_INPUT_TOKENS = GEN_AI_USAGE_INPUT_TOKENS
class-attribute
instance-attribute
The number of tokens used in the GenAI input (prompt).
USAGE_OUTPUT_COST = 'gen_ai.usage.output_cost'
class-attribute
instance-attribute
Dollars spent for the output of the LLM.
USAGE_OUTPUT_TOKENS = GEN_AI_USAGE_OUTPUT_TOKENS
class-attribute
instance-attribute
The number of tokens used in the GenAI response (completion).