ILangfuseScenario
NexusLabs.Needlr.AgentFramework.Langfuse¶
ILangfuseScenario Interface¶
Represents a single Langfuse trace scoped to one eval scenario or agent run. Created via BeginScenario(string, string, string, IEnumerable<string>, IReadOnlyDictionary<string,string>).
Implements System.IDisposable
Remarks¶
Beginning a scenario starts a root OpenTelemetry span carrying Langfuse trace-level attributes (name, session id, user id, tags, metadata). Agent telemetry produced while the scenario is active nests under this trace. Disposing the scenario ends the root span.
Evaluation scores are attached to the scenario's trace through the Langfuse Scores API, keyed by TraceId. Because Langfuse links scores to traces asynchronously, scores may be recorded while the scenario is still open.
Properties¶
ILangfuseScenario.Activity Property¶
Gets the root Activity for this scenario, or null when the owning session is disabled or no listener is sampling the span.
Property Value¶
ILangfuseScenario.TraceId Property¶
Gets the Langfuse trace id (the lowercase-hex OpenTelemetry trace id) for this scenario, or null when the owning session is disabled.
Property Value¶
Methods¶
ILangfuseScenario.RecordEvaluationAsync(EvaluationResult, CancellationToken) Method¶
Projects every metric in a Microsoft.Extensions.AI.Evaluation.EvaluationResult to a Langfuse score on this scenario's trace. Numeric metrics become numeric scores, boolean metrics become boolean scores, and string metrics become categorical scores. Each metric's reason is sent as the score comment. Metrics whose value is unset are skipped.
System.Threading.Tasks.Task RecordEvaluationAsync(Microsoft.Extensions.AI.Evaluation.EvaluationResult result, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));
Parameters¶
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.
ILangfuseScenario.RecordScoreAsync(string, bool, string, CancellationToken) Method¶
Records a boolean score (stored as 1/0) on this scenario's trace.
System.Threading.Tasks.Task RecordScoreAsync(string name, bool value, string? comment=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));
Parameters¶
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.
ILangfuseScenario.RecordScoreAsync(string, double, string, CancellationToken) Method¶
Records a numeric score on this scenario's trace.
System.Threading.Tasks.Task RecordScoreAsync(string name, double value, string? comment=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));
Parameters¶
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.
ILangfuseScenario.RecordScoreAsync(string, string, string, CancellationToken) Method¶
Records a categorical score on this scenario's trace.
System.Threading.Tasks.Task RecordScoreAsync(string name, string value, string? comment=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));
Parameters¶
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.