< Summary

Information
Class: NexusLabs.Needlr.AgentFramework.Workflows.Sequential.AgentStageExecutor
Assembly: NexusLabs.Needlr.AgentFramework.Workflows
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework.Workflows/Sequential/AgentStageExecutor.cs
Line coverage
50%
Covered lines: 6
Uncovered lines: 6
Coverable lines: 12
Total lines: 53
Line coverage: 50%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
ExecuteAsync()100%210%

File(s)

/home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework.Workflows/Sequential/AgentStageExecutor.cs

#LineLine coverage
 1using Microsoft.Agents.AI;
 2
 3namespace NexusLabs.Needlr.AgentFramework.Workflows.Sequential;
 4
 5/// <summary>
 6/// Executes a pipeline stage by running an <see cref="AIAgent"/> with a
 7/// dynamically constructed prompt.
 8/// </summary>
 9/// <example>
 10/// <code>
 11/// var executor = new AgentStageExecutor(
 12///     writerAgent,
 13///     ctx => $"Write a draft about topic in workspace.");
 14///
 15/// var result = await executor.ExecuteAsync(context, cancellationToken);
 16/// Console.WriteLine(result.ResponseText);
 17/// </code>
 18/// </example>
 19[DoNotAutoRegister]
 20public sealed class AgentStageExecutor : IStageExecutor
 21{
 22    private readonly AIAgent _agent;
 23    private readonly Func<StageExecutionContext, string> _promptFactory;
 24
 25    /// <summary>
 26    /// Initializes a new <see cref="AgentStageExecutor"/>.
 27    /// </summary>
 28    /// <param name="agent">The AI agent to execute.</param>
 29    /// <param name="promptFactory">
 30    /// Factory that produces the prompt string from the current stage context.
 31    /// </param>
 3032    public AgentStageExecutor(
 3033        AIAgent agent,
 3034        Func<StageExecutionContext, string> promptFactory)
 35    {
 3036        _agent = agent;
 3037        _promptFactory = promptFactory;
 3038    }
 39
 40    /// <inheritdoc />
 41    public async Task<StageExecutionResult> ExecuteAsync(
 42        StageExecutionContext context,
 43        CancellationToken cancellationToken)
 44    {
 045        var prompt = _promptFactory(context);
 046        using (context.DiagnosticsAccessor.BeginCapture())
 47        {
 048            var response = await _agent.RunAsync(prompt, cancellationToken: cancellationToken);
 049            var diagnostics = context.DiagnosticsAccessor.LastRunDiagnostics;
 050            return StageExecutionResult.Success(context.StageName, diagnostics, response.GetText());
 51        }
 052    }
 53}