Skip to content

.NET: fix: Foundry Agents without description in Handoff#5311

Merged
lokitoth merged 4 commits intomainfrom
dev/dotnet_workflow/fix_foundry_agent_handoff_reason
Apr 16, 2026
Merged

.NET: fix: Foundry Agents without description in Handoff#5311
lokitoth merged 4 commits intomainfrom
dev/dotnet_workflow/fix_foundry_agent_handoff_reason

Conversation

@lokitoth
Copy link
Copy Markdown
Member

Motivation and Context

Foundry Agents without a description set will return an empty string (rather than null) for the description. This was breaking the fallback logic for handoffReason.

There was also logic to try to cast the AIAgent to ChatClientAgent which would not work for wrapped agents, e.g. anything using DelegatingAIAgent, or any FoundryAgent.

Description

  • Harden the fallback logic for handoff reason to take into account empty/whitespace AIAgent.Description and AIAgent.Name.
  • Harden the fallback logic for handoff reason to use the AIAgent.GetService mechanism to get an underlying ChatClientAgent rather than casting the outermost AIAgent instance.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • [ ] Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Copilot AI review requested due to automatic review settings April 16, 2026 15:50
@moonbox3 moonbox3 added .NET workflows Related to Workflows in agent-framework labels Apr 16, 2026
@github-actions github-actions Bot changed the title fix: Foundry Agents without description in Handoff .NET: fix: Foundry Agents without description in Handoff Apr 16, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens handoff tool description (“handoffReason”) derivation in the .NET Workflows handoff builder to better support Foundry agents that return empty strings for Description, and to support wrapped agents by retrieving an underlying ChatClientAgent via AIAgent.GetService.

Changes:

  • Treat empty/whitespace AIAgent.Description and AIAgent.Name as missing when deriving the default handoffReason.
  • Use AIAgent.GetService(...) to retrieve an underlying ChatClientAgent (instead of casting the outer agent) to fall back to ChatClientAgent.Instructions.

Comment thread dotnet/src/Microsoft.Agents.AI.Workflows/HandoffWorkflowBuilder.cs Outdated
Comment thread dotnet/src/Microsoft.Agents.AI.Workflows/HandoffWorkflowBuilder.cs Outdated
Comment thread dotnet/src/Microsoft.Agents.AI.Workflows/HandoffWorkflowBuilder.cs Outdated
@lokitoth lokitoth self-assigned this Apr 16, 2026
@lokitoth lokitoth moved this to In Review in Agent Framework Apr 16, 2026
Foundry Agents without a description set will return an empty string (rather than null) for the description. This was breaking the fallback logic for `handoffReason`.
@lokitoth lokitoth force-pushed the dev/dotnet_workflow/fix_foundry_agent_handoff_reason branch from 3076066 to 14c8683 Compare April 16, 2026 17:29
Comment thread dotnet/src/Microsoft.Agents.AI.Workflows/HandoffWorkflowBuilder.cs
@lokitoth lokitoth added this pull request to the merge queue Apr 16, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 16, 2026
@lokitoth lokitoth added this pull request to the merge queue Apr 16, 2026
Merged via the queue into main with commit dbf935b Apr 16, 2026
21 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in Agent Framework Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET workflows Related to Workflows in agent-framework

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants