PHP code example of ririkana / agent-framework

1. Go to this page and download the library: Download ririkana/agent-framework 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/ */

    

ririkana / agent-framework example snippets


use Ririkana\AgentFramework\Domain\Agent\AgentKey;
use Ririkana\AgentFramework\Domain\Agent\AgentManifest;
use Ririkana\AgentFramework\Domain\Agent\AgentVersion;
use Ririkana\AgentFramework\Domain\Agent\ManifestStatus;

$manifest = AgentManifest::create(
    key: new AgentKey('customer-support'),
    version: new AgentVersion('1.0.0'),
    instructionProvider: 'You are a helpful customer support agent.',
    modelProfile: 'support-agent',
    toolPolicy: 'customer-tools',
    guardrailProfile: 'default',
    memoryPolicy: 'default',
    capabilities: ['text'],
    status: ManifestStatus::Published,
);

use Ririkana\AgentFramework\Contracts\AgentRegistry;

app(AgentRegistry::class)->register($manifest);

use Ririkana\AgentFramework\Contracts\ToolRegistry;

// Implement GovernedTool interface on your tool
app(ToolRegistry::class)->register(new LookupCustomerTool);

use Ririkana\AgentFramework\Contracts\AgentRuntime;
use Ririkana\AgentFramework\Domain\Context\ActorContext;
use Ririkana\AgentFramework\Domain\Context\ExecutionContext;
use Ririkana\AgentFramework\Domain\Context\TenantContext;
use Ririkana\AgentFramework\Domain\Context\TraceContext;

$context = new ExecutionContext(
    new TenantContext('customer-123'),
    new ActorContext('user-456', 'human'),
    'req-'.Str::uuid(),
    new TraceContext('00-'.bin2hex(random_bytes(16)).'-01'),
    'en',
    'web',
    new DateTimeImmutable,
);

$result = app(AgentRuntime::class)->execute(
    new AgentExecutionRequest($context, $manifest, 'Find order #9876')
);

echo $result->text;

$result = app(AgentRuntime::class)->execute($request);
// Read text, structured output, usage, and finish reason

use Ririkana\AgentFramework\Contracts\AgentDelegator;
use Ririkana\AgentFramework\Domain\Delegation\DelegationPolicy;

$policy = new DelegationPolicy(allowlist: [
    'parent-agent' => ['child-agent-1', 'child-agent-2'],
], maxDepth: 3, maxDescendants: 10);

$delegator = app(AgentDelegator::class);
$result = $delegator->delegate(
    new AgentDelegationRequest('parent-run-id', 'parent-agent', 'child-agent-1', 'Analyze this document'),
    $context,
);

use Ririkana\AgentFramework\Contracts\ImageGenerator;
use Ririkana\AgentFramework\Domain\Media\ImageGenerationRequest;

$generator = app(ImageGenerator::class);
$result = $generator->generate(
    new ImageGenerationRequest(prompt: 'A futuristic city skyline', aspectRatio: 'landscape', quality: 'high'),
    $context,
);
// $result->storagePath, $result->mimeType, $result->checksum, etc.

use Ririkana\AgentFramework\Contracts\SpeechSynthesizer;
use Ririkana\AgentFramework\Domain\Media\SpeechSynthesisRequest;

$synthesizer = app(SpeechSynthesizer::class);
$result = $synthesizer->synthesize(
    new SpeechSynthesisRequest(text: 'Your order has shipped', voiceId: 'nova'),
    $context,
);

use Ririkana\AgentFramework\Contracts\Transcriber;
use Ririkana\AgentFramework\Domain\Media\TranscriptionRequest;

$transcriber = app(Transcriber::class);
$result = $transcriber->transcribe(
    new TranscriptionRequest(sourcePath: 'meeting.mp3', diarization: true),
    $context,
);
echo $result->transcript;
bash
php artisan vendor:publish --tag=ririkana-agent-config
bash
php artisan ririkana-agent:install