-
Notifications
You must be signed in to change notification settings - Fork 849
Fix FunctionInvokingChatClient invoke_agent span detection with exact match or space delimiter #7224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: stephentoub <[email protected]>
test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/FunctionInvokingChatClientTests.cs
Show resolved
Hide resolved
Co-authored-by: stephentoub <[email protected]>
There was a problem hiding this 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 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
test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/FunctionInvokingChatClientTests.cs
Outdated
Show resolved
Hide resolved
… add negative tests Co-authored-by: stephentoub <[email protected]>
src/Libraries/Microsoft.Extensions.AI/ChatCompletion/FunctionInvokingChatClient.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: stephentoub <[email protected]>
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