@anvia/langfuse
v1.2.2
Published
Langfuse tracing adapter for Anvia.
Readme
@anvia/langfuse
Connect Anvia agents to Langfuse for tracing, evaluations, scores, datasets, and prompts. Follow a conversation from model calls to tool results, then use the same traces to evaluate quality.
Installation
pnpm add @anvia/langfuse @anvia/core @anvia/openaiQuick start
Set OPENAI_API_KEY and your LANGFUSE_BASE_URL, LANGFUSE_PUBLIC_KEY, and LANGFUSE_SECRET_KEY.
import { Agent } from "@anvia/core";
import { OpenAIClient } from "@anvia/openai";
import { LangfuseClient } from "@anvia/langfuse";
await using telemetry = new LangfuseClient({
baseUrl: process.env.LANGFUSE_BASE_URL,
publicKey: process.env.LANGFUSE_PUBLIC_KEY,
secretKey: process.env.LANGFUSE_SECRET_KEY,
});
const openai = new OpenAIClient({ apiKey: process.env.OPENAI_API_KEY! });
const agent = new Agent({
id: "support",
model: openai.completionModel({ modelId: "gpt-5", api: "responses" }),
observability: {
observers: { langfuse: telemetry.observer({ captureMode: "safe" }) },
primaryTrace: "langfuse",
},
});
const result = await agent.generate({ prompt: "How do refunds work?" });
if (result.type === "response") {
console.log(result.output);
console.log(result.trace);
}What you get
- Agent tracing with configurable capture and redaction.
- Evaluation reporting and dataset experiments.
- Trace-correlated scores and evaluation results.
- Dataset access and reusable prompts.
- Isolated telemetry providers with explicit flush and cleanup.
captureMode: "safe" omits prompt and response bodies. Keep the client alive while agents run; await using flushes and closes it at scope exit. See the guide for redaction and graceful server shutdown.
