Langfuse

Use Langfuse observability with PraisonAI TypeScript

Diagram

Input

Agent

Output

Langfuse Observability

Production observability with Langfuse.

Environment Variables

bash
export LANGFUSE_SECRET_KEY=sk-lf-...
export LANGFUSE_PUBLIC_KEY=pk-lf-...
export LANGFUSE_HOST=https://cloud.langfuse.com  # optional
VariableRequiredDescription
LANGFUSE_SECRET_KEYYesLangfuse secret key
LANGFUSE_PUBLIC_KEYYesLangfuse public key
LANGFUSE_HOSTNoCustom Langfuse host

Features

FeatureSupported
Traces✅
Spans✅
Events✅
Errors✅
Metrics✅
Export✅

Quick Start

  1. Simple Usage
    typescript
    import { Agent, setObservabilityAdapter } from 'praisonai';
    import { LangfuseObservabilityAdapter } from 'praisonai/observability';
    
    // Initialize Langfuse adapter
    const obs = new LangfuseObservabilityAdapter();
    await obs.initialize();
    setObservabilityAdapter(obs);
    
    // Create agent with tracing
    const agent = new Agent({
      name: 'TracedAgent',
      instructions: 'You are a helpful assistant.',
      llm: 'openai/gpt-4o-mini'
    });
    
    // Run with automatic tracing
    const response = await agent.chat('Hello!');
    
    // Flush traces to Langfuse
    await obs.flush();
  2. With Configuration

    Adjust observability adapter options and agent settings for production — see the sections above.

Multi-Agent Tracing

typescript
import { Agent, Agents, setObservabilityAdapter } from 'praisonai';
import { LangfuseObservabilityAdapter } from 'praisonai/observability';

const obs = new LangfuseObservabilityAdapter();
await obs.initialize();
setObservabilityAdapter(obs);

const researcher = new Agent({
  name: 'Researcher',
  instructions: 'Research topics.',
  llm: 'openai/gpt-4o'
});

const writer = new Agent({
  name: 'Writer',
  instructions: 'Write summaries.',
  llm: 'openai/gpt-4o-mini'
});

const agents = new AgentTeam({
  agents: [researcher, writer],
  tasks: [
    { agent: researcher, description: 'Research {topic}' },
    { agent: writer, description: 'Summarize findings' }
  ]
});

await agents.start({ topic: 'AI trends' });
await obs.flush();

Troubleshooting

Missing API Keys

Error: Langfuse SDK not available

Solution: Set both LANGFUSE_SECRET_KEY and LANGFUSE_PUBLIC_KEY.

Traces Not Appearing

Solution: Ensure you call await obs.flush() before the process exits.

Related