What Are Toolboxes?
Toolboxes let you group related tools into logical collections with built-in authorization support. Think of them as “tool bundles” that can be enabled or disabled based on user permissions, subscription tiers, or any other context.Organized Tools
Group related tools together for cleaner agent definitions
Built-in Authorization
Use Laravel Gates and Policies at both toolbox and tool levels
Dynamic Loading
Tools are loaded on-demand based on user context
Runtime Flexibility
Add or remove toolboxes at runtime based on conditions
Using Toolboxes in Agents
The easiest way to use toolboxes is to declare them in your agent’s$toolboxes property:
app/Agents/CustomerAgent.php
- Checks toolbox-level authorization for each toolbox
- Filters individual tools based on per-tool gates/policies
- Applies any conditional inclusion logic
- Merges authorized tools with the agent’s direct tools
Runtime Toolbox Management
You can add or remove toolboxes dynamically at runtime:Adding/Removing Toolboxes at Runtime
Checking Toolbox Status
Toolbox Inspection Methods
Creating Your First Toolbox
Generate a new toolbox using the Artisan command:Basic Toolbox Structure
app/Toolboxes/CustomerSupportToolbox.php
Authorization
Toolboxes support a powerful multi-level authorization system using Laravel’s built-in Gates and Policies.Toolbox-Level Gates
The simplest form of authorization uses a Laravel Gate:app/Toolboxes/AdminToolbox.php
AuthServiceProvider:
app/Providers/AuthServiceProvider.php
Toolbox-Level Policies
For more complex authorization logic, use a Policy:app/Toolboxes/PremiumToolbox.php
app/Policies/SubscriptionPolicy.php
When both a
$gate and $policy are defined, the policy takes precedence. Only one authorization method is checked.Per-Tool Gates
You can apply fine-grained authorization to individual tools within a toolbox:app/Toolboxes/FinanceToolbox.php
Per-Tool Policies
For even more control, use policies on individual tools:Per-Tool Policy Configuration
Conditional Tool Inclusion
For dynamic logic that goes beyond gates and policies, override theshouldIncludeTool() method:
app/Toolboxes/ContextAwareToolbox.php
Real-World Examples
Admin Toolbox with Gate
app/Toolboxes/AdminToolbox.php
Multi-Tenant Toolbox
app/Toolboxes/TenantToolbox.php
Feature-Flagged Toolbox
app/Toolboxes/ExperimentalToolbox.php
Best Practices
Group by Domain
Organize tools by business domain (orders, payments, support) rather than technical function
Use Gates for Simple Checks
Gates are perfect for role-based checks. Use policies for complex business logic
Keep Toolboxes Focused
A toolbox should have 3-8 related tools. Split large toolboxes into smaller ones
Prefer Toolbox Auth
Use toolbox-level authorization when possible. Per-tool auth adds complexity
API Reference
BaseToolbox Properties
BaseToolbox Methods
Agent Toolbox Methods
Artisan Command
Tools
Learn the basics of creating tools
Tool Pipelines
Chain tools together for sequential workflows