While the #[Tool] attribute is recommended for most use cases, Tool Classes and Inline Tools offer additional flexibility for reusable or dynamically generated tools.
Tool Classes
Tool classes are standalone PHP classes that encapsulate tool logic. They’re ideal for:- Complex tools with extensive logic
- Tools shared across multiple agents
- Tools requiring their own dependencies or configuration
Creating a Tool Class
The
handle() method replaces execute() for class-based tools from v1.2. It provides automatic DataModel and Enum conversion. The execute() method still works for backward compatibility.Registering Tool Classes
Add tool classes to the$tools property in your agent:
registerTools() method by instantiating:
Tool Class Properties
Property Definitions
Properties are OpenAPI compatible schemas. Each property in$properties can have:
Using DataModel as Input Schema
Define your entire tool schema using a DataModel class:DataModel in Properties Array
Mix DataModel classes directly in your$properties array:
Inline Tools
Inline tools are created programmatically using the fluentTool API. They’re ideal for:
- Tools that depend on runtime context (user state, request data)
- Dynamically generated tools based on configuration
- Quick prototyping before extracting to a class
Creating Inline Tools
Use theregisterTools() method in your agent:
Fluent API Reference
Using DataModel with Inline Tools
UseaddProperty() with a DataModel class as the type:
addDataModelAsProperties() to use an entire DataModel as your tool’s input:
Callback Options
ThesetCallback() method accepts any PHP callable, including:
Runtime Tool Addition
Add inline tools at runtime usingwithTool():
Context-Aware Tools Example
Choosing the Right Approach
Next Steps
Attribute Tools
The recommended way to create tools.
Tool Configuration
Configure tool choice and parallel execution.

