Used for internal testing of tool loops
()
| 263 | |
| 264 | // Used for internal testing of tool loops |
| 265 | func GetAdderToolDefinition() uctypes.ToolDefinition { |
| 266 | return uctypes.ToolDefinition{ |
| 267 | Name: "adder", |
| 268 | DisplayName: "Adder", |
| 269 | Description: "Add an array of numbers together and return their sum", |
| 270 | ToolLogName: "gen:adder", |
| 271 | Strict: true, |
| 272 | InputSchema: map[string]any{ |
| 273 | "type": "object", |
| 274 | "properties": map[string]any{ |
| 275 | "values": map[string]any{ |
| 276 | "type": "array", |
| 277 | "items": map[string]any{ |
| 278 | "type": "integer", |
| 279 | }, |
| 280 | "description": "Array of numbers to add together", |
| 281 | }, |
| 282 | }, |
| 283 | "required": []string{"values"}, |
| 284 | "additionalProperties": false, |
| 285 | }, |
| 286 | ToolAnyCallback: func(input any, toolUseData *uctypes.UIMessageDataToolUse) (any, error) { |
| 287 | inputMap, ok := input.(map[string]any) |
| 288 | if !ok { |
| 289 | return nil, fmt.Errorf("invalid input format") |
| 290 | } |
| 291 | |
| 292 | valuesInterface, ok := inputMap["values"] |
| 293 | if !ok { |
| 294 | return nil, fmt.Errorf("missing values parameter") |
| 295 | } |
| 296 | |
| 297 | valuesSlice, ok := valuesInterface.([]any) |
| 298 | if !ok { |
| 299 | return nil, fmt.Errorf("values must be an array") |
| 300 | } |
| 301 | |
| 302 | if len(valuesSlice) == 0 { |
| 303 | return 0, nil |
| 304 | } |
| 305 | |
| 306 | sum := 0 |
| 307 | for i, val := range valuesSlice { |
| 308 | floatVal, ok := val.(float64) |
| 309 | if !ok { |
| 310 | return nil, fmt.Errorf("value at index %d is not a number", i) |
| 311 | } |
| 312 | sum += int(floatVal) |
| 313 | } |
| 314 | |
| 315 | return sum, nil |
| 316 | }, |
| 317 | } |
| 318 | } |
no outgoing calls
no test coverage detected