Fix Message#to_h to deep convert tool_calls#611
Open
sevginuroksuz wants to merge 1 commit intocrmne:mainfrom
Open
Fix Message#to_h to deep convert tool_calls#611sevginuroksuz wants to merge 1 commit intocrmne:mainfrom
sevginuroksuz wants to merge 1 commit intocrmne:mainfrom
Conversation
KieranP
reviewed
Feb 18, 2026
| @thinking = options[:thinking] | ||
|
|
||
| ensure_valid_role | ||
| def normalize_tool_calls(tool_calls) |
There was a problem hiding this comment.
@sevginuroksuz This seems like a copy/paste issue or an AI hallucination
| h[:arguments] = h[:arguments].transform_keys(&:to_sym) | ||
| end | ||
| filtered = h.select { |k, _| allowed_keys.include?(k) } | ||
| puts "ToolCall.new args: #{filtered.inspect}" |
| if h[:arguments].is_a?(Hash) | ||
| h[:arguments] = h[:arguments].transform_keys(&:to_sym) | ||
| end | ||
| filtered = h.select { |k, _| allowed_keys.include?(k) } |
There was a problem hiding this comment.
Can simplify this to: filtered = h.slice(*allowed_keys)
| signature: extract_thought_signature(parts) | ||
| ), | ||
| tool_calls: tool_calls, | ||
| tool_calls: tool_calls&.map { |tc| tc.respond_to?(:to_h) ? tc.to_h : tc }, |
There was a problem hiding this comment.
Why was this added? tool_calls comes from a extract_tool_calls which provides ToolCall records, and deals with building Message records, not converting to hashes. This seems like an unneeded change.
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.
Closes #610
Summary
This PR improves serialization consistency for
RubyLLM::Message.Changes
Message#to_hnow deep-convertstool_callsusingToolCall#to_h.Message#initializenow accepts bothRubyLLM::ToolCallinstances and hashes in thetool_callsarray.id,name,arguments,thought_signature) are automatically converted intoToolCallobjects.ArgumentError.Why
Previously:
Message#to_hperformed shallow serialization.tool_callsdid not normalize them intoToolCallobjects.This ensures:
Tests
tool_calls