Provide support for complex function parameters in tool requests #249
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.
What this does
Hey @crmne! This PR aims to have RubyLLM support complex function parameter in tool calls.
Motivation
The RubyLLM Tools Guide mentions support for object and array parameters, but advises against using them to maintain compatibility across language models. This guidance is supported by benchmarks like ComplexFuncBench, which highlight varying support across models.
However, as models are getting better complex parameters seem to be getting used more and more. Some of the MCP example servers already include tools with complex parameters. For example, the Filesystem MCP server defines tools with array-based inputs.
RubyLLM::MCP has allowed support through optional monkey patches that you can apply if you know your tools will include complex function parameters. While functional, this not a great longterm approach. This PR refactors and improves that logic, lifting it from those patches into the core implementation. Regardless of this being beneficial to RubyLLM::MCP, sounds like this could also benefit anyone else who would want to be able to use complex parameters.
Implementation
This PR introduces native support for complex tool parameters by enhancing the
Parameters
class adding optional parameters to theparam
method to handle both:This enables more expressive and capable tool definitions while remaining compatible with RubyLLM’s execution model.
Examples
Here are some usage examples, as seen in specs:
Object Parameter Example
Array Parameter Example
Type of change
Scope check
Quality check
overcommit --install
and all hooks passmodels.json
,aliases.json
)API changes
Related issues
No an open issue, but when running the commit hooks the alias.json was changed and did break a spec. Let me know if I need to change this or make other adjustments on this PR.
I also did not update the documentation to reflect these changes. Happy to if this approach is good to be merged.