Working with Multiple Agents

Learn how to use LangDB to Trace Multi Agent workflows

LangDB automatically visualizes how agents interact, providing a clear view of workflows, hierarchies, and usage patterns by adding run and thread headers.

This allows developers to track interactions between agents seamlessly, ensuring clear visibility into workflows and dependencies.

With LangDB you can trace mulitple Agents. This will be in a form of a thread which stores all the interaction of workflow as a conversation and tracing which has details about the LLMs, Tool calls, Models, Parameters, etc.

What is a Multi-Agent System?

A multi-agent system consists of independent agents collaborating to solve complex tasks. Agents handle various roles such as user interaction, data processing, and workflow orchestration. LangDB streamlines tracking these interactions for better efficiency and transparency.

Why Track Workflows?

Tracking ensures:

  • Clear Execution Flow: Understand how agents interact.

  • Performance Optimization: Identify bottlenecks.

  • Reliability & Accountability: Improve transparency.

LangDB supports two main concepts.

  • Run: A complete end-to-end interaction between agents, grouped for easy tracking.

  • Thread: Aggregate multiple Runs into a single thread for a unified chat experience.

    Example

Using the same Run ID and Thread ID across multiple agents ensures seamless tracking, maintaining context across interactions and providing a complete view of the workflow

from openai import OpenAI
from uuid import uuid4
client = OpenAI(
    base_url="https://api.us-east-1.langdb.ai/{langdb_project_id}/v1"  # LangDB API base URL,
    api_key=api_key,  # Replace with your LangDB token
)
response1 = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "developer", "content": "You are a helpful assistant."},
              {"role": "user", "content": "Hello!"}],  
    extra_headers={"x-thread-id": thread_id, "x-run-id": run_id}
)

# Agent 2 processes the response
response2 = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "developer", "content": "Processing user input."},
              {"role": "user", "content": response1.choices[0].message["content"]}],  
    extra_headers={"x-thread-id": thread_id, "x-run-id": run_id}
)

Checkout the full Multi-Agent Tracing Example here.

Last updated

Was this helpful?