Skip to content

Langtrace Overview

Langtrace is an open-source, external tool that helps you set up observability and evaluations for Large Language Models (LLMs), LLM frameworks, and Vector Databases. While not built directly into CrewAI, Langtrace can be used alongside CrewAI to gain deep visibility into the cost, latency, and performance of your CrewAI Agents. This integration allows you to log hyperparameters, monitor performance regressions, and establish a process for continuous improvement of your Agents.

Setup Instructions

  1. Sign up for Langtrace by visiting
  2. Create a project and generate an API key.
  3. Install Langtrace in your CrewAI project using the following commands:
# Install the SDK
pip install langtrace-python-sdk

Using Langtrace with CrewAI

To integrate Langtrace with your CrewAI project, follow these steps:

  1. Import and initialize Langtrace at the beginning of your script, before any CrewAI imports:
from langtrace_python_sdk import langtrace

# Now import CrewAI modules
from crewai import Agent, Task, Crew
  1. Create your CrewAI agents and tasks as usual.

  2. Use Langtrace's tracking functions to monitor your CrewAI operations. For example:

with langtrace.trace("CrewAI Task Execution"):
    result = crew.kickoff()

Features and Their Application to CrewAI

  1. LLM Token and Cost Tracking
  2. Monitor the token usage and associated costs for each CrewAI agent interaction.
  3. Example:

    with langtrace.trace("Agent Interaction"):
        agent_response = agent.execute(task)

  4. Trace Graph for Execution Steps

  5. Visualize the execution flow of your CrewAI tasks, including latency and logs.
  6. Useful for identifying bottlenecks in your agent workflows.

  7. Dataset Curation with Manual Annotation

  8. Create datasets from your CrewAI task outputs for future training or evaluation.
  9. Example:

    langtrace.log_dataset_item(task_input, agent_output, {"task_type": "research"})

  10. Prompt Versioning and Management

  11. Keep track of different versions of prompts used in your CrewAI agents.
  12. Useful for A/B testing and optimizing agent performance.

  13. Prompt Playground with Model Comparisons

  14. Test and compare different prompts and models for your CrewAI agents before deployment.

  15. Testing and Evaluations

  16. Set up automated tests for your CrewAI agents and tasks.
  17. Example:
    langtrace.evaluate(agent_output, expected_output, "accuracy")

Monitoring New CrewAI Features

CrewAI has introduced several new features that can be monitored using Langtrace:

  1. Code Execution: Monitor the performance and output of code executed by agents.

    with langtrace.trace("Agent Code Execution"):
        code_output = agent.execute_code(code_snippet)

  2. Third-party Agent Integration: Track interactions with LlamaIndex, LangChain, and Autogen agents.