Skip to content

Commit 0a73d74

Browse files
committed
Refactor tool parameters to simplify and enhance weather tool functionality
1 parent b6ddf11 commit 0a73d74

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

docs/guides/tools.md

+18-25
Original file line numberDiff line numberDiff line change
@@ -207,42 +207,35 @@ chat.ask "What's the weather at invalid coordinates 1000, 1000?"
207207
# => "The coordinates 1000, 1000 are not valid for any location on Earth, as latitude must be between -90 and 90, and longitude must be between -180 and 180. Please provide valid coordinates or a city name for weather information."
208208
```
209209

210-
## Advanced Tool Parameters
210+
## Simple Tool Parameters
211211

212-
Tools can have complex parameter types:
212+
RubyLLM currently only supports simple parameter types: strings, numbers, and booleans. Complex types like arrays and objects are not supported.
213213

214214
```ruby
215-
class DataAnalysis < RubyLLM::Tool
216-
description "Analyzes numerical data"
217-
218-
param :data,
219-
type: :array,
220-
desc: "Array of numbers to analyze"
221-
222-
param :operations,
223-
type: :object,
224-
desc: "Analysis operations to perform",
225-
required: false
226-
227-
def execute(data:, operations: {mean: true, median: false})
228-
result = {}
215+
class WeatherTool < RubyLLM::Tool
216+
description "Gets current weather for a location"
229217

230-
result[:mean] = data.sum.to_f / data.size if operations[:mean]
231-
result[:median] = calculate_median(data) if operations[:median]
218+
param :latitude,
219+
type: :string,
220+
desc: "Latitude (e.g., 52.5200)"
232221

233-
result
234-
end
222+
param :longitude,
223+
type: :string,
224+
desc: "Longitude (e.g., 13.4050)"
235225

236-
private
226+
param :unit,
227+
type: :string,
228+
desc: "Temperature unit. Must be 'celsius' or 'fahrenheit'",
229+
required: false
237230

238-
def calculate_median(data)
239-
sorted = data.sort
240-
mid = sorted.size / 2
241-
sorted.size.odd? ? sorted[mid] : (sorted[mid-1] + sorted[mid]) / 2.0
231+
def execute(latitude:, longitude:, unit: 'celsius')
232+
# Weather lookup logic here
242233
end
243234
end
244235
```
245236

237+
> Note: For parameters with limited valid values, clearly specify them in the description.
238+
246239
## Security Considerations
247240

248241
When implementing tools that process user input (via the AI):

0 commit comments

Comments
 (0)