-
-
Notifications
You must be signed in to change notification settings - Fork 372
feat: Allow instance-level customization of tool parameters #572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: Allow instance-level customization of tool parameters #572
Conversation
Add support for customizing tool description, parameters, and provider_params at the instance level, with fallback to class-level definitions when not overridden. - Add initialize method with optional description, parameters, and provider_params arguments - Modify instance getters to check instance values first, then fall back to class-level definitions - Add instance setters for post-initialization customization - Update params_schema to generate schema from instance parameters - Add comprehensive unit tests for instance-level customization - Add integration tests for customized tools with Chat Closes crmne#418
Allow users to explicitly set unique names for tool instances, solving the name collision issue where multiple instances of the same tool class would overwrite each other in the chat's tools hash. - Add name: parameter to Tool#initialize - Update name getter to check @instance_name first - Add name= setter for post-initialization customization - Add unit and integration tests - Document instance-level customization in tools.md
| berlin_weather = Weather.new(description: "Get current weather in Berlin") | ||
| paris_weather = Weather.new(description: "Get current weather in Paris") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the current implementation, this would fail without giving a name, as both would have the same name and get overwritten.
I think the current name approach is great, as this won't break the overwriting functionality, but we need to be clear in the docs.
| if @instance_parameters | ||
| return SchemaDefinition.from_parameters(@instance_parameters)&.json_schema if @instance_parameters.any? | ||
|
|
||
| return nil | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if @instance_parameters | |
| return SchemaDefinition.from_parameters(@instance_parameters)&.json_schema if @instance_parameters.any? | |
| return nil | |
| end | |
| if @instance_parameters | |
| return SchemaDefinition.from_parameters(@instance_parameters)&.json_schema | |
| end |
Line 122 in bd2bb14
| return nil if parameters.nil? || parameters.empty? |
SchemaDefinition.from_parameters would return nil if the value is nil or empty.
we can also just one line it
| if @instance_parameters | |
| return SchemaDefinition.from_parameters(@instance_parameters)&.json_schema if @instance_parameters.any? | |
| return nil | |
| end | |
| return SchemaDefinition.from_parameters(@instance_parameters)&.json_schema if @instance_parameters |
Summary
Enable instance-level customization of tools, allowing different instances of the same tool class to have unique configurations:
name,description,parameters, andprovider_paramsat the instance levelMotivation
Closes #418
Currently, RubyLLM tools define descriptions and parameters at the class level only, meaning all instances share the same configuration. This limits flexibility for use cases like:
Usage
Test plan
initializewith optional parameters (name,description,parameters,provider_params)params_schemawith instance parameters