call() method.
The interface
Implementation
src/Tools/WeatherTool.php
CallResponse takes the text result, the cost in credits, and optionally a library item when your tool produced something like an image.
Writing a good tool
- Describe it for a model, not a human. Say when to use it and what it returns.
- Keep the schema small. Few parameters, clear names, explicit
required. - Return text. The content goes back into the conversation, so make it readable and compact.
- Be fast, and time out. A slow tool stalls the whole answer.
- Throw
CallExceptionfor failures, so the model sees an error instead of a broken stream. - Charge for expensive work with
CostCalculator, and return the amount in the response.
Register the tool
src/Plugin.php
What the core offers to models
When a message is generated, the tool collection decides which tools to expose. It checks, in order:isEnabled()on the tool.- Whether the conversation is temporary, which disables context tools such as memory and canvas.
- Whether the plan’s tool configuration has the tool’s key enabled.
- Whether the user disabled that capability in their preferences.
Billing\Domain\ValueObjects\PlanConfig builds its tools map from a fixed list of keys.
A key outside that list is never enabled on a plan, so the collection never yields it to the model.
What you can do instead
Replace a built-in tool's implementation
Replace a built-in tool's implementation
Register your class under an existing key, such as
google_search, to swap the provider behind a capability administrators already control. Keep the same argument schema so existing prompts keep working.Call the tool from your own flow
Call the tool from your own flow
If your plugin runs its own AI flow, for example an assistant of your own, you own the tool loop: build the definitions, call your tool when the model asks for it, and feed the result back. Nothing restricts which tools you offer there.
Do the work before the model runs
Do the work before the model runs
Some “tools” are better as context. Fetch what’s needed and add it to the system instructions rather than waiting for the model to ask.
Testing
With the capability enabled on the plan, the model calls your tool when it should.
The tool’s result appears in the answer, and the tool call is shown in the transcript.
A failure produces a graceful message rather than a broken response.
Credits are charged when the tool costs money.