Tools (also known as function calling) allow your AI agents to interact with
external systems, APIs, and services, greatly expanding their capabilities
beyond simple text generation.
Tool Configuration
Tools in LarAgent can be configured using these properties in your Agent class:Creating Tools
There are three ways to create and register tools in your agent:#[Tool] Attribute
Best for service-based or static tools specific to a single agent.
registerTools Method
Ideal for dynamically creating tools based on runtime conditions or user
state.
Tool Classes
Perfect for complex tools that may be reused across multiple agents or
require extensive logic.
1. Using the Tool Attribute
The simplest approach is using the#[Tool] attribute to transform your agent’s methods into tools:
Using Enum Types with Tools
You can use PHP Enums to provide the AI with a specific set of options to choose from, as well as provide separate descriptions for each property (argument):2. Using the registerTools Method
This method allows you to programmatically create and register tools using theLarAgent\Tool class:
3. Using Tool Classes
For complex tools, you can create dedicated tool classes and add them to the$tools property:
Example Tool Class
Tool creation artisan command is comming soon…
Tool choice
You can set the tool choice for your agent using the following methods:forceTool method requires tool’s name as a parameter.Phantom Tools 👻
Phantom Tools are dynamically registered tools that are not executed on the LarAgent side, but instead returnsToolCallMessage
- You need to integrate with external services dynamically
- You want to handle tool execution outside of LarAgent
- You need to make tool registration/execution available from API
Chainable Tool Methods
You can dynamically add or remove tools during runtime usingwithTool and removeTool methods:
Add tool with instance
Best Practices
Do create separate tool classes for complex functionality that might be
reused
Do provide clear, descriptive names and parameter descriptions
Do use Enums when you need to restrict the AI to specific options

