fix(tools): preserve conversation history across multi-step tool calls#40
Merged
iskakaushik merged 2 commits intomainfrom May 1, 2026
Merged
fix(tools): preserve conversation history across multi-step tool calls#40iskakaushik merged 2 commits intomainfrom
iskakaushik merged 2 commits intomainfrom
Conversation
Two bugs caused multi-step tool calling to repeatedly re-issue the same tool calls and drop the system prompt: - MultiStepCoordinator::execute_multi_step rebuilt step inputs from initial_options + only the most recent step's tool calls/results, so earlier turns were lost between iterations. Refactor to mirror the Vercel AI SDK pattern (packages/ai/src/generate-text/generate-text.ts): immutable initial_messages plus a response_messages accumulator; each step's input is the concatenation of the two. - OpenAIRequestBuilder dropped options.system whenever the caller supplied a non-empty messages array (the Chat Completions API has no top-level system field; system must be a leading role=system message). Anthropic's builder already handled this correctly via request["system"]. Validated by the existing MultiStepDuplicateExecutionTest cases, which were known-failing per issue #26 and now pass for both providers. Adds tests/cmake_test_discovery_*.json to .gitignore (build artifact).
4 tasks
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.
Summary
Multi-turn tool calling on this branch had two bugs that combined to make the model repeatedly re-issue the same tool calls:
MultiStepCoordinator::execute_multi_steprebuilt each step's input frominitial_options + only the most recent step's tool calls/results, so earlier turns were lost between iterations. Refactored to mirror the Vercel AI SDK pattern (packages/ai/src/generate-text/generate-text.ts): immutableinitial_messages+ aresponse_messagesaccumulator; each step's input is the concatenation of the two.OpenAIRequestBuildersilently droppedoptions.systemwhenever the caller supplied a non-emptymessagesarray. The OpenAI Chat Completions API has no top-level `system` field — it must be a leading `role: "system"` message. The Anthropic builder already handled this correctly via `request["system"]`.The two changes together also let the coordinator drop a workaround that was pushing the system prompt as a
role=usermessage.Validates against the existing
MultiStepDuplicateExecutionTestcases (which were known-failing per issue #26). They now pass for both OpenAI and Anthropic.Also adds `tests/cmake_test_discovery_*.json` to `.gitignore` (CMake test discovery cache, no need to track).
Test plan