Skip to content

Conversation

@bjornhandersson
Copy link

Motivation and Context

Fixes #13243.

Description

Ensure each "tool_use" is directly followed by it's corresponding "tool_result" in the ChatHistory, this is a soft convention but Anthropic Sonnet is strict to it and fails.

Contribution Checklist

@bjornhandersson bjornhandersson requested a review from a team as a code owner October 17, 2025 21:23
@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code kernel Issues or pull requests impacting the core kernel kernel.core labels Oct 17, 2025
@github-actions github-actions bot changed the title .NET: Ensure tool results follow corresponding tool calls in chat history .Net: Ensure tool results follow corresponding tool calls in chat history Oct 17, 2025
@bjornhandersson
Copy link
Author

@microsoft-github-policy-service agree

@bjornhandersson
Copy link
Author

@microsoft-github-policy-service agree company="Microsoft"

@bjornhandersson bjornhandersson force-pushed the fix/tool-history-ordering branch from c9c0793 to 7f0eef2 Compare October 21, 2025 20:40
@bjornhandersson
Copy link
Author

This is not a good solution where I mutate the history after yielding the result.
I have no personal interest in solving this anymore since I've picked another model for the project which works with unordered tool_use and tool_result.
But if someone can point me to the right direction I'm still willing to contribute.

@westey-m
Copy link
Contributor

Thanks for filing a bug and providing this PR @bjornhandersson.
I recently changed this code to yield FunctionCallContent and FunctionResultContent as soon as possible instead of deferring them until the end. This was causing issues upstream where callers were expecting these to arrive as they happened (before the final result) instead of only after the final result. This is obviously conflicting with the problem you have.
I'm thinking there may be a (slightly more complicated) middle ground where we yield both FCC & FRC as soon as the FRC is available but not until it is available, but I suppose we'll have to test to ensure that that solves the issue you found.

@bjornhandersson
Copy link
Author

Closing this since this is not a good solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kernel.core kernel Issues or pull requests impacting the core kernel .NET Issue or Pull requests regarding .NET code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.Net: Bug: ChatHistory function call ordering is broken in streaming mode

3 participants