Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public class HandoffWorkflowBuilderCore<TBuilder> where TBuilder : HandoffWorkfl
private bool _emitAgentResponseUpdateEvents;
private HandoffToolCallFilteringBehavior _toolCallFilteringBehavior = HandoffToolCallFilteringBehavior.HandoffOnly;
private bool _returnToPrevious;
private string? _name;
private string? _description;

/// <summary>
/// Initializes a new instance of the <see cref="HandoffsWorkflowBuilder"/> class with no handoff relationships.
Expand Down Expand Up @@ -97,6 +99,20 @@ public TBuilder WithHandoffInstructions(string? instructions)
return (TBuilder)this;
}

/// <inheritdoc cref="WorkflowBuilder.WithName(string)"/>
public TBuilder WithName(string name)
{
this._name = name;
return (TBuilder)this;
}

/// <inheritdoc cref="WorkflowBuilder.WithDescription(string)"/>
public TBuilder WithDescription(string description)
{
this._description = description;
return (TBuilder)this;
}

/// <summary>
/// Sets a value indicating whether agent streaming update events should be emitted during execution.
/// If <see langword="null"/>, the value will be taken from the <see cref="TurnToken"/>
Expand Down Expand Up @@ -330,7 +346,16 @@ public Workflow Build()
builder.AddEdge(start, executors[this._initialAgent.Id]);
}

// Build the workflow.
if (!string.IsNullOrWhiteSpace(this._name))
{
builder.WithName(this._name);
}

if (!string.IsNullOrWhiteSpace(this._description))
{
builder.WithDescription(this._description);
}

return builder.WithOutputFrom(end).Build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,30 @@ public void AddWorkflow_MultipleCalls_RegistersMultipleWorkflows()
Assert.Contains(workflowDescriptors, d => (string)d.ServiceKey! == "workflow3");
}

/// <summary>
/// Verifies that a handoff workflow can be named from the DI workflow key.
/// </summary>
[Fact]
public void AddWorkflow_HandoffWorkflowWithName_ResolvesWorkflow()
{
var builder = new HostApplicationBuilder();
const string WorkflowName = "handoffWorkflow";

var mockAgent = new Mock<AIAgent>();
mockAgent.Setup(a => a.Name).Returns("handoffAgent");

#pragma warning disable MAAIW001 // This test covers hosting handoff workflows.
builder.AddWorkflow(WorkflowName, (sp, key) =>
AgentWorkflowBuilder.CreateHandoffBuilderWith(mockAgent.Object)
.WithName(key)
.Build());
#pragma warning restore MAAIW001

var workflow = builder.Build().Services.GetRequiredKeyedService<Workflow>(WorkflowName);

Assert.Equal(WorkflowName, workflow.Name);
}

/// <summary>
/// Verifies that AddWorkflow handles empty strings for name.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,23 @@ public void BuildHandoffs_DelegatingAIAgent_DoesNotThrow()
target.Reason.Should().Be("instructions");
}

[Fact]
public void BuildHandoffs_WithNameAndDescription_SetsWorkflowMetadata()
{
const string WorkflowName = "handoff-workflow";
const string WorkflowDescription = "A handoff workflow";

DoubleEchoAgent agent = new("agent");

var workflow = AgentWorkflowBuilder.CreateHandoffBuilderWith(agent)
.WithName(WorkflowName)
.WithDescription(WorkflowDescription)
.Build();

Assert.Equal(WorkflowName, workflow.Name);
Assert.Equal(WorkflowDescription, workflow.Description);
}

[Fact]
public async Task Handoffs_NoTransfers_ResponseServedByOriginalAgentAsync()
{
Expand Down
Loading