Fix FunctionInvokingChatClient invoke_agent span detection with exact match or space delimiter#7224
Merged
stephentoub merged 5 commits intomainfrom Jan 22, 2026
Merged
Conversation
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix validation of parent span in FunctionInvokingChatClient
Fix FunctionInvokingChatClient invoke_agent span detection to use StartsWith
Jan 22, 2026
stephentoub
reviewed
Jan 22, 2026
test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/FunctionInvokingChatClientTests.cs
Show resolved
Hide resolved
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request fixes a bug in FunctionInvokingChatClient where the span detection logic for invoke_agent spans was using exact string equality instead of a prefix check. The issue prevented the correct detection of invoke_agent spans with postfixed display names like "invoke_agent demo_app", causing spurious orchestrate_tools spans to be created.
Changes:
- Modified
CurrentActivityIsInvokeAgentproperty to useStartsWithinstead of equality comparison - Added new theory test with three test cases to validate the fix handles postfixed display names
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Libraries/Microsoft.Extensions.AI/ChatCompletion/FunctionInvokingChatClient.cs | Changed span detection from exact equality to StartsWith check |
| test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/FunctionInvokingChatClientTests.cs | Added parameterized test covering postfixed display name scenarios |
test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/FunctionInvokingChatClientTests.cs
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI/ChatCompletion/FunctionInvokingChatClient.cs
Outdated
Show resolved
Hide resolved
stephentoub
reviewed
Jan 22, 2026
test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/FunctionInvokingChatClientTests.cs
Outdated
Show resolved
Hide resolved
… add negative tests Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Copilot
AI
changed the title
Fix FunctionInvokingChatClient invoke_agent span detection to use StartsWith
Fix FunctionInvokingChatClient invoke_agent span detection with exact match or space delimiter
Jan 22, 2026
stephentoub
reviewed
Jan 22, 2026
src/Libraries/Microsoft.Extensions.AI/ChatCompletion/FunctionInvokingChatClient.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
stephentoub
approved these changes
Jan 22, 2026
This was referenced Feb 14, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CurrentActivityIsInvokeAgentproperty to useStartsWithinstead of equality checkSummary
Fixed the
FunctionInvokingChatClientto correctly detectinvoke_agentspans. The implementation now checks for:"invoke_agent"This prevents false positives for span names like "invoke_agent_extra" while avoiding unnecessary string allocations.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
Microsoft Reviewers: Open in CodeFlow