Integrating Agno with Langtrace

Langtrace provides a powerful platform for tracing and monitoring AI model calls. By integrating Agno with Langtrace, you can gain insights into your agent’s performance and behavior.

Prerequisites

  1. Install Dependencies Ensure you have the necessary package installed:
    pip install langtrace-python-sdk
    
  2. Create a Langtrace Account
    • Sign up for an account at Langtrace.
    • Obtain your API key from the Langtrace dashboard.
  3. Set Environment Variables Configure your environment with the Langtrace API key:
    export LANGTRACE_API_KEY=<your-key>
    

Sending Traces to Langtrace

This example demonstrates how to instrument your Agno agent with Langtrace.
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.duckduckgo import DuckDuckGoTools
from langtrace_python_sdk import langtrace
from langtrace_python_sdk.utils.with_root_span import with_langtrace_root_span

# Initialize Langtrace
langtrace.init()

# Create and configure the agent
agent = Agent(
    name="Research Agent",
    model=OpenAIChat(id="gpt-4o-mini"),
    tools=[DuckDuckGoTools(search=True, news=True)],
    instructions="You are a research agent. Answer questions in the style of a professional researcher.",
    debug_mode=True,
)

# Use the agent
agent.print_response("What is the latest news about artificial intelligence?")

Notes

  • Environment Variables: Ensure your environment variable is correctly set for the API key.
  • Initialization: Call langtrace.init() to initialize Langtrace before using the agent.
By following these steps, you can effectively integrate Agno with Langtrace, enabling comprehensive observability and monitoring of your AI agents.