Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.langsight.dev/llms.txt

Use this file to discover all available pages before exploring further.

What you’ll build

By the end of this page you’ll have LangSight running locally and capturing every tool call your AI agent makes — with full traces visible in both the CLI and the dashboard.

Prerequisites

  • Python 3.11+
  • Docker Desktop (recommended) — or skip Docker for CLI-only use

1. Choose your path

Quickstart flags

FlagWhat it does
(none)Start / resume the stack
--redisAlso start Redis (enables multi-worker mode and SSE broadcasting across workers)
--resetWipe all volumes + .env and start completely fresh
--buildForce-rebuild Docker images (pick up code changes)
Flags can be combined:
./scripts/quickstart.sh --reset          # clean slate
./scripts/quickstart.sh --redis          # start with Redis
./scripts/quickstart.sh --reset --build  # clean slate + fresh images

Troubleshooting the quickstart

Your Postgres volume was initialised with a different password than your current .env. This happens when .env was deleted or regenerated while volumes still existed.
./scripts/quickstart.sh --reset
--reset wipes both the volumes and .env so they’re always in sync.
On a slow machine or first run the cold-start chain (postgres → clickhouse → api → dashboard) can take up to 3–4 minutes. If it times out, the script shows which service is still starting and its last 20 log lines.Check logs directly:
docker compose logs api --tail=50
docker compose logs clickhouse --tail=50
If ports 3003, 8000, 5432, or 8123 are taken by another service, the script warns you before starting.Find what’s using a port:
lsof -i :8000   # macOS / Linux
netstat -ano | findstr :8000   # Windows
Use Git Bash (included with Git for Windows) or WSL to run the script. PowerShell and CMD are not supported. Docker Desktop must be running.

2. Instrument your agent

Add 2 lines to your existing agent code. LangSight traces every LLM call, every MCP tool call, and every agent handoff — automatically.
import langsight
langsight.auto_patch()  # LLM + MCP + handoffs — all automatic

question = "How many orders were placed today?"

# Wrap your agent logic in a session context
async with langsight.session(
    agent_name="my-agent",
    input=question,          # records the initial human prompt
) as sess:
    # MCP calls: auto-traced — no wrap() needed
    result = await mcp_session.call_tool("query", {"sql": "SELECT 1"})
    #                                                 ↑ traced automatically
    sess.set_output(result)  # records the final agent response
Set environment variables before running (all three values are in your .env):
export LANGSIGHT_URL=http://localhost:8000
export LANGSIGHT_API_KEY=ls_your_key         # grep LANGSIGHT_API_KEYS .env
export LANGSIGHT_PROJECT_ID=your-project-id  # copy from dashboard Settings > Project ID
auto_patch() patches mcp.ClientSession.call_tool, all OpenAI/Anthropic/ Gemini SDK classes, and enables handoff auto-detection — all at once. If LangSight is unreachable, your agent works normally — nothing breaks.
If you need explicit control over which MCP sessions are traced (e.g. different redact_payloads per server), use wrap() directly:
from langsight.sdk import LangSightClient

ls = LangSightClient(url="http://localhost:8000")
traced = ls.wrap(mcp_session, server_name="postgres-mcp",
                 agent_name="my-agent", session_id="sess-001")
result = await traced.call_tool("query", {"sql": "SELECT 1"})

Using a framework? Even simpler.

import langsight
langsight.auto_patch()  # zero config — patches LangGraph automatically

# No callbacks needed — auto_patch() injects tracing into
# graph.stream(), graph.invoke(), and all LLM calls.
graph = builder.compile()
result = graph.invoke({"task": "Write a report on EU inflation"})
See LangGraph Integration for topology capture, loop detection, and budget enforcement.

3. See your first trace

Run your agent, then check results:
langsight sessions
Agent Sessions                             last 24 hours
──────────────────────────────────────────────────────────────
Session       Agent         Duration   Tools   Errors   Cost
sess-001      my-agent      1,482ms       5        0   $0.02
Drill into a session:
langsight sessions --id sess-001
Session: sess-001  |  1 agent  |  5 tool calls  |  0 failures

├── [MCP] postgres-mcp/query          42ms  ✓
├── [MCP] postgres-mcp/list_tables    18ms  ✓
├── [MCP] postgres-mcp/query          89ms  ✓
├── [MCP] slack-mcp/send_message     210ms  ✓
└── [MCP] slack-mcp/send_message     180ms  ✓

3 (optional). Add prevention guardrails

Prevent runaway loops and budget overruns with a few extra parameters:
client = LangSightClient(
    url="http://localhost:8000",
    loop_detection=True,   # stop if agent loops the same call 3x
    max_steps=25,          # hard stop at 25 tool calls per session
    circuit_breaker=True,  # auto-disable servers after 5 consecutive failures
)
See Prevention Guardrails for full configuration options.

4. What’s next

You now have full traces of every tool call. Here’s what LangSight does beyond tracing:

MCP Health Monitoring

Continuous uptime and latency checks for every MCP server. Detects schema drift and fires alerts on state changes.

Security Scanning

OWASP MCP Top 10 checks, CVE scanning, tool poisoning detection, and auth auditing — built in.

Cost Attribution

Per-agent, per-tool, per-session cost breakdown with model pricing database (Claude, GPT, Gemini, Llama).

SLOs & Alerting

Define success rate and latency SLOs per agent. Get Slack alerts on breaches and anomalies.

Multi-agent tracing

If your agent hands off to sub-agents, LangSight captures the full tree — automatically when tools follow the call_<agent> naming convention:
import langsight
langsight.auto_patch()

async def orchestrator(question: str):
    async with langsight.session(agent_name="orchestrator", input=question) as sess:
        await jira_mcp.call_tool("get_issue", {"id": "TASK-42"})
        # LLM selects "call_research_agent" → handoff span auto-emitted
        response = await llm.generate(question, tools=[call_research_agent_tool])
        sess.set_output(response)

async def research_agent(question: str):
    async with langsight.session(agent_name="research_agent", input=question) as sess:
        result = await confluence_mcp.call_tool("search", {"query": question})
        sess.set_output(result)
        return result
For explicit handoff control (no tool-name convention required):
from langsight.sdk import LangSightClient

ls = LangSightClient(url="http://localhost:8000")

async with langsight.session(agent_name="orchestrator") as session_id:
    handoff = ls.create_handoff("orchestrator", "research-agent", session_id=session_id)
    researcher = ls.wrap_child_agent(mcp, "confluence-mcp", "research-agent", handoff)
    await researcher.call_tool("search", {"query": "returns policy"})
The dashboard renders both patterns as a single connected tree across all agents.

Python SDK Reference

Full API reference with all options.

Self-Hosting Guide

Production deployment with Postgres + ClickHouse.