1. Go to this page and download the library: Download veda-ai/laravel-client 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/ */
veda-ai / laravel-client example snippets
namespace App\Tools;
use Illuminate\Contracts\JsonSchema\JsonSchema;
use Illuminate\Support\Facades\Auth;
use Sveda\LaravelClient\Contracts\HostTool;
class CreatePostTool implements HostTool
{
public function name(): string
{
return 'create_post';
}
public function description(): string
{
// This text is the prompt the model sees — say when to call the tool.
return 'Create a post for the current user. Call this whenever the user asks to create or publish a post. Invent a short title and body if the user did not specify them.';
}
public function schema(JsonSchema $schema): array
{
return [
'title' => $schema->string()->description('Post title.')->max(120),
'body' => $schema->string()->description('Post body.')->max(5000),
];
}
public function mode(): string
{
// HostTool::MODE_READ | MODE_WRITE | MODE_DELETE
return self::MODE_WRITE;
}
public function domain(): string
{
return 'posts';
}
public function handle(array $arguments): mixed
{
$post = Auth::user()->posts()->create([
'title' => $arguments['title'] ?? 'Untitled',
'body' => $arguments['body'] ?? '',
]);
return ['id' => $post->id, 'title' => $post->title];
}
}
use Sveda\LaravelClient\Facades\SvedaClient;
public function boot(): void
{
SvedaClient::host()->policyUsing(fn ($user) => $user->hasRole('agent') ? 'agent' : 'reader');
SvedaClient::host()->resolveToolsUsing(fn ($user) => [
new \App\Tools\SearchPostsTool,
new \App\Tools\CreatePostTool,
new \App\Tools\UpdatePostTool,
]);
// Optional: who may use the AI at all (default: any authenticated user).
SvedaClient::host()->authorizeUsing(fn ($user) => $user->is_active);
// Roles live in your app; Sveda stores named policies (admin → Policies).
// Optional: customize the visitor id sent to the sidecar (default: "host-{id}").
SvedaClient::host()->visitorIdUsing(fn ($user) => "user-{$user->id}");
}