langtrace_op.py
"""
Langtrace Integration
=====================
Demonstrates instrumenting an Agno agent with Langtrace.
"""
# Must precede other imports
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.yfinance import YFinanceTools
from langtrace_python_sdk import langtrace # type: ignore
# ---------------------------------------------------------------------------
# Setup
# ---------------------------------------------------------------------------
langtrace.init()
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(
name="Stock Price Agent",
model=OpenAIChat(id="gpt-5.2"),
tools=[YFinanceTools()],
instructions="You are a stock price agent. Answer questions in the style of a stock analyst.",
debug_mode=True,
)
# ---------------------------------------------------------------------------
# Run Example
# ---------------------------------------------------------------------------
if __name__ == "__main__":
agent.print_response("What is the current price of Tesla?")
Run the Example
1
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
2
Install dependencies
uv pip install -U agno langtrace-python-sdk openai yfinance
3
Export your OpenAI API key
export OPENAI_API_KEY="your_openai_api_key_here"
$Env:OPENAI_API_KEY="your_openai_api_key_here"
4
Run the example
Save the code above as
langtrace_op.py, then run:python langtrace_op.py