Langtrace

Monitoring Agents and Swarms with Langtrace

Langtrace is an open source observability and evaluations platform for AI Agents. You can use it to track vital LLM metrics, store & version control your prompts, compare the performance of your prompts across different models and much more.

Configuring Langtrace for SwarmZero

Setup

  1. Create a new project.

    1. Give it a name and description.

    2. Set the project type to Default.

Install Langtrace

  1. Install the Python SDK for Langtrace in your existing SwarmZero project.

pip install langtrace-python-sdk
  1. Import and initialize Langtrace before you import the SwarmZero SDK.

import os

from dotenv import load_dotenv
load_dotenv()

from langtrace_python_sdk import langtrace
langtrace.init(
    api_key=os.getenv("LANGTRACE_API_KEY", ""),
    disable_instrumentations={ "only": ["sqlalchemy"] }  # optional
)

from swarmzero import Agent

# ...

Add the Langtrace API Key

  1. Generate a Langtrace API Key from the Langtrace app dashboard.

    1. Select the Setup Project button on the newly created project card.

    2. Click Generate API Key and follow the on-screen instructions.

    3. Copy the API key.

  2. In the .env file of your SwarmZero project, add this:

LANGTRACE_API_KEY=<your_generated_api_key>
  1. Restart the agent server if you are using the agent.run() method.

    1. If not, just call agent.chat(...) again from your Python script.

Sample agent observability dashboard

Examples of Langtrace integration can be found in the examples repository.

Last updated

Was this helpful?