Repository navigation
RubyLLM2 W1-01: Accept RubyLLM 2.0's tool DSL names on the 1.16 fork - #37
Conversation
Add parameter, declared_parameters, parameters(schema/block), parameters_schema_definition and instance parameters_schema. Each 1.x name calls its 2.0 name through plain methods, so overrides of either name are honored by the protocols. Docs use the 2.0 names. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Co-authored-by: Sam Boland <sam.boland@appfolio.com>
|
Review of 3dd533f. The code, specs and docs match the brief. The only thing blocking merge is CI, and the cause is not this PR. 1. CI never ran the specs. Fix the runner image in its own commit.
The matrix has no Change 2. No PR description work needed. I will write the description after your last push. Verified and fine:
|
I've queued the runner fix and I'm working on it now. It changes |
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Pushed Changed 1 file (+2 −1): Questions:
|
samuelboland
left a comment
There was a problem hiding this comment.
Verified: both call chains as briefed, override specs for both names across all five protocols, docs, and the ubuntu-24.04 pin; full CI matrix green.
RubyLLM2 W1-01. Supernova is moving from this fork's 1.16 to upstream RubyLLM 2.x. 2.0 renames the tool DSL, and Supernova declares about 1,780 tool parameters across 537 files with the 1.x names. This PR makes the fork accept the 2.0 names as well, so Supernova can rename everything on today's gem, in ordinary PRs, before the gem bump. This PR targets the fork's
mainonly; it is not an upstream contribution.The rename
Parameter.new(name, desc: ...)Parameter.new(name, description: ...)(already accepted before this PR)param :x, desc: '...'parameter :x, description: '...'parameters(no-argument getter)declared_parametersparams(schema)/params do ... endparameters(schema)/parameters do ... endparams_schema_definitionparameters_schema_definitionparametersdeclared_parametersparams_schemaparameters_schemaHow the two sets of names relate
All changes are in
lib/ruby_llm/tool.rb. Each concept is one chain of plaindefmethods, neveralias(an alias binds to the method body when it is defined, so a subclass overriding one name would not be seen through the other):parameters-> instancedeclared_parameters-> classparameters(no arguments) -> classdeclared_parameters(storage).params_schema-> instanceparameters_schema(holds the existing logic) -> classparams_schema_definition-> classparameters_schema_definition(storage).The protocols call the head of each chain (
tool.params_schema || ... from_parameters(tool.parameters)inanthropic/tools.rb:49,chat_completions/tools.rb:21,converse/chat.rb:333,gemini/tools.rb:95;responses/tools.rb:16goes throughChatCompletions::Tools.parameters_schema_for). So an override of any link, under either name, at the class or the instance level, reaches every protocol. The protocol files are unchanged.parameterswith a schema or block is the 2.0 form ofparams. With neither, it stays the 1.x getter for the parameter hash (2.0 raisesArgumentErrorthere; the fork keeps the getter until Supernova no longer calls it).paramsbehaves as before: with no arguments it sets an empty definition and returns the class.Overrides of either name are honored
Supernova overrides these methods in three ways today and will use the 2.0 names after RubyLLM2 W1-02. Each is covered in
spec/ruby_llm/tool_spec.rb,describe 'RubyLLM 2.0 tool DSL names':parametersmerging another tool's parameters (Supernova'sAutomationCreateTool): "honors a class-level parameters override through both names";declared_parameters: "honors a class-level declared_parameters override through both names";parametersandparams_schema(Supernova'sToolDiscovery::ToolHeadline): "honors instance-level parameters and params_schema overrides at the 1.x names", and at the 2.0 names: "honors instance-level declared_parameters and parameters_schema overrides at the 2.0 names";The 2.0 names sit further down each chain than the 1.x names, so an instance-level override of a 1.x name is not seen by a direct call to the 2.0 name. The protocols call the 1.x names, so they see it; the spec says so in a comment. W1-02 moves Supernova's overrides to the 2.0 names.
Every 1.x method keeps its behavior and the protocols are unchanged, so a Supernova lock bump that only picks up this PR is not expected to change any tool schema. RubyLLM2 W1-03 dumps every tool's schema before and after its rename, which measures this directly.
Also covered: the same schema from
param/desc:andparameter/description:, compared against a literal ("builds the same schema from param/desc and parameter/description");paramsandparameterswith a schema hash and with aRubyLLM::Schemablock; and the no-argument getter.No inheritance change
2.0 copies a parent's declared parameters and schema definition into each subclass through an
inheritedhook; 1.16 does not. This PR deliberately does not add the hook, because it would change the schema of every Supernova tool that subclasses another tool. "does not copy declared parameters into subclasses" pins today's behavior. Supernova handles the difference at the gem bump.Other readers in
lib/A grep of
lib/forparams_schema,params_schema_definition,.parametersand@parametersfound only the five protocol call sites above; none needed a change. The other.paramshits are Faradayrequest.paramsin the xai, vertexai and mistral providers, unrelated to tools. No code inlib/or in Supernova reads the moved instance variables (@parameters,@params_schema,@params_schema_definition) directly.Docs
README.mdanddocs/use the 2.0 names in every tool example and in the prose about the DSL.docs/_core_features/tools.mdanddocs/_core_features/tool-parameters.mdeach say that the 1.x names still work on this fork.with_params,docs/_advanced/agents.md,docs/_core_features/image-generation.mdand the tool generator template are unchanged.CI runner image
A separate commit pins
.github/workflows/_test-matrix.ymltoruns-on: ubuntu-24.04.ubuntu-latestmoved to ubuntu-26.04 between Oct 14 and Oct 19, and ruby/setup-ruby has no Ruby 3.1.7 or JRuby 10.0.2.0 build for it, so those two jobs failed in "Set up Ruby" and fail-fast cancelled the other 17. The lint and gitleaks workflows still run onubuntu-latest.Tests
spec/ruby_llm/tool_spec.rb, three seeds: 36 examples, 0 failures.chat_schema_spec.rbthat skip because the model does not support structured output).Out of scope
with_params/provider_params(2.0:provider_options), 2.0'stool_name,requires_approvaland thecall(tool_call:, **arguments)signature. Supernova handles those at the gem bump.