Tool Management Made More Flexible in LarAgent

Tool Management Made More Flexible in LarAgent

We're excited to announce a major improvement in the flexibility and reliability of tool management within the agent system!

The latest PR introduces dynamic runtime management of tools, allowing you to add or remove tools on the fly. This enhancement addresses initialization issues, improves type safety, and ensures robust handling of tool instances and class references.

🔧 Key Features:

Now you can add a tool at runtime

With the newly created tool object

$tool = Tool::create('test_tool', 'Test tool')->setCallback(fn () => 'test');
$agent->withTool($tool);

With the predefined tool class

$agent->withTool(WeatherTool::class);

And you can remove tools at runtime:

With tool name

// Remove tool by name
$agent->removeTool('get_current_weather');

With the tool object

$tool = Tool::create('test_tool', 'Test tool')->setCallback(fn () => 'test');
$agent->withTool($tool);
if (!$needsTool) {
    $agent->removeTool($tool);
}

With the tool class

$agent->removeTool(WeatherTool::class);

🔄 Note: These changes will be deployed with version 0.4 soon. Stay tuned!

Read more