LangDB

Integrate Kern with LangDB to trace agent execution, tool calls, and gain comprehensive observability into your agent's performance.

Integrating Kern with LangDB

LangDB provides an AI Gateway platform for comprehensive observability and tracing of AI agents and LLM interactions. By integrating Kern with LangDB, you can gain full visibility into your agent's operations, including agent runs, tool calls, team interactions, and performance metrics.

For detailed integration instructions, see the LangDB Kern documentation.

langdb-kern finance team observability
LangDB Finance Team Trace

Prerequisites

  1. Install Dependencies

    Ensure you have the necessary packages installed:

    1uv pip install kern-ai 'pylangdb[kern-ai]'
  2. Setup LangDB Account

    • Sign up for an account at LangDB
    • Create a new project in the LangDB dashboard
    • Obtain your API key and Project ID from the project settings
  3. Set Environment Variables

    Configure your environment with the LangDB credentials:

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

Sending Traces to LangDB

Example: Basic Agent Setup

This example demonstrates how to instrument your Kern agent with LangDB tracing.

1from pylangdb.kern import init
2
3# Initialize LangDB tracing - must be called before creating agents
4init()
5
6from kern.agent import Agent
7from kern.models.langdb import LangDB
8from kern.tools.hackernews import HackerNewsTools
9
10# Create agent with LangDB model (uses environment variables automatically)
11agent = Agent(
12 name="Web Research Agent",
13 model=LangDB(id="openai/gpt-4.1"),
14 tools=[HackerNewsTools()],
15 instructions="Answer questions using web search and provide comprehensive information"
16)
17
18# Use the agent
19response = agent.run("What are the latest developments in AI agents?")
20print(response)

Example: Multi-Agent Team Coordination

For more complex workflows, you can use Kern's Team class with LangDB tracing:

1from pylangdb.kern import init
2init()
3
4from kern.agent import Agent
5from kern.team import Team
6from kern.models.langdb import LangDB
7from kern.tools.hackernews import HackerNewsTools
8from kern.tools.yfinance import YFinanceTools
9
10# Research Agent
11web_agent = Agent(
12 name="Market Research Agent",
13 model=LangDB(id="openai/gpt-4.1"),
14 tools=[HackerNewsTools()],
15 instructions="Research current market conditions and news"
16)
17
18# Financial Analysis Agent
19finance_agent = Agent(
20 name="Financial Analyst",
21 model=LangDB(id="xai/grok-4"),
22 tools=[YFinanceTools(stock_price=True, company_info=True)],
23 instructions="Perform quantitative financial analysis"
24)
25
26# Coordinated Team
27reasoning_team = Team(
28 name="Finance Reasoning Team",
29 model=LangDB(id="xai/grok-4"),
30 members=[web_agent, finance_agent],
31 instructions=[
32 "Collaborate to provide comprehensive financial insights",
33 "Consider both fundamental analysis and market sentiment"
34 ]
35)
36
37# Execute team workflow
38reasoning_team.print_response("Analyze Apple (AAPL) investment potential")

Sample Trace

View a complete example trace in the LangDB dashboard: Finance Reasoning Team Trace

langdb-kern finance team observability
LangDB Finance Team Thread

Advanced Features

LangDB Capabilities

  • Virtual Models: Save, share, and reuse model configurations—combining prompts, parameters, tools, and routing logic into a single named unit for consistent behavior across apps
  • MCP Support: Enhanced tool capabilities through Model Context Protocol servers
  • Multi-Provider: Support for OpenAI, Anthropic, Google, xAI, and other providers

Notes

  • Initialization Order: Always call init() before creating any Kern agents or teams
  • Environment Variables: With LANGDB_API_KEY and LANGDB_PROJECT_ID set, you can create models with just LangDB(id="model_name")

Resources

By following these steps, you can effectively integrate Kern with LangDB, enabling comprehensive observability and monitoring of your AI agents.