News
1 min read
Laravel AI: Load Tools On Demand With ToolSearch
Reduce context window bloat in AI agents by dynamically loading tools on demand using ToolSearch in Laravel AI SDK.
Dynamic Tool Discovery in Laravel AI
When building complex AI agents with hundreds of available functions (such as CRM actions, database queries, and external APIs), sending every tool schema in the system prompt wastes context window tokens and increases response latency.
The Laravel AI SDK solves this with ToolSearch, allowing agents to dynamically query and activate only the tools necessary for the user's specific request.
use Laravel\AI\Agent;
use Laravel\AI\Tools\ToolSearch;
use App\AI\Tools\CreateInvoice;
use App\AI\Tools\SendSlackNotification;
class SupportAgent extends Agent
{
public function tools(): array
{
return [
ToolSearch::make([
CreateInvoice::class,
SendSlackNotification::class,
])->threshold(0.75),
];
}
}