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
-
Install Dependencies
Ensure you have the necessary package installed:
1uv pip install langtrace-python-sdk -
Create a Langtrace Account
- Sign up for an account at Langtrace.
- Obtain your API key from the Langtrace dashboard.
-
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 Agent2from kern.models.openai import OpenAIResponses3from kern.tools.yfinance import YFinanceTools4from langtrace_python_sdk import langtrace5from langtrace_python_sdk.utils.with_root_span import with_langtrace_root_span67# Initialize Langtrace8langtrace.init()910# Create and configure the agent11agent = 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)1819# Use the agent20agent.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.