PHP code example of agent-state-language / asl

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

    

agent-state-language / asl example snippets




use AgentStateLanguage\Engine\WorkflowEngine;
use AgentStateLanguage\Agents\AgentRegistry;

$registry = new AgentRegistry();
$registry->register('GreeterAgent', new MyGreeterAgent());

$engine = WorkflowEngine::fromFile('workflow.asl.json', $registry);
$result = $engine->run(['userName' => 'Alice']);

echo $result->getOutput(); // "Hello, Alice!"

use AgentStateLanguage\Engine\WorkflowEngine;
use AgentStateLanguage\Agents\AgentRegistry;
use ClaudeAgents\Agent;
use ClaudePhp\ClaudePhp;

// Create a claude-php-agent wrapped for ASL
$client = ClaudePhp::make(getenv('ANTHROPIC_API_KEY'));
$agent = Agent::create($client)
    ->withSystemPrompt('You are a helpful assistant.')
    ->withTools([...]);

// Register with ASL
$registry = new AgentRegistry();
$registry->register('Assistant', new ClaudeAgentAdapter('Assistant', $agent));

// Run workflow with advanced agent capabilities
$engine = WorkflowEngine::fromFile('workflow.asl.json', $registry);
$result = $engine->run(['task' => 'Analyze this code...']);