.Net: Add tool_call_id to tool result messages in model diagnostics#13497
Open
dsorokin-st wants to merge 2 commits intomicrosoft:mainfrom
Open
.Net: Add tool_call_id to tool result messages in model diagnostics#13497dsorokin-st wants to merge 2 commits intomicrosoft:mainfrom
dsorokin-st wants to merge 2 commits intomicrosoft:mainfrom
Conversation
Tool result messages in model diagnostics are missing the tool_call_id property, making it difficult to correlate tool results with their corresponding tool calls in observability tools. Changes: - Check for FunctionResultContent in message items - Add tool_call_id from FunctionResultContent.CallId - Use FunctionResultContent.FunctionName for name field (instead of AuthorName which is always null for tool messages) This aligns with the OpenAI API format and enables observability tools (OpenInference, Arize, Galileo) to properly correlate tool calls with results. This is a backward-compatible, additive change.
a51cb32 to
34b5daa
Compare
16c3f04 to
34b5daa
Compare
Author
|
@microsoft-github-policy-service agree company="ServiceTitan" |
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.
Motivation and Context
Tool result messages in model diagnostics are missing the
tool_call_idproperty, making it difficult to correlate tool results with their corresponding tool calls in observability tools.Current behavior - tool result messages only have role and content:
{"role": "tool", "name": null, "content": "Partly Cloudy, 22°C", "tool_calls": []}After this change - includes
tool_call_idfor correlation:{"role": "tool", "name": "get_weather", "tool_call_id": "call_abc123", "content": "Partly Cloudy, 22°C", "tool_calls": []}This aligns with the OpenAI API format and enables observability tools (OpenInference, Arize, Galileo) to properly correlate tool calls with their results.
Description
Updated
ToGenAIConventionsFormatinModelDiagnostics.csto:FunctionResultContentin message itemstool_call_idfromFunctionResultContent.CallIdFunctionResultContent.FunctionNamefor thenamefield (instead ofAuthorNamewhich is always null for tool messages)This is a backward-compatible, additive change - existing consumers will simply ignore the new field.
Why Unit Testing Is Difficult
Unit testing this change is challenging due to
ModelDiagnosticsarchitecture:Static readonly field caching: The feature flags (
s_enableDiagnostics,s_enableSensitiveEvents) arestatic readonlyfields initialized at type load time viaAppContextSwitchHelper.GetConfigValue().No test isolation: Once
ModelDiagnosticsis loaded by any test in the assembly, the flag values are permanently cached. SettingAppContext.SetSwitchor environment variables after type initialization has no effect.Reflection blocked: .NET prevents modification of
initonlystatic fields after type initialization:Existing precedent: The test
GetInvalidResponseThrowsExceptionAndIsCapturedByDiagnosticsAsyncinOpenAIChatCompletionServiceTests.csis already skipped with[Fact(Skip = "Not working running in the console")]for the same reason.The change has been manually verified to produce the correct output.
Contribution Checklist
.Net: <description>