Repository navigation
Serialize the function result, not the whole FunctionResultContent, in ToContentBlock - #1945
Open
dfedoryshchev wants to merge 1 commit into
Open
dfedoryshchev wants to merge 1 commit into
dfedoryshchev wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
ToContentBlockon aFunctionResultContentwhoseResultis not anAIContentbuilds the text block from the wholeFunctionResultContentinstead of fromResult, so the text is a JSON object with$type,resultandcallIdin it rather than the tool's output.Through
SampleAsync(IEnumerable<ChatMessage>, ...)/AsSamplingChatClient()withUseFunctionInvocation(), a local tool's result reaches the client as{"$type":"functionResult","result":"Weather in Paris: ...","callId":"call_weather_123"}, and that is what the client's model reads. That path is[Obsolete]with the rest of sampling, butToContentBlockitself is public and not obsolete, so any caller converting a function result hits the same thing.The fix serializes
resultContent.Result, the same wayAIFunctionMcpServerToolturns a non-content return value into text.StructuredContentwas already taken fromResult, so the two now agree.EndToEnd_SamplingWithTools_...already goes through this path, but it only asserts that the text contains "Weather in Paris: sunny", which the wrapped JSON also does. I added oneDoesNotContain("callId")line there, plus unit tests for a string result, aJsonElementresult and anAIContentresult (the last one is unchanged behaviour).One thing you may want differently: a string result that comes through as a
JsonElementstill ends up quoted ("Weather in Paris: ..."), the same as a tool returning aJsonElementstring today. I kept it consistent with that path rather than unwrapping strings here, but happy to change it if you prefer.Tests pass on net10.0, net9.0, net8.0 and net472.