Documentation
¶
Overview ¶
Package langfuse provides observability and tracing for LLM interactions via the Langfuse service.
It solves the problem of capturing traces, spans, and generations for Genie's agent runs so that teams can debug, monitor, and analyze LLM usage in one place. When configured (LANGFUSE_* credentials), the package exports traces to Langfuse and can optionally sync prompt definitions. Without it, debugging agent behavior would rely solely on local logs and audit files.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AgentUsageStats ¶ added in v0.1.7
type AgentUsageStats struct {
// AgentName is the trace name (i.e. the agent identifier) in Langfuse.
AgentName string `json:"agent_name"`
// TotalCost is the total cost in USD for all observations belonging to
// this agent's traces within the queried time window.
TotalCost float64 `json:"total_cost"`
// InputTokens is the sum of input tokens consumed across all observations.
InputTokens float64 `json:"input_tokens"`
// OutputTokens is the sum of output tokens produced across all observations.
OutputTokens float64 `json:"output_tokens"`
// TotalTokens is the sum of all tokens consumed across all observations.
TotalTokens float64 `json:"total_tokens"`
// Count is the total number of observations for this agent.
Count float64 `json:"count"`
}
AgentUsageStats holds the aggregated token usage and cost statistics for a single agent within a given time window. Without this type, callers would have to parse raw Langfuse API responses and perform their own aggregation, which is error-prone and duplicated across consumers.
func GetAgentStats ¶ added in v0.1.7
func GetAgentStats(ctx context.Context, req GetAgentStatsRequest) ([]AgentUsageStats, error)
GetAgentStats delegates to the global defaultClient's GetAgentStats. Returns nil, nil when no client is configured (callers should handle accordingly). Exists to allow callers to get per-agent usage stats without managing their own Client instance.
type Client ¶
type Client interface {
// GetPrompt returns the prompt template by name, or the default if not found/disabled.
GetPrompt(ctx context.Context, name, defaultPrompt string) string
// GetAgentStats returns aggregated token usage and cost statistics per
// agent (trace name) for the duration specified in the request. Without
// this method, consumers would need to call the Langfuse metrics API
// directly, duplicating auth and parsing logic.
GetAgentStats(ctx context.Context, req GetAgentStatsRequest) ([]AgentUsageStats, error)
}
Client defines the interface for interacting with the Langfuse API, including prompt management and usage metrics retrieval.
type Config ¶
type Config struct {
PublicKey string `json:"public_key" toml:"public_key,omitempty" yaml:"public_key,omitempty"`
SecretKey string `json:"secret_key" toml:"secret_key,omitempty" yaml:"secret_key,omitempty"`
Host string `json:"host" toml:"host,omitempty" yaml:"host,omitempty"`
EnablePrompts bool `json:"enable_prompts" toml:"enable_prompts,omitempty" yaml:"enable_prompts,omitempty"`
}
Config holds the configuration for the Langfuse integration, which provides observability and tracing for LLM interactions.
func DefaultConfig ¶
func DefaultConfig(ctx context.Context, sp security.SecretProvider) Config
DefaultConfig builds the default Langfuse configuration by resolving credentials through the given SecretProvider. Without a SecretProvider, callers can pass security.NewEnvProvider() to preserve the legacy os.Getenv behavior.
type GetAgentStatsRequest ¶ added in v0.1.7
type GetAgentStatsRequest struct {
// Duration is the lookback period from now (e.g. 24h, 7*24h).
Duration time.Duration
// AgentName optionally restricts the query to a single agent.
// When empty, stats for all agents are returned.
AgentName string
}
GetAgentStatsRequest encapsulates the parameters for querying agent-level usage statistics from Langfuse. The Duration field specifies the lookback window from the current time. An optional AgentName can filter results to a single agent.