environment-setup-guide
Guide developers through setting up development environments with proper tools, dependencies, and configurations
langfuse-core-workflow-a
Execute Langfuse primary workflow: Tracing LLM calls and spans. Use when implementing LLM tracing, building traced AI features, or adding observability to existing LLM applications. Trigger with phrases like "langfuse tracing", "trace LLM calls", "add langfuse to openai", "langfuse spans", "track...
Full skill instructions
Primary workflow for Langfuse: end-to-end tracing of LLM calls, chains, and agents.
langfuse-install-auth setupimport { observeOpenAI } from "langfuse";
import OpenAI from "openai";
// Wrap OpenAI client for automatic tracing
const openai = observeOpenAI(new OpenAI());
// All calls are now automatically traced
const response = await openai.chat.completions.create({
model: "gpt-4",
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "What is Langfuse?" },
],
});
import { Langfuse } from "langfuse";
const langfuse = new Langfuse();
async function ragPipeline(query: string) {
// Create top-level trace
const trace = langfuse.trace({
name: "rag-pipeline",
input: { query },
metadata: { pipeline: "rag-v1" },
});
// Span: Query embedding
const embedSpan = trace.span({
name: "embed-query",
input: { text: query },
});
const queryEmbedding = await embedText(query);
embedSpan.end({
output: { dimensions: queryEmbedding.length },
metadata: { model: "text-embedding-ada-002" },
});
// Span: Vector search
const searchSpan = trace.span({
name: "vector-search",
input: { embedding: "vector[1536]" },
});
const documents = await searchVectorDB(queryEmbedding);
searchSpan.end({
output: {
documentCount: documents.length,
topScore: documents[0]?.score,
},
});
// Generation: LLM call with context
const generation = trace.generation({
name: "generate-answer",
model: "gpt-4",
modelParameters: { temperature: 0.7, maxTokens: 500 },
input: {
query,
context: documents.map((d) => d.content),
},
});
const answer = await generateAnswer(query, documents);
generation.end({
output: answer.content,
usage: {
promptTokens: answer.usage.prompt_tokens,
completionTokens: answer.usage.completion_tokens,
totalTokens: answer.usage.total_tokens,
},
});
// Update trace with final output
trace.update({
output: { answer: answer.content },
});
return answer.content;
}
async function streamingChat(messages: ChatMessage[]) {
const trace = langfuse.trace({
name: "streaming-chat",
input: { messages },
});
const generation = trace.generation({
name: "stream-response",
model: "gpt-4",
input: messages,
});
const stream = await openai.chat.completions.create({
model: "gpt-4",
messages,
stream: true,
});
let fullContent = "";
let usage = { promptTokens: 0, completionTokens: 0 };
for await (const chunk of stream) {
const content = chunk.choices[0]?.delta?.content || "";
fullContent += content;
// Track usage from final chunk
if (chunk.usage) {
usage = {
promptTokens: chunk.usage.prompt_tokens,
completionTokens: chunk.usage.completion_tokens,
};
}
yield content;
}
// End generation after stream completes
generation.end({
output: fullContent,
usage,
});
trace.update({ output: { response: fullContent } });
}
// API endpoint that creates parent trace
async function handleChatRequest(req: Request) {
const trace = langfuse.trace({
name: "api/chat",
userId: req.userId,
sessionId: req.sessionId,
input: req.body,
});
// Pass trace to child operations
const response = await processChat(trace, req.body.message);
return response;
}
// Child function receives parent trace
async function processChat(
parentTrace: ReturnType<typeof langfuse.trace>,
message: string
) {
// Create child span under parent trace
const span = parentTrace.span({
name: "process-chat",
input: { message },
});
// OpenAI call linked to parent
const response = await openai.chat.completions.create(
{
model: "gpt-4",
messages: [{ role: "user", content: message }],
},
{ langfuseParent: span } // Link generation to span
);
span.end({ output: response.choices[0].message });
return response.choices[0].message.content;
}
| Issue | Cause | Solution |
|---|---|---|
| Missing generations | Wrapper not applied | Use observeOpenAI() wrapper |
| Orphaned spans | Missing .end() call | Always end spans in finally block |
| No token usage | Stream without usage | Use stream_options: {include_usage: true} |
| Broken hierarchy | Missing parent link | Pass langfuseParent option |
import Anthropic from "@anthropic-ai/sdk";
import { Langfuse } from "langfuse";
const anthropic = new Anthropic();
const langfuse = new Langfuse();
async function callClaude(prompt: string) {
const trace = langfuse.trace({ name: "claude-call", input: { prompt } });
const generation = trace.generation({
name: "claude-response",
model: "claude-3-sonnet-20240229",
input: [{ role: "user", content: prompt }],
});
const response = await anthropic.messages.create({
model: "claude-3-sonnet-20240229",
max_tokens: 1024,
messages: [{ role: "user", content: prompt }],
});
generation.end({
output: response.content[0].text,
usage: {
promptTokens: response.usage.input_tokens,
completionTokens: response.usage.output_tokens,
},
});
return response.content[0].text;
}
from langchain.callbacks import LangfuseCallbackHandler
from langchain.chat_models import ChatOpenAI
from langchain.schema import HumanMessage
# Create callback handler
langfuse_handler = LangfuseCallbackHandler()
# Pass to LLM
llm = ChatOpenAI(callbacks=[langfuse_handler])
# All LangChain operations are now traced
response = llm([HumanMessage(content="Hello!")])
async function tracedToolCall(trace: Trace, toolName: string, args: any) {
const span = trace.span({
name: `tool/${toolName}`,
input: args,
metadata: { type: "tool-call" },
});
try {
const result = await executeTool(toolName, args);
span.end({ output: result });
return result;
} catch (error) {
span.end({
level: "ERROR",
statusMessage: String(error),
});
throw error;
}
}
For evaluation and scoring workflows, see langfuse-core-workflow-b.
Guide developers through setting up development environments with proper tools, dependencies, and configurations
Implement Exa lint rules, policy enforcement, and automated guardrails. Use when setting up code quality rules for Exa integrations, implementing pre-commit hooks, or configuring CI policy checks for Exa best practices. Trigger with phrases like "exa policy", "exa lint", "exa guardrails", "exa be...
Configure CI/CD pipelines for Documenso integrations. Use when setting up automated testing, deployment pipelines, or continuous integration for Documenso projects. Trigger with phrases like "documenso CI", "documenso GitHub Actions", "documenso pipeline", "documenso automated testing".
Build check model availability and implement fallback chains. Use when building resilient systems or handling model outages. Trigger with phrases like 'openrouter availability', 'openrouter fallback', 'openrouter model down', 'openrouter health check'.
Configure Langfuse enterprise organization management and access control. Use when implementing team access controls, configuring organization settings, or setting up role-based permissions for Langfuse projects. Trigger with phrases like "langfuse RBAC", "langfuse teams", "langfuse organization"...
Execute compliance and security auditing for Cursor usage. Triggers on "cursor compliance", "cursor audit", "cursor security review", "cursor soc2", "cursor gdpr". Use when analyzing or auditing cursor compliance audit. Trigger with phrases like "cursor compliance audit", "cursor audit", "cursor".
Configure Apollo.io CI/CD integration. Use when setting up automated testing, continuous integration, or deployment pipelines for Apollo integrations. Trigger with phrases like "apollo ci", "apollo github actions", "apollo pipeline", "apollo ci/cd", "apollo automated tests".
Create robust Python automation with full logging and safety checks. Use when tasks need complex data processing, authenticated API work, conditional file operations, or error handling beyond simple shell commands.
Configure PostHog across development, staging, and production environments. Use when setting up multi-environment deployments, configuring per-environment secrets, or implementing environment-specific PostHog configurations. Trigger with phrases like "posthog environments", "posthog staging", "po...
Expert in designing and building autonomous AI agents. Masters tool use, memory systems, planning strategies, and multi-agent orchestration. Use when: build agent, AI agent, autonomous agent, tool use, function calling.
Validate insecure deserialization checker operations. Auto-activating skill for Security Fundamentals. Triggers on: insecure deserialization checker, insecure deserialization checker Part of the Security Fundamentals skill category. Use when working with insecure deserialization checker functiona...
Manage path traversal finder operations. Auto-activating skill for Security Fundamentals. Triggers on: path traversal finder, path traversal finder Part of the Security Fundamentals skill category. Use when working with path traversal finder functionality. Trigger with phrases like "path traversa...
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience