Skip to content

Fix NoMethodError when a tool returns Tool::Halt#31

Merged
adham90 merged 1 commit into
mainfrom
adham90/check-issue-30
May 20, 2026
Merged

Fix NoMethodError when a tool returns Tool::Halt#31
adham90 merged 1 commit into
mainfrom
adham90/check-issue-30

Conversation

@adham90

@adham90 adham90 commented May 20, 2026

Copy link
Copy Markdown
Owner

Summary

  • Fixes NoMethodError on input_tokens when a tool returns Tool::Halt #30. ruby_llm 1.14 short-circuits Chat#handle_tool_calls and returns RubyLLM::Tool::Halt (not a Message) from chat.ask/complete when a tool calls halt. BaseAgent#capture_response then crashed on response.input_tokens because Tool::Halt only exposes #content and #to_s.
  • Detect Tool::Halt in capture_response and 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). Set context.finish_reason = "halt" so executions are recorded with a meaningful state, and fall back to the configured model when no prior assistant message has metadata.
  • Cache the chat client as @client in execute so capture_response can reach the message history without changing its signature.

Test plan

  • New regression specs in spec/lib/base_agent_execution_spec.rb covering: 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 with finish_reason = "halt".
  • bundle exec rspec — 4670 examples, 0 failures.
  • bundle exec standardrb — clean.

🤖 Generated with Claude Code

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>
@adham90 adham90 merged commit c30dac2 into main May 20, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NoMethodError on input_tokens when a tool returns Tool::Halt

1 participant