Skip to content

Forward choice: and calls: from Agent tools macro to with_tools#806

Open
juanmanuelramallo wants to merge 1 commit into
crmne:mainfrom
juanmanuelramallo:agent-tools-forward-choice-calls
Open

Forward choice: and calls: from Agent tools macro to with_tools#806
juanmanuelramallo wants to merge 1 commit into
crmne:mainfrom
juanmanuelramallo:agent-tools-forward-choice-calls

Conversation

@juanmanuelramallo

Copy link
Copy Markdown

What this does

The RubyLLM::Agent tools class macro accepted only positional tools and ignored the tool-call controls (choice:, calls:) that Chat#with_tools has supported since 1.13.0. The docs state "tools maps to with_tools", but passing the options either crashed or was silently dropped:

class MacroKwargAgent < RubyLLM::Agent
  tools DummyTool, choice: :required
end
MacroKwargAgent.new
# => NoMethodError: undefined method 'name' for an instance of Hash
#    (the choice: hash was swallowed into *tools and treated as a tool)

class MacroBlockAgent < RubyLLM::Agent
  tools(choice: :required) { [DummyTool.new] }
end
MacroBlockAgent.new.chat.tool_prefs[:choice]
# => nil   (silently dropped)

This PR makes tools accept choice: and calls:, store them, and forward them in apply_tools, so both the positional and block forms set the tool preferences on the underlying chat, equivalent to with_tools(*tools, choice:, calls:).

  • Reader path preserved: tools with no args/options still returns the configured tool list.
  • Options propagated to subclasses via inherited.
  • Forwarding **{} is safe since with_tools/update_tool_options already skip nil options.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Performance improvement

Scope check

  • I read the Contributing Guide
  • This aligns with RubyLLM's focus on LLM communication
  • This isn't application-specific logic that belongs in user code
  • This benefits most users, not just my specific use case

Required for new features

  • I opened an issue before writing code and received maintainer approval
  • Linked issue: #___

PRs for new features or enhancements without a prior approved issue will be closed.

Quality check

  • I ran overcommit --install and all hooks pass
  • I tested my changes thoroughly
    • For provider changes: Re-recorded VCR cassettes with bundle exec rake vcr:record[provider_name]
    • All tests pass: bundle exec rspec
  • I updated documentation if needed
  • I didn't modify auto-generated files manually (models.json, aliases.json)

AI-generated code

  • I used AI tools to help write this code
  • I have reviewed and understand all generated code (required if above is checked)

API changes

  • Breaking change
  • New public methods/classes
  • Changed method signatures
  • No API changes

The Agent tools class macro previously accepted only positional tools and
ignored tool-call controls. Passing choice:/calls: either crashed (the hash
was treated as a tool) or was silently dropped in the block form.

Accept choice: and calls: on the macro, store them, and forward them in
apply_tools so both the positional and block forms set tool preferences on
the underlying chat, matching with_tools.
@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.85%. Comparing base (978d5f2) to head (8c91247).
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #806      +/-   ##
==========================================
- Coverage   88.47%   82.85%   -5.62%     
==========================================
  Files         122      122              
  Lines        5898     5903       +5     
  Branches     1405     1405              
==========================================
- Hits         5218     4891     -327     
+ Misses        680      679       -1     
- Partials        0      333     +333     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant