PHP code example of datashaman / laravel-agent-tools
1. Go to this page and download the library: Download datashaman/laravel-agent-tools library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
datashaman / laravel-agent-tools example snippets
use DataShaman\LaravelAgent\Tools\Filesystem\ReadFile;
use DataShaman\LaravelAgent\Tools\Filesystem\WriteFile;
use DataShaman\LaravelAgent\Tools\Filesystem\EditFile;
use DataShaman\LaravelAgent\Tools\Filesystem\GlobFiles;
use DataShaman\LaravelAgent\Tools\Filesystem\GrepFiles;
use DataShaman\LaravelAgent\Tools\Execution\RunCommand;
use Laravel\Ai\Contracts\Agent;
use Laravel\Ai\Contracts\HasTools;
use Laravel\Ai\Promptable;
class CodeAssistant implements Agent, HasTools
{
use Promptable;
public function __construct(
private string $projectPath,
) {}
public function instructions(): string
{
return 'You are a code assistant with full filesystem and shell access.';
}
public function tools(): iterable
{
return [
new ReadFile(basePath: $this->projectPath),
new WriteFile(basePath: $this->projectPath),
new EditFile(basePath: $this->projectPath),
new GlobFiles(basePath: $this->projectPath),
new GrepFiles(basePath: $this->projectPath),
new RunCommand(
basePath: $this->projectPath,
timeout: 30,
allow: ['git *', 'composer *', 'php *'],
deny: ['rm -rf *', 'sudo *'],
),
];
}
}
use DataShaman\LaravelAgent\Support\InMemoryTaskStore;
use DataShaman\LaravelAgent\Tools\Tasks\TaskCreate;
use DataShaman\LaravelAgent\Tools\Tasks\TaskList;
use DataShaman\LaravelAgent\Tools\Tasks\TaskUpdate;
$store = new InMemoryTaskStore;
$tools = [
new TaskCreate($store),
new TaskList($store),
new TaskUpdate($store),
// ... other tools
];
use DataShaman\LaravelAgent\Support\ToolRegistry;
use DataShaman\LaravelAgent\Tools\Meta\ToolSearch;
$registry = new ToolRegistry([
new ReadFile(basePath: $path),
new WriteFile(basePath: $path),
new EditFile(basePath: $path),
new GlobFiles(basePath: $path),
new GrepFiles(basePath: $path),
new RunCommand(basePath: $path),
]);
// Agent starts with just ReadFile, GlobFiles, and ToolSearch
$tools = [
new ReadFile(basePath: $path),
new GlobFiles(basePath: $path),
new ToolSearch($registry),
];
use DataShaman\LaravelAgent\Support\InMemoryTaskStore;
use DataShaman\LaravelAgent\Support\ProcessManager;
use DataShaman\LaravelAgent\Tools\Execution\RunCommand;
$store = new InMemoryTaskStore;
$processManager = new ProcessManager($store);
// Async: background process via Laravel Process::start()
$tool = new RunCommand(
basePath: $path,
executor: 'async',
taskStore: $store,
processManager: $processManager,
);
// Queued: dispatched as a Laravel job
$tool = new RunCommand(
basePath: $path,
executor: 'queued',
taskStore: $store,
);
new EditFile(
basePath: $path,
description: 'Edit files. No restrictions.',
)