agentskit.js
Packages

@agentskit/observability-langfuse

Langfuse tracing backend for @agentskit/observability — spans for plan, tool, model, and HITL gates with token/cost/latency capture.

@agentskit/observability-langfuse is a drop-in observer that ships AgentsKit trace spans to Langfuse. LLM generations become generation nodes; tool calls, planning steps, and HITL gates become span nodes. Token usage and error state are captured on each node end.

The langfuse npm package is an optional peer — loaded dynamically at runtime. If it is absent or no API keys are provided, the observer is a no-op and does not throw.

#When to reach for it

  • You already use Langfuse for prompt management, user feedback, or cost analytics.
  • You want per-session or per-user trace grouping without manual instrumentation.
  • You want token + cost tracking in the Langfuse UI alongside your AgentsKit runs.

#Best fit

  • Add alongside consoleLogger or opentelemetry — observers compose and do not conflict.
  • Pair with @agentskit/eval to turn Langfuse trace failures into repeatable eval cases.
  • Pair with @agentskit/runtime to trace multi-step agent workflows end-to-end.

#Install

npm install @agentskit/observability-langfuse
# peer deps
npm install @agentskit/observability langfuse

#Hello world

import { langfuse } from '@agentskit/observability-langfuse'
import { createRuntime } from '@agentskit/runtime'

const runtime = createRuntime({
  adapter,
  observers: [langfuse()],
})

Keys are read from LANGFUSE_PUBLIC_KEY and LANGFUSE_SECRET_KEY env vars. No config object required for the common case.

#Public API

#langfuse(config?): Observer

Config fieldTypeDefaultNotes
publicKeystring?LANGFUSE_PUBLIC_KEY envLangfuse project public key
secretKeystring?LANGFUSE_SECRET_KEY envLangfuse project secret key
baseUrlstring?LANGFUSE_HOST env, then https://cloud.langfuse.comSelf-hosted base URL
releasestring?LANGFUSE_RELEASE envDeployment release tag
environmentstring?LANGFUSE_ENVIRONMENT enve.g. production, staging
sessionIdstring?Groups traces into a Langfuse session
userIdstring?Associates traces with a Langfuse user
tagsstring[]?Arbitrary trace tags
flushAtnumber?15Batch size before auto-flush
flushIntervalnumber?1000Auto-flush interval in ms

Returns an Observer that can be passed directly to observers in createRuntime, useChat, or any other AgentsKit entry point that accepts observers.

#LangfuseConfig

Named export — the type of the config object above. Useful when building helper factories.

#Per-session tracing

import { langfuse } from '@agentskit/observability-langfuse'

// One observer instance per request / conversation to isolate sessions.
const observer = langfuse({
  sessionId: req.sessionId,
  userId: req.user.id,
  tags: ['support-bot', 'v2'],
})

const runtime = createRuntime({ adapter, observers: [observer] })

#Self-hosted Langfuse

langfuse({
  baseUrl: 'https://langfuse.internal.example.com',
  publicKey: process.env.LF_PUBLIC_KEY,
  secretKey: process.env.LF_SECRET_KEY,
})

#Configuration

Env varPurpose
LANGFUSE_PUBLIC_KEYLangfuse project public key (client-safe)
LANGFUSE_SECRET_KEYLangfuse project secret key (server only)
LANGFUSE_HOSTSelf-hosted base URL; defaults to Langfuse cloud
LANGFUSE_RELEASERelease tag attached to every trace
LANGFUSE_ENVIRONMENTEnvironment tag (e.g. production)

Explicit config fields always take precedence over env vars.

#Stability

  • Version: 0.1.0
  • Tier: beta
  • Contract: Observer interface stable; Langfuse SDK peer-resolved at runtime.

#Source

npm: @agentskit/observability-langfuse · repo: packages/observability-langfuse

Explore nearby

✎ Edit this page on GitHub·Found a problem? Open an issue →·How to contribute →

On this page