Skip to content

Agent Tracing

An AgentTrace is returned when calling agent.run or agent.run_async.

any-agent generates standardized (regarding the structure) OpenTelemetry traces regardless of the framework used, based on the Semantic conventions for generative AI systems. This means that any OpenTelemetry exporter compatible with the Python SDK can be added. More information can be found below.

You can try to find the subtle differences (regarding the content) across frameworks in the examples below.

Here is what the console output looks like:

Here’s what the returned agent_trace.spans look like when dumped to JSON format:

You can download the AGNO trace JSON.

The AgentTrace object is a pydantic model and can be saved to disk via standard pydantic practices:

from any_agent import AgentConfig, AnyAgent
from any_agent.tools import search_web
agent = AnyAgent.create(
"openai",
agent_config=AgentConfig(
model_id="mistral:mistral-small-latest",
tools=[search_web],
)
)
agent_trace = agent.run("Which agent framework is the best?")
with open("agent_trace.json", "w", encoding="utf-8") as f:
f.write(agent_trace.model_dump_json(indent=2, serialize_as_any=True))

Before starting to use the library, you can add new OpenTelemetry exporters and processors as needed.

The following code will use the OpenTelemetry Python SDK to send the agent traces to an additional endpoint using OTLP over HTTP in the indicated URL:

from opentelemetry.trace import get_tracer_provider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
tp = get_tracer_provider()
http_exporter = OTLPSpanExporter(endpoint="http://localhost:4318/v1/traces")
tp.add_span_processor(SimpleSpanProcessor(http_exporter))