Skip to content

ILangfuseScoreClient

NexusLabs.Needlr.AgentFramework.Langfuse

ILangfuseScoreClient Interface

Records Langfuse scores against a known trace id. Registered in dependency injection by AddNeedlrLangfuse(this IServiceCollection, Action<LangfuseOptions>) for ASP.NET Core and generic-host applications that score their own request traces.

public interface ILangfuseScoreClient

Remarks

In a host application the OTLP exporter assigns each operation an OpenTelemetry trace id (Activity.Current?.TraceId). Pass that id here to attach evaluation scores to the corresponding Langfuse trace. For the eval/console flow, prefer BeginScenario(string, string, string, IEnumerable<string>, IReadOnlyDictionary<string,string>), which manages the trace for you.

Properties

ILangfuseScoreClient.IsEnabled Property

Gets a value indicating whether scores are being sent. false when Langfuse was not configured, in which case all record calls are no-ops.

bool IsEnabled { get; }

Property Value

System.Boolean

ILangfuseScoreClient.ScoresFailed Property

Gets the cumulative number of score uploads that have failed.

int ScoresFailed { get; }

Property Value

System.Int32

Methods

ILangfuseScoreClient.RecordEvaluationAsync(string, EvaluationResult, CancellationToken) Method

Projects every metric in result to a Langfuse score against traceId, using the same mapping as RecordEvaluationAsync(EvaluationResult, CancellationToken).

System.Threading.Tasks.Task RecordEvaluationAsync(string traceId, Microsoft.Extensions.AI.Evaluation.EvaluationResult result, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

traceId System.String

The Langfuse/OpenTelemetry trace id to attach the scores to.

result Microsoft.Extensions.AI.Evaluation.EvaluationResult

The evaluation result to project.

cancellationToken System.Threading.CancellationToken

A cancellation token.

Returns

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

ILangfuseScoreClient.RecordObservationScoreAsync(string, string, string, bool, string, CancellationToken) Method

Records a boolean score (stored as 1/0) against a specific observation.

System.Threading.Tasks.Task RecordObservationScoreAsync(string traceId, string observationId, string name, bool value, string? comment=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

traceId System.String

The owning trace id.

observationId System.String

The observation id to attach the score to.

name System.String

The score name.

value System.Boolean

The boolean value.

comment System.String

An optional explanation surfaced in Langfuse.

cancellationToken System.Threading.CancellationToken

A cancellation token.

Returns

System.Threading.Tasks.Task
A task that completes when Langfuse has accepted the score.

ILangfuseScoreClient.RecordObservationScoreAsync(string, string, string, double, string, CancellationToken) Method

Records a numeric score against a specific observation within a trace.

System.Threading.Tasks.Task RecordObservationScoreAsync(string traceId, string observationId, string name, double value, string? comment=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

traceId System.String

The owning trace id.

observationId System.String

The observation (span/generation) id to attach the score to.

name System.String

The score name.

value System.Double

The numeric value.

comment System.String

An optional explanation surfaced in Langfuse.

cancellationToken System.Threading.CancellationToken

A cancellation token.

Returns

System.Threading.Tasks.Task
A task that completes when Langfuse has accepted the score.

ILangfuseScoreClient.RecordObservationScoreAsync(string, string, string, string, string, CancellationToken) Method

Records a categorical score against a specific observation.

System.Threading.Tasks.Task RecordObservationScoreAsync(string traceId, string observationId, string name, string value, string? comment=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

traceId System.String

The owning trace id.

observationId System.String

The observation id to attach the score to.

name System.String

The score name.

value System.String

The category label.

comment System.String

An optional explanation surfaced in Langfuse.

cancellationToken System.Threading.CancellationToken

A cancellation token.

Returns

System.Threading.Tasks.Task
A task that completes when Langfuse has accepted the score.

ILangfuseScoreClient.RecordScoreAsync(string, string, bool, string, CancellationToken) Method

Records a boolean score (stored as 1/0) against traceId.

System.Threading.Tasks.Task RecordScoreAsync(string traceId, string name, bool value, string? comment=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

traceId System.String

The Langfuse/OpenTelemetry trace id to attach the score to.

name System.String

The score name.

value System.Boolean

The boolean value.

comment System.String

An optional explanation surfaced in Langfuse.

cancellationToken System.Threading.CancellationToken

A cancellation token.

Returns

System.Threading.Tasks.Task
A task that completes when Langfuse has accepted the score.

ILangfuseScoreClient.RecordScoreAsync(string, string, double, string, CancellationToken) Method

Records a numeric score against traceId.

System.Threading.Tasks.Task RecordScoreAsync(string traceId, string name, double value, string? comment=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

traceId System.String

The Langfuse/OpenTelemetry trace id to attach the score to.

name System.String

The score name.

value System.Double

The numeric value.

comment System.String

An optional explanation surfaced in Langfuse.

cancellationToken System.Threading.CancellationToken

A cancellation token.

Returns

System.Threading.Tasks.Task
A task that completes when Langfuse has accepted the score.

ILangfuseScoreClient.RecordScoreAsync(string, string, string, string, CancellationToken) Method

Records a categorical score against traceId.

System.Threading.Tasks.Task RecordScoreAsync(string traceId, string name, string value, string? comment=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

traceId System.String

The Langfuse/OpenTelemetry trace id to attach the score to.

name System.String

The score name.

value System.String

The category label.

comment System.String

An optional explanation surfaced in Langfuse.

cancellationToken System.Threading.CancellationToken

A cancellation token.

Returns

System.Threading.Tasks.Task
A task that completes when Langfuse has accepted the score.

ILangfuseScoreClient.RecordSessionScoreAsync(string, string, bool, string, CancellationToken) Method

Records a boolean session score (stored as 1/0).

System.Threading.Tasks.Task RecordSessionScoreAsync(string sessionId, string name, bool value, string? comment=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

sessionId System.String

The session id to attach the score to.

name System.String

The score name.

value System.Boolean

The boolean value.

comment System.String

An optional explanation surfaced in Langfuse.

cancellationToken System.Threading.CancellationToken

A cancellation token.

Returns

System.Threading.Tasks.Task
A task that completes when Langfuse has accepted the score.

ILangfuseScoreClient.RecordSessionScoreAsync(string, string, double, string, CancellationToken) Method

Records a numeric score against a whole session (across its traces).

System.Threading.Tasks.Task RecordSessionScoreAsync(string sessionId, string name, double value, string? comment=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

sessionId System.String

The session id to attach the score to.

name System.String

The score name.

value System.Double

The numeric value.

comment System.String

An optional explanation surfaced in Langfuse.

cancellationToken System.Threading.CancellationToken

A cancellation token.

Returns

System.Threading.Tasks.Task
A task that completes when Langfuse has accepted the score.

ILangfuseScoreClient.RecordSessionScoreAsync(string, string, string, string, CancellationToken) Method

Records a categorical session score.

System.Threading.Tasks.Task RecordSessionScoreAsync(string sessionId, string name, string value, string? comment=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

sessionId System.String

The session id to attach the score to.

name System.String

The score name.

value System.String

The category label.

comment System.String

An optional explanation surfaced in Langfuse.

cancellationToken System.Threading.CancellationToken

A cancellation token.

Returns

System.Threading.Tasks.Task
A task that completes when Langfuse has accepted the score.