Skip to content

LangfuseEvaluationScoreExtensions

NexusLabs.Needlr.AgentFramework.Langfuse

LangfuseEvaluationScoreExtensions Class

Convenience extensions for projecting Microsoft.Extensions.AI.Evaluation results onto a Langfuse scenario trace as scores.

public static class LangfuseEvaluationScoreExtensions

Inheritance System.Object 🡒 LangfuseEvaluationScoreExtensions

Methods

LangfuseEvaluationScoreExtensions.EvaluateAndRecordAsync(this ILangfuseScenario, IEnumerable<IEvaluator>, IEnumerable<ChatMessage>, ChatResponse, ChatConfiguration, IEnumerable<EvaluationContext>, CancellationToken) Method

Runs each evaluator over the supplied agent output and records every resulting metric as a Langfuse score on the scenario's trace. Collapses the per-test evaluate-then-record boilerplate into one call.

public static System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyList<Microsoft.Extensions.AI.Evaluation.EvaluationResult>> EvaluateAndRecordAsync(this NexusLabs.Needlr.AgentFramework.Langfuse.ILangfuseScenario scenario, System.Collections.Generic.IEnumerable<Microsoft.Extensions.AI.Evaluation.IEvaluator> evaluators, System.Collections.Generic.IEnumerable<Microsoft.Extensions.AI.ChatMessage> messages, Microsoft.Extensions.AI.ChatResponse modelResponse, Microsoft.Extensions.AI.Evaluation.ChatConfiguration? chatConfiguration=null, System.Collections.Generic.IEnumerable<Microsoft.Extensions.AI.Evaluation.EvaluationContext>? additionalContext=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

scenario ILangfuseScenario

The scenario whose trace the scores attach to.

evaluators System.Collections.Generic.IEnumerable<Microsoft.Extensions.AI.Evaluation.IEvaluator>

The evaluators to run.

messages System.Collections.Generic.IEnumerable<Microsoft.Extensions.AI.ChatMessage>

The conversation messages sent to the agent (for example, from EvaluationInputs.Messages).

modelResponse Microsoft.Extensions.AI.ChatResponse

The agent's response (for example, from EvaluationInputs.ModelResponse).

chatConfiguration Microsoft.Extensions.AI.Evaluation.ChatConfiguration

Optional chat configuration for LLM-judged evaluators.

additionalContext System.Collections.Generic.IEnumerable<Microsoft.Extensions.AI.Evaluation.EvaluationContext>

Optional additional context (for example, AgentRunDiagnosticsContext).

cancellationToken System.Threading.CancellationToken

A cancellation token.

Returns

System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyList<Microsoft.Extensions.AI.Evaluation.EvaluationResult>>
The evaluation results, in evaluator order.

Exceptions

System.ArgumentNullException
scenario, evaluators, messages, or modelResponse is null.

LangfuseEvaluationScoreExtensions.RecordLangfuseScoresAsync(this EvaluationResult, ILangfuseScenario, CancellationToken) Method

Records every metric in result as a Langfuse score on scenario's trace. Equivalent to RecordEvaluationAsync(EvaluationResult, CancellationToken), provided as a fluent call site for eval code that already holds an Microsoft.Extensions.AI.Evaluation.EvaluationResult.

public static System.Threading.Tasks.Task RecordLangfuseScoresAsync(this Microsoft.Extensions.AI.Evaluation.EvaluationResult result, NexusLabs.Needlr.AgentFramework.Langfuse.ILangfuseScenario scenario, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

result Microsoft.Extensions.AI.Evaluation.EvaluationResult

The evaluation result to project.

scenario ILangfuseScenario

The scenario whose trace the scores attach to.

cancellationToken System.Threading.CancellationToken

A cancellation token.

Returns

System.Threading.Tasks.Task
A task that completes when Langfuse has accepted all projected scores.

Exceptions

System.ArgumentNullException
result or scenario is null.