Merge add_tool_call() tool calls into to_dict() output#1438
Open
CrypticCortex wants to merge 1 commit into
Open
Merge add_tool_call() tool calls into to_dict() output#1438CrypticCortex wants to merge 1 commit into
CrypticCortex wants to merge 1 commit into
Conversation
When a plugin yielded any StreamEvent and also called response.add_tool_call(), the tool call was silently dropped from response.to_dict()["messages"] because Part assembly read only from _stream_events. The _tool_calls fallback only fired when no events existed at all (the rehydrate-from-SQLite path). Fix: in _build_parts(), after assembling Parts from stream events, walk self._tool_calls and append a ToolCallPart for any tool_call_id not already represented. None-id calls always append, since some providers (Gemini) omit the id on parallel tool calls. Dedup-by-tool_call_id keeps the OpenAI plugin's "emit StreamEvents AND add_tool_call" pattern working without producing duplicate Parts. Refs simonw#1433
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
Read-time merge in
_build_parts(): after Parts are assembled from stream events, append aToolCallPartfor eachtool_call_idinself._tool_callsnot already represented. None-id calls always append (Gemini omits the id on parallel calls).tool_call_idkeeps the OpenAI plugin's "emit StreamEvents ANDadd_tool_call" pattern producing exactly one Part.test_text_then_tool_call_part_index_advancesstill passes.test_to_dict_includes_tool_calls_added_alongside_text(mirrors thellm-echoshape, fails on main) andtest_to_dict_dedupes_tool_call_emitted_via_both_apistoTestResponseToDictFromDict.732 tests pass, ruff/black/mypy clean. Happy to switch to a
DeprecationWarningfromadd_tool_callinstead, if you'd rather nudge plugins t