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

* fix: Foundry Agents without description in Handoff

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`.

* test: Add unit tests
This commit is contained in:
Jacob Alber
2026-04-16 21:23:01 +00:00
committed by GitHub
parent ca580a8316
commit dbf935b4e3
2 changed files with 55 additions and 3 deletions
@@ -219,13 +219,17 @@ public class HandoffWorkflowBuilderCore<TBuilder> where TBuilder : HandoffWorkfl
if (string.IsNullOrWhiteSpace(handoffReason))
{
handoffReason = to.Description ?? to.Name ?? (to as ChatClientAgent)?.Instructions;
handoffReason = (string.IsNullOrWhiteSpace(to.Description) ? null : to.Description)
?? (string.IsNullOrWhiteSpace(to.Name) ? null : $"handoff to {to.Name}")
?? to.GetService<ChatClientAgent>()?.Instructions;
if (string.IsNullOrWhiteSpace(handoffReason))
{
Throw.ArgumentException(
nameof(to),
$"The provided target agent '{to.Name ?? to.Id}' has no description, name, or instructions, and no handoff description has been provided. " +
"At least one of these is required to register a handoff so that the appropriate target agent can be chosen.");
$"The provided target agent '{(string.IsNullOrWhiteSpace(to.Name) ? to.Id : to.Name)}' has no description, name, or instructions, and no " +
"handoff description has been provided. At least one of these is required to register a handoff so that the appropriate target agent can " +
"be chosen.");
}
}