-
Notifications
You must be signed in to change notification settings - Fork 848
Improve FunctionInvokingChatClient's awareness of agents #7030
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
This addresses several issues: 1. When FunctionInvokingChatClient is used from an agent, and the agent creates an invoke_agent span, that effectively serves the same purpose as the orchestrate_tools span the FICC would have otherwise created, yielding duplication in the telemetry. If we detect an "invoke_agent" span is the parent, we can simply not create "orchestrate_tools". 2. When FunctionInvokingChatClient is used from an agent, its operation is much more closely tied to the agent than to the inner chat client it's orchestrating. So whereas by default it gets its ActivitySource from the inner client, if it detects an "invoke_agent" span as current, it will instead use that activity's source. This means that we can still get "execute_tool" spans created even if telemetry isn't enabled for the inner chat client but is for the parent agent. 3. "execute_tool" optionally has sensitive data to emit. FICC currently determines whether to emit sensitive data based on the inner OpenTelemetryChatClient, since it's also using its ActivitySource. Now when it uses the "invoke_agent" span, it also picks up the sensitivity setting from a custom property on that span.
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 PR adds support for detecting and respecting "invoke_agent" activities when creating telemetry spans in the AI chat completion pipeline. When an "invoke_agent" span is the current activity, the FunctionInvokingChatClient will skip creating an "orchestrate_tools" span and instead use the agent's activity source for tool execution spans. Additionally, the sensitive data configuration from the agent activity is propagated to tool execution activities.
- Added
invoke_agentconstant toOpenTelemetryConsts.GenAIfor standardized activity naming - Modified
FunctionInvokingChatClientto detect "invoke_agent" parent activities and adjust telemetry behavior accordingly - Propagated sensitive data settings from agent activities to tool execution activities via custom properties
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/FunctionInvokingChatClientTests.cs | Added three comprehensive tests verifying invoke_agent span detection, activity source selection, and sensitive data propagation behavior |
| src/Libraries/Microsoft.Extensions.AI/OpenTelemetryConsts.cs | Added InvokeAgentName constant for standardized activity naming |
| src/Libraries/Microsoft.Extensions.AI/ChatCompletion/OpenTelemetryChatClient.cs | Added internal constants for sensitive data custom property and logic to set this property on chat activities |
| src/Libraries/Microsoft.Extensions.AI/ChatCompletion/FunctionInvokingChatClient.cs | Modified to detect invoke_agent activities, conditionally create orchestrate_tools spans, use agent activity sources, and propagate sensitive data settings |
This addresses several issues:
cc: @rogerbarreto, @TaoChenOSU, @eiriktsarpalis
Microsoft Reviewers: Open in CodeFlow