Skip to main content
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:
Or register them in the registerTools() method by instantiating:
Or add them at runtime:

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 fluent Tool 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 the registerTools() method in your agent:

Fluent API Reference

Using DataModel with Inline Tools

Use addProperty() with a DataModel class as the type:
Or use addDataModelAsProperties() to use an entire DataModel as your tool’s input:

Callback Options

The setCallback() method accepts any PHP callable, including:

Runtime Tool Addition

Add inline tools at runtime using withTool():

Context-Aware Tools Example


Choosing the Right Approach

Start with the #[Tool] attribute. Use Inline Tools when the tool depends on runtime context.

Next Steps

Attribute Tools

The recommended way to create tools.

Tool Configuration

Configure tool choice and parallel execution.