microsoft / microsoft/agent-framework
.NET: The Handoff Workflow Output is filled with null elements when a Handoff AsAgent is used inside a Handoff Workflow.
- Dominant language
- Python
- Stars
- 13.6k
- Forks
- 2.3k
- Avg merge
- 2d 45m
- Merged PRs (30d)
- 358
Description
### Description
As a test, I created a Handoff and wrapped it as an AIAgent, which I then used inside a Handoff workflow.
I noticed that the workflow output contained a lot of useless chat message elements filled with assistant null.
I could not find an issue that focused on this bug, so I created one.
### Code Sample
```markdown
public static Workflow CreateHandoffWorkflow(AIAgent mainAgent, List agents)
{
subject to change or removal in future updates. Suppress this diagnostic to proceed.
HandoffWorkflowBuilder workflowBuilder = AgentWorkflowBuilder.CreateHandoffBuilderWith(mainAgent)
.WithHandoffs(mainAgent, agents) // Triage can route to either specialist
.WithHandoffs(agents, mainAgent)
.WithToolCallFilteringBehavior(HandoffToolCallFilteringBehavior.None)
.EnableReturnToPrevious()
.EmitAgentResponseUpdateEvents();
Workflow workflow = workflowBuilder.Build();
return workflow;
}
public static async Task CreateHandoffWorkflow(IChatClient chatClient)
{
List mainAgents = new();
mainAgents.Add(CreateHandoffWorkflow(
new ChatClientAgent(
chatClient,
name: "main-core-agent",
instructions: "You determine which agent is needed to answer the question. Always Handoff",
description: "main-agent with a focus on updates")
.AsBuilder()
.UseOpenTelemetry(sourceName: "MainAgent-source", configure: (cfg) => cfg.EnableSensitiveData = true)
.Build(),
await Agents.LoadCoreAgents())
.AsAIAgent(
name: "core_agent",
description: "A specialist agent who has variety of tools that can be useful for any operations.")
.AsBuilder()
.UseOpenTelemetry(sourceName: "MainAgent-source", configure: (cfg) => cfg.EnableSensitiveData = true)
.Use(runFunc: MiddlewareClass.AgentAsyncMiddleware, runStreamingFunc: MiddlewareClass.AgentStreamingMiddleware)
.Build());
mainAgents.Add(CreateHandoffWorkflow(
new ChatClientAgent(
chatClient,
name: "main-educP-agent",
instructions: "You determine which agent is needed to answer the question. Always Handoff",
description: "main-agent with a focus on weather")
.AsBuilder()
.UseOpenTelemetry(sourceName: "MainAgent-source", configure: (cfg) => cfg.EnableSensitiveData = true)
.Build(),
await Agents.LoadEducationalPurposesAgents())
.AsAIAgent(
name: "educational_purposes_agent",
description: "A specialist agent which tools focusing on smartLight and weather system.")
.AsBuilder()
.UseOpenTelemetry(sourceName: "MainAgent-source", configure: (cfg) => cfg.EnableSensitiveData = true)
.Use(runFunc: MiddlewareClass.AgentAsyncMiddleware, runStreamingFunc: MiddlewareClass.AgentStreamingMiddleware)
.Build());
AIAgent masterAgent = new ChatClientAgent(
chatClient,
name: "Master-Agent",
instructions: "You determine which agent to use based on the user's prompt.",
description: "A agent that delagates a task to another with handoff, to response the prompt.")
.AsBuilder()
.UseOpenTelemetry(sourceName: "MasterAgent-source", configure: (cfg) => cfg.EnableSensitiveData = true)
.Use(runFunc: MiddlewareClass.AgentAsyncMiddleware, runStreamingFunc: MiddlewareClass.AgentStreamingMiddleware)
.Use(MiddlewareClass.FunctionCallingMiddleware)
.Build();
Workflow workflow = CreateSimpleHandoffWorkflow(masterAgent, mainAgents);
return workflow;
}
```
### Error Messages / Stack Traces
```markdown
```
### Package Versions
Microsoft.Agents.AI.Workflows" Version="1.3.0, Microsoft.Agents.AI" Version="1.3.0"
### .NET Version
.Net 10
### Additional Context
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.