Страницы · Laravilt
Custom Tools
Write your own tools for AI function calling.
Laravilt\AI\Tools\Tool is abstract. Extend it and implement handle():
php
Closure handlers
When handler() is set, execute() calls the closure instead of handle(). You still need a concrete class, for example an anonymous one:
php
Parameters
php
toArray() turns the parameters into a JSON Schema object (type, properties, required) for the provider.
schema()stores a custom schema on the tool, buttoArray()builds the definition from the parameters. UseaddParameter()orparameters()to shape what the model sees.
Methods
| Method | Description |
|---|---|
make(string $name) | Create the tool |
description(string) | Description sent to the model |
addParameter($name, $type, $description, $required = false) | Add one parameter |
parameters(array) | Replace all parameters |
handler(Closure) | Use a closure instead of handle() |
execute(array $arguments) | Run the tool |
toArray() | Export the definition for providers |