@anvia/langfuse
v0.1.5
Published
Langfuse tracing adapter for Anvia.
Readme
@anvia/langfuse
Langfuse tracing adapter for Anvia.
Use this package to attach Langfuse tracing to Anvia agents and to publish evaluation scores from Anvia eval reporters.
Installation
pnpm add @anvia/langfuse @anvia/coreIn this monorepo, the package is available through the workspace:
pnpm --filter @anvia/langfuse buildUsage
import { AgentBuilder } from "@anvia/core";
import { OpenAIClient } from "@anvia/openai";
import { langfuse } from "@anvia/langfuse";
const tracing = langfuse.create({
publicKey,
secretKey,
baseUrl,
environment,
release,
});
const client = new OpenAIClient({
apiKey,
});
const agent = new AgentBuilder("support", client.completionModel())
.instructions("Answer support questions clearly.")
.observe(tracing)
.build();
const response = await agent.prompt("How do I reset my password?").send();
console.log(response.output);
await tracing.flush();Use flush() after short-lived jobs. Use shutdown() when the process is exiting.
Eval Scores
import { createLangfuseEvalReporter } from "@anvia/langfuse";
const reporter = createLangfuseEvalReporter(tracing);The reporter reads trace information from eval output when available, then publishes metric scores to Langfuse.
Exports
langfusecreateLangfuseEvalReporterLangfuseTracingLangfuseTracingOptionsLangfuseScoreArgsLangfuseEvalReporterOptions
Development
pnpm --filter @anvia/langfuse typecheck
pnpm --filter @anvia/langfuse test
pnpm --filter @anvia/langfuse build