Langtrace

Integrate Kern with Langtrace to send traces and gain insights into your agent's performance.

Integrating Kern with Langtrace

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

Prerequisites

  1. Install Dependencies

    Ensure you have the necessary package installed:

    1uv 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:

    1export LANGTRACE_API_KEY=<your-key>

Sending Traces to Langtrace

This example demonstrates how to instrument your Kern agent with Langtrace.

1from kern.agent import Agent
2from kern.models.openai import OpenAIResponses
3from kern.tools.yfinance import YFinanceTools
4from langtrace_python_sdk import langtrace
5from langtrace_python_sdk.utils.with_root_span import with_langtrace_root_span
6
7# Initialize Langtrace
8langtrace.init()
9
10# Create and configure the agent
11agent = Agent(
12 name="Stock Price Agent",
13 model=OpenAIResponses(id="gpt-5.2"),
14 tools=[YFinanceTools()],
15 instructions="You are a stock price agent. Answer questions in the style of a stock analyst.",
16 debug_mode=True,
17)
18
19# Use the agent
20agent.print_response("What is the current price of Tesla?")

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 Kern with Langtrace, enabling comprehensive observability and monitoring of your AI agents.