traceloop_op.py
Run the Example
1
Set up your virtual environment
2
Install dependencies
3
Export your API keys
4
Run the example
Save the code above as
traceloop_op.py, then run:Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Wraps an agent run in a Traceloop @workflow-decorated function so the run appears under a parent workflow span.
"""
Traceloop Integration
=====================
Demonstrates wrapping Agno calls in Traceloop workflow spans.
"""
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from traceloop.sdk import Traceloop
from traceloop.sdk.decorators import workflow
# ---------------------------------------------------------------------------
# Setup
# ---------------------------------------------------------------------------
Traceloop.init(app_name="agno_workflows")
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(
name="AnalysisAgent",
model=OpenAIChat(id="gpt-5.2"),
debug_mode=True,
)
@workflow(name="data_analysis_pipeline")
def analyze_data(query: str) -> str:
"""Custom workflow that wraps agent execution."""
response = agent.run(query)
return response.content
# ---------------------------------------------------------------------------
# Run Example
# ---------------------------------------------------------------------------
if __name__ == "__main__":
# The workflow decorator creates a parent span
result = analyze_data("Analyze the benefits of observability in AI systems")
print(result)
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
Install dependencies
uv pip install -U agno openai traceloop-sdk
Export your API keys
export OPENAI_API_KEY="your_openai_api_key_here"
export TRACELOOP_API_KEY="your_traceloop_api_key_here"
$Env:OPENAI_API_KEY="your_openai_api_key_here"
$Env:TRACELOOP_API_KEY="your_traceloop_api_key_here"
Run the example
traceloop_op.py, then run:python traceloop_op.py
Was this page helpful?