-
Notifications
You must be signed in to change notification settings - Fork 4.4k
.Net: Add tool_call_id to tool result messages in model diagnostics #13497
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
base: main
Are you sure you want to change the base?
.Net: Add tool_call_id to tool result messages in model diagnostics #13497
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
|
@dsorokin-st please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
16c3f04 to
34b5daa
Compare
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>