PHP code example of whilesmart / eloquent-agent-actions

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

    

whilesmart / eloquent-agent-actions example snippets


use Whilesmart\AgentActions\Traits\HasAgentActions;

class Workspace extends Model
{
    use HasAgentActions;
}

$workspace->agentActions()->create([
    'action_type' => 'send_mail',
    'payload' => ['to' => '[email protected]', 'subject' => 'Hi'],
    'metadata' => ['agent_run_id' => 42],
    'summary' => 'Email the customer',
    'risk' => 'medium',
]);

$action->source()->associate($chatMessage)->save();
$action->source;   // the chat message, resolved back through morphTo

use Whilesmart\AgentActions\Contracts\ActionHandler;
use Whilesmart\AgentActions\Models\AgentAction;

class SendMailHandler implements ActionHandler
{
    public function type(): string
    {
        return 'send_mail';
    }

    public function execute(AgentAction $action): mixed
    {
        // ... send the mail, optionally return the created record
    }
}

'handlers' => [
    App\AgentActions\SendMailHandler::class,
],

$actions = $workspace->proposeActionBatch([
    ['action_type' => 'record_transaction', 'payload' => ['amount' => 12.5]],
    ['action_type' => 'record_transaction', 'payload' => ['amount' => 40.0]],
], ['risk' => 'low']);          // second arg: attributes shared by every member

$batch = $actions->first()->batch;

// routes/console.php
Schedule::command('agent-actions:process-due')->everyMinute();