PHP code example of multek / laravel-agno-os
1. Go to this page and download the library: Download multek/laravel-agno-os 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/ */
multek / laravel-agno-os example snippets
use Multek\AgnoOS\Facades\AgnoOS;
use Multek\AgnoOS\Runs\AgentRunOptions;
$response = AgnoOS::forUser(
auth()->user(),
claims: ['tenant_id' => 'org-1', 'role' => 'member'],
scopes: ['agents:support:run', 'sessions:read'],
)->runAgent(
agentId: 'support',
message: 'Summarize my open requests.',
sessionId: 'conversation-123',
options: new AgentRunOptions(
dependencies: ['locale' => 'pt-BR'],
sessionState: ['draft_id' => 'draft-42'],
metadata: ['source' => 'dashboard'],
knowledgeFilters: ['category' => 'support'],
outputSchema: [
'type' => 'object',
'properties' => ['summary' => ['type' => 'string']],
'
$response = AgnoOS::forSystem()->runWorkflow(
workflowId: 'negotiation',
message: 'Start the negotiation.',
sessionId: 'conversation-123',
options: new AgentRunOptions(background: true),
);
AgnoOS::forSystem()->runAgent('support', 'Describe this photo.', files: [
['contents' => $bytes, 'name' => 'photo.jpg', 'mime' => 'image/jpeg'],
]);
$token = AgnoOS::tokens()->forUser(
auth()->user(),
scopes: ['agents:support:run', 'sessions:read'],
);
use Illuminate\Support\Facades\Cache;
use Multek\AgnoOS\Exceptions\AgentRunFailed;
use Multek\AgnoOS\Exceptions\AgentRunStreamFailed;
use Multek\AgnoOS\Facades\AgnoOS;
use Throwable;
public function handle(): void
{
$client = AgnoOS::forSystem(scopes: ['agents:intake:run', 'agents:intake:read']);
$key = "intake-run:{$this->batchId}";
$runId = Cache::get($key);
try {
$run = $runId === null
? $client->streamAgentRun(
'intake',
$this->message,
$this->sessionId,
onRunStarted: fn (string $runId) => Cache::put($key, $runId, now()->addHour()),
idleTimeout: 120,
)
: $client->resumeAgentRun('intake', $runId, $this->sessionId, idleTimeout: 120);
} catch (AgentRunFailed $e) {
// The run ended as ERROR or CANCELLED: the retry must start a fresh run, not resume this one.
Cache::forget($key);
throw $e;
} catch (AgentRunStreamFailed $e) {
// AgentRunWentSilent
use Illuminate\Support\Str;
$client = AgnoOS::withHeaders([
'X-Tenant-Context' => 'tenant-42',
'X-Correlation-ID' => (string) Str::uuid(),
])->withHttpOptions([
'timeout' => 120,
]);
$response = $client->rawRequest('POST', '/future/endpoint', [
'query' => ['version' => 'next'],
'headers' => ['X-Feature' => 'experimental'],
'json' => ['any_payload' => ['is' => 'accepted']],
]);
AgnoOS::config();
AgnoOS::agents();
AgnoOS::sessions(['user_id' => '42']);
AgnoOS::getRun('support', $runId, $sessionId);
AgnoOS::continueRun('support', $runId, $sessionId, ['input' => 'Go deeper']);
AgnoOS::cancelRun('support', $runId, $sessionId);
AgnoOS::request('GET', '/teams');
$body = AgnoOS::forSystem()->rawRequest('POST', '/workflows/negotiation/runs', [
'multipart' => [['name' => 'message', 'contents' => 'Go'], ['name' => 'stream', 'contents' => 'true']],
'stream' => true,
])->toPsrResponse()->getBody();