Working with Agno

Unlock full observability for CrewAI agents and tasks—capture LLM calls, task execution, and agent interactions with LangDB’s init().

LangDB’s Agno integration provides end-to-end tracing for your Agno agent pipelines.

Installation

Install the LangDB client with Agno feature flag:

pip install 'pylangdb[agno]'

Quick Start

Export Environment Variables

Set your LangDB credentials:

export LANGDB_API_KEY="<your_langdb_api_key>"
export LANGDB_PROJECT_ID="<your_langdb_project_id>"

Initialize Tracing

Import and run the initialize before configuring your Agno Code:

from pylangdb.agno import init
# Initialise LangDB
init()

Configure your Agno code

import os
from pylangdb.agno import init
init()

from agno.agent import Agent
from agno.tools.duckduckgo import DuckDuckGoTools
from agno.models.langdb import LangDB

# Configure LangDB-backed model
langdb_model = LangDB(
    id="openai/gpt-4",
    api_key=os.getenv("LANGDB_API_KEY"),
    project_id=os.getenv("LANGDB_PROJECT_ID"),
)

# Create and run your agent
agent = Agent(
    name="Web Agent",
    role="Search the web for information",
    model=langdb_model,
    tools=[DuckDuckGoTools()],
    instructions="Answer questions using web search",
)

response = agent.run("What is LangDB?")
print(response)

All Agno interactions from invocation through tool calls to final output are traced with LangDB.

Complete Agno Example

Here is a full example based on Web Search Agno Multi Agent Team.

Setup Environment

pip install agno 'pylangdb[agno]' duckduckgo-search

Export Environment Variables

export LANGDB_API_KEY="<your_langdb_api_key>"
export LANGDB_PROJECT_ID="<your_langdb_project_id>"
export LANGDB_API_BASE_URL='https://api.us-east-1.langdb.ai'

main.py

import os
from textwrap import dedent

# Initialize LangDB tracing and import model
from pylangdb.agno import init
init()
from agno.models.langdb import LangDB

# Import Agno agent components
from agno.agent import Agent
from agno.tools.duckduckgo import DuckDuckGoTools

# Function to create a LangDB model with selectable model name
def create_langdb_model(model_name="openai/gpt-4.1"):
    return LangDB(
        id=model_name,
        api_key=os.getenv("LANGDB_API_KEY"),
        project_id=os.getenv("LANGDB_PROJECT_ID"),
    )

web_agent = Agent(
    name="Web Agent",
    role="Search the web for comprehensive information and current data",
    model=create_langdb_model("openai/gpt-4.1"),
    tools=[DuckDuckGoTools()],
    instructions="Always use web search tools to find current and accurate information. Search for multiple aspects of the topic to gather comprehensive data.",
    show_tool_calls=True, 
    markdown=True,        
)


writer_agent = Agent(
    name="Writer Agent",
    role="Write comprehensive article on the provided topic",
    model=create_langdb_model("anthropic/claude-3.7-sonnet"),
    instructions="Use outlines to write articles",
    show_tool_calls=True,
    markdown=True,
)

agent_team = Agent(
    name="Research Team",
    team=[web_agent, writer_agent],  
    model=create_langdb_model("gemini/gemini-2.0-flash"),
    instructions=dedent("""\
        You are the coordinator of a research team with two specialists:
        
        1. Web Agent: Has DuckDuckGo search tools and must be used for ALL research tasks
        2. Writer Agent: Specializes in creating comprehensive articles
        
        WORKFLOW:
        1. ALWAYS delegate research tasks to the Web Agent first
        2. The Web Agent MUST use web search tools to gather current information
        3. Then delegate writing tasks to the Writer Agent using the research findings
        4. Ensure comprehensive coverage of the topic through multiple searches
        
        IMPORTANT: Never attempt to answer without first having the Web Agent conduct searches.
    """),
    show_tool_calls=True,
    markdown=True,
)

agent_team.print_response(
    "I need a comprehensive article about the Eiffel Tower. "
    "Please have the Web Agent search for current information about its history, architectural significance, and cultural impact. "
    "Then have the Writer Agent create a detailed article based on the research findings.", 
    stream=True
)

Running your Agent

Navigate to the parent directory of your agent project and use one of the following commands:

python main.py

Traces on LangDB

When you run queries against your agent, LangDB automatically captures detailed traces of all agent interactions:

Multi Team Agno Trace

Next Steps: Advanced Agno Integration

This guide covered the basics of integrating LangDB with Agno using a Web Search agent example. For more complex scenarios and advanced use cases, check out our comprehensive resources in Guides Section.

Last updated

Was this helpful?