You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds the ability to define more complex param schemas, while retaining the existing simple methods + bump version to 1.3 since this is kind of a major feature.
param :location, type::object, desc:"Country and city where weather is requested.", required:false, properties: {
101
+
country: { type::string, description:"Full name of the country." },
102
+
city: { type::string, description:"Full name of the city." }
103
+
}
104
+
```
105
+
Remember, `required:` at the root is not part of the JSON schema and automatically removed before sending to the LLM API.
106
+
Also, `desc` at the root level is converted to `description`.
67
107
68
-
1.**Inheritance:** Must inherit from `RubyLLM::Tool`.
69
-
2.**`description`:** A class method defining what the tool does. Crucial for the AI model to understand its purpose. Keep it clear and concise.
70
-
3.**`param`:** A class method used to define each input parameter.
71
-
***Name:** The first argument (a symbol) is the parameter name. It will become a keyword argument in the `execute` method.
72
-
***`type:`:** (Optional, defaults to `:string`) The expected data type. Common types include `:string`, `:integer`, `:number` (float), `:boolean`. Provider support for complex types like `:array` or `:object` varies. Stick to simple types for broad compatibility.
73
-
***`desc:`:** (Required) A clear description of the parameter, explaining its purpose and expected format (e.g., "The city and state, e.g., San Francisco, CA").
74
-
***`required:`:** (Optional, defaults to `true`) Whether the AI *must* provide this parameter when calling the tool. Set to `false` for optional parameters and provide a default value in your `execute` method signature.
75
-
4.**`execute` Method:** The instance method containing your Ruby code. It receives the parameters defined by `param` as keyword arguments. Its return value (typically a String or Hash) is sent back to the AI model.
108
+
### 3. Define `execute` method
109
+
Define the `execute` instance method containing your Ruby code. It receives the parameters defined by `param` as keyword arguments. Its return value (typically a String or Hash) is sent back to the AI model.
76
110
77
111
{: .note }
78
112
The tool's class name is automatically converted to a snake_case name used in the API call (e.g., `WeatherLookup` becomes `weather_lookup`).
@@ -210,4 +244,4 @@ Treat any arguments passed to your `execute` method as potentially untrusted use
210
244
* [Chatting with AI Models]({% link guides/chat.md %})
211
245
* [Streaming Responses]({% link guides/streaming.md %}) (See how tools interact with streaming)
212
246
* [Rails Integration]({% link guides/rails.md %}) (Persisting tool calls and results)
213
-
* [Error Handling]({% link guides/error-handling.md %})
247
+
* [Error Handling]({% link guides/error-handling.md %})
0 commit comments