Documentation Index
Fetch the complete documentation index at: https://mintlify.com/phpaisdk/core/llms.txt
Use this file to discover all available pages before exploring further.
Tool is the core abstraction for giving AI models access to PHP callables. A tool carries a name, a description shown to the model, an input schema describing the arguments, and a handler invoked when the model calls the tool. It can be defined inline with the fluent builder API or as a dedicated class that extends Tool and implements __invoke.
Tool::make()
Create or resolve a tool. Accepts an inline name string, an existing Tool instance (returned as-is), or a class name that will be resolved via the SDK container.
One of:
- A plain string tool name (e.g.
'get_weather') — creates an inline tool. - A fully-qualified class name string — instantiates the class (optionally via the container) and returns it as a
Tool. - An existing
Toolinstance — returned unchanged.
Human-readable description shown to the model. Only used when creating an inline tool from a name string.
Instance methods
named()
Set or update the tool’s name. Also callable as ->as(string $name).
The tool name passed to the model. Must be unique across all tools registered on a request.
for()
Set or update the tool’s description.
A clear, model-facing description of what the tool does and when to use it.
input()
Define the tool’s input using a single schema. For primitive inputs the schema must be named; for an object schema the schema’s own properties become the parameters.
A named
Schema instance describing the input. If the schema type is not object, it must have a non-empty name. Replaces any previously registered inputs.inputs()
Define the tool’s input as multiple named schemas. Each schema maps to a positional argument in the handler.
A non-empty indexed array of named
Schema instances. Every schema must have a non-empty name. Throws InvalidArgumentException when the array is empty or contains unnamed schemas.run()
Attach the callable handler that is invoked when the model calls this tool.
A callable that receives the validated input arguments as positional parameters. Optionally receives a
ToolExecutionContext as a final argument when the handler signature declares it.name()
Return the tool’s current name.
The tool name. Empty string if none has been set.
description()
Return the tool’s description string.
The description shown to the model.
handler()
Return the registered callable handler, or null if no handler has been attached. For class-based tools, returns $this when the class implements __invoke.
The tool handler, or
null when none has been set and the object does not implement __invoke.inputSchemaForProvider()
Return the tool’s input as a JSON Schema array in the format expected by AI providers.
A JSON Schema object. Returns
{"type":"object","properties":{}} when no inputs are defined. For a single object schema, returns that schema’s jsonSchema() directly. For multiple named schemas, they are wrapped in a synthesised object.call()
Validate the arguments and invoke the handler. Throws ToolExecutionException on handler failure and InvalidToolInputException on validation errors.
The raw arguments object supplied by the model, keyed by parameter name.
Optional execution context. Automatically forwarded to the handler if the handler’s signature declares a final
ToolExecutionContext parameter.The value returned by the handler. Serialized to a string by the calling loop when appended to the conversation.
ToolChoice
ToolChoice is a value object that instructs the model how to select tools during generation.
Constants
| Constant | Value | Meaning |
|---|---|---|
ToolChoice::AUTO | 'auto' | Model decides whether to call a tool |
ToolChoice::NONE | 'none' | Tools are registered but the model must not call any |
ToolChoice::REQUIRED | 'required' | Model must call at least one tool |
ToolChoice::TOOL | 'tool' | Model must call the named tool |
Static factory methods
Required only for
ToolChoice::tool(). The exact name of the tool the model must call. Throws InvalidArgumentException when empty.ToolChoice::from() is a convenience normaliser — pass a ToolChoice instance (returned as-is) or one of the string constants 'auto', 'none', or 'required'. Any other string is treated as a tool name and delegates to ToolChoice::tool().
A
ToolChoice instance or one of the string values 'auto', 'none', 'required', or a tool name string.ToolExecutionContext
ToolExecutionContext is a read-only value object injected into tool handlers that declare it as their final parameter. It provides runtime context about the current tool call.
The unique identifier for this specific tool call, assigned by the model.
The name of the tool being called.
The raw argument map as supplied by the model before validation.
The full conversation message history at the time of tool invocation, including all prior assistant and tool messages in the current step loop.
ToolPackageInterface
ImplementToolPackageInterface to group related tools into a single registerable package.
Returns any iterable of tools (arrays, generators, or collections). Each item is resolved via
ToolResolver, so class names, Tool instances, and invokable objects are all accepted.Class-based tool example
ExtendTool directly to create a self-contained, reusable tool class. Implement __invoke as the handler — the SDK detects it automatically.