Fix NoMethodError when a tool returns Tool::Halt#31
Merged
Conversation
ruby_llm 1.14 returns a Tool::Halt instance (not a Message) from chat.ask/complete when a tool calls `halt`. capture_response then crashed on `response.input_tokens`. Detect Halt and recover token and model metadata from the last assistant message in the client's history, stamping `finish_reason = "halt"`. Fixes #30 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
Chat#handle_tool_callsand returnsRubyLLM::Tool::Halt(not aMessage) fromchat.ask/completewhen a tool callshalt.BaseAgent#capture_responsethen crashed onresponse.input_tokensbecauseTool::Haltonly exposes#contentand#to_s.Tool::Haltincapture_responseand recover token / model metadata from the last assistant message in the client's history (per the approach suggested upstream in [FEATURE] Enrich RubyLLM::Tool::Halt triggering message response metadata. crmne/ruby_llm#436). Setcontext.finish_reason = "halt"so executions are recorded with a meaningful state, and fall back to the configuredmodelwhen no prior assistant message has metadata.@clientinexecutesocapture_responsecan reach the message history without changing its signature.Test plan
spec/lib/base_agent_execution_spec.rbcovering: the original NoMethodError no longer raises, metadata is recovered from the last assistant message, and the no-history path falls back to the configured model withfinish_reason = "halt".bundle exec rspec— 4670 examples, 0 failures.bundle exec standardrb— clean.🤖 Generated with Claude Code