Laminar Documentation

repository·main·Indexed 25 days ago

https://github.com/lmnr-ai/lmnr

Laminar is an open-source observability platform for AI agents, providing tracing, signal tracking, evaluations, and dashboards to monitor and debug agentic workflows. The project includes an app-server for backend logic, a React-based frontend, and a pii-redactor gRPC service for redacting personally identifiable information using token-classification models.

Tokens
45.6K
Snippets
81
Records
402
Agent score
83%

What's inside Laminar

  1. Overview of app-server modules

    main

    The app-server is organized into several core modules:

    • API: Provides endpoints for external access, such as triggering a pipeline by its ID.
    • DB: Handles all database interactions. Submodule names typically correspond to their respective database tables.
    • Language model: Contains structs and methods for interacting directly with language models.
    • Routes: Uses the actix_web router to manage and direct incoming HTTP requests.
  2. Laminar Architecture Overview

    main

    Laminar is designed for high-throughput agent observability using a high-performance stack:

    • Rust backend: Core performance engine.
    • gRPC ingestion: Low-overhead trace collection.
    • ClickHouse: Used for high-speed analytics.
    • Postgres: Manages transactional state.
    • RabbitMQ: Handles asynchronous processing.
    • OpenTelemetry-native: Built from the ground up for OTel compatibility.
  3. Compare Laminar and Langfuse for Agent Observability

    main

    Laminar and Langfuse are both observability platforms for LLMs, but they optimize for different workflows:

    • Laminar is optimized for real-time agent observability and debugging complex, multi-step agents. It features a tree/timeline trace explorer, SQL-native data access, and is designed for high-throughput, real-time ingestion.
    • Langfuse is optimized for prompt lifecycle management and prompt-centric iteration. It focuses on structured logs, prompt versioning, and evaluation workflows.

    Choose Laminar if:

    • You are running multi-step agents in production.
    • You require real-time trace visibility and deep tree traversal.
    • You need direct SQL access to your telemetry (traces, spans, events, etc.).
    • You want to use Signals to run queries (prompt + schema) across historical and new traces.

    Choose Langfuse if:

    • You are primarily tracking single LLM calls or short flows.
    • Your core workflow is prompt versioning and caching.
    • You are in an early stage of product development focusing on prompt quality.
  4. Key features of Laminar for agent debugging

    main

    Laminar provides several specialized features for LLM and agent observability:

    • Deep agent debugging: Uses a span-tree structure to enable causal reasoning.
    • Real-time trace visibility: Monitor long-running operations as they happen.
    • Span Replay: Replay from captured spans as a first-class workflow for iteration.
    • Browser-agent session replay: Synchronized session replay tied directly to traces for browser-automation agents.
    • OpenTelemetry support: Native ingestion for existing pipelines.
    • Deployment flexibility: Managed cloud or self-hosted via Docker Compose.
  5. Understand and use Signals for agent observability

    main

    Signals allow you to define specific patterns or behaviors you want to extract from AI agent traces. A signal consists of a name, a prompt (the question you are asking about the trace), and a structured output schema.

    Signals are LLM-extracted and support two primary modes of operation:

    1. Trigger Mode (Real-time Monitoring): Set signals to run against every new incoming trace. This is used to catch critical failures (e.g., tool_call_failure, stuck_loop) and trigger real-time notifications via integrations like Slack.
    2. Backfill Mode (Historical Analysis): Run a signal against existing traces already in your history. This is used to investigate patterns, validate hypotheses, or measure improvements across large datasets (e.g., calculating retrieval_efficiency over the last month of traces).

    Every signal run is logged, allowing you to cluster events to surface patterns, export them to datasets for evaluation, or track metrics over time to catch regressions.

  6. Quickstart: TypeScript SDK

    main

    Install the Laminar TS SDK and instrumentation packages via npm, initialize it with your project API key, and use the observe wrapper to trace function inputs and outputs.

    import { Laminar } from '@lmnr-ai/lmnr';
    import { OpenAI } from 'openai';
    import { observe } from '@lmnr-ai/lmnr';
    
    // Initialize
    Laminar.initialize({ projectApiKey: process.env.LMNR_PROJECT_API_KEY });
    
    const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
    
    // Trace function inputs/outputs
    const poemWriter = observe({name: 'poemWriter'}, async (topic) => {
      const response = await client.chat.completions.create({
        model: "gpt-4o-mini",
        messages: [{ role: "user", content: `write a poem about ${topic}` }],
      });
      return response.choices[0].message.content;
    });
    
    await poemWriter('laminar flow');
  7. Quickstart: Python SDK

    main

    Install the Laminar Python SDK using pip, initialize it with your project API key, and use the @observe() decorator to trace functions.

    import os
    from openai import OpenAI
    from lmnr import observe, Laminar
    
    # Initialize
    Laminar.initialize(project_api_key="<LMNR_PROJECT_API_KEY>")
    
    client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
    
    @observe()  # Decorate functions to trace
    def poem_writer(topic):
        response = client.chat.completions.create(
            model="gpt-4o",
            messages=[
                {"role": "user", "content": f"write a poem about {topic}"},
            ],
        )
        return response.choices[0].message.content
    
    if __name__ == "__main__":
        print(poem_writer(topic="laminar flow"))
  8. Configure app-server environment variables

    main
    The app-server uses environment variables for configuration. You can use the .env.example file as a template. Copy it to a .env file, replace the placeholder URLs with your actual service URLs, and add your required secrets.
  9. Cross-build PII Redactor for different architectures

    main

    The Dockerfile is TARGETARCH-aware and automatically downloads the matching ONNX Runtime build. Use docker buildx to target specific architectures.

    For AWS x86 (amd64):

    docker buildx build --platform linux/amd64 -t lmnr/pii-redactor:latest .

    For ARM64 (e.g., Graviton):

    docker buildx build --platform linux/arm64 -t lmnr/pii-redactor:latest .
  10. Use Laminar Signals for Agent Debugging

    main

    Laminar Signals allow you to define a question using a prompt and a schema, which can then be executed across both real-time and historical traces. This enables:

    • Detecting and alerting on specific failure modes as they occur.
    • Backfilling historical traces to validate new hypotheses.
    • Converting production trace history into labeled datasets without manual scripting.