1. Go to this page and download the library: Download michal78/laravel-pandora 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/ */
michal78 / laravel-pandora example snippets
final class IssueRefund extends Tool
{
public function name(): string
{
return 'issue_refund';
}
public function description(): string
{
return 'Issue a refund for an existing order.';
}
public function rules(): array
{
// The JSON schema shown to the model is generated from these, so the
// interface it is told about and the one enforced cannot drift.
return [
'order_id' => 'rder::find($input->string('order_id')));
}
public function handle(ToolInput $input, ToolContext $context): ToolResult
{
$this->refunds->issue($input->string('order_id'), $input->integer('amount_minor'));
return ToolResult::success('Refund issued.');
}
}
$run = Pandora::agent('support')
->forUser($user)
->withContext(['order_id' => $order->getKey()])
->stream()
->dispatch('Help this customer resolve their order problem.');
// app/Tools/LookupOrder.php
namespace App\Tools;
use Pandora\Tools\Enums\RiskLevel;
use Pandora\Tools\Tool;
use Pandora\Tools\ToolContext;
use Pandora\Tools\ToolInput;
use Pandora\Tools\ToolResult;
final class LookupOrder extends Tool
{
public function name(): string
{
return 'lookup_order';
}
public function description(): string
{
return 'Look up an order by its reference.';
}
public function rules(): array
{
return ['reference' => ' $reference = (string) $input->string('reference');
return isset($orders[$reference])
? ToolResult::success("Order {$reference} {$orders[$reference]}.")
: ToolResult::failure('No order has that reference.');
}
}
// app/Agents/SupportAgent.php
namespace App\Agents;
use Pandora\Agents\AgentBlueprint;
use Pandora\Contracts\AgentDefinition;
final class SupportAgent implements AgentDefinition
{
public function define(AgentBlueprint $agent): AgentBlueprint
{
return $agent
->name('Support')
->instructions('Help customers resolve support issues.')
->tools(['lookup_order']);
}
}
// config/pandora.php -- in the file the installer published
'agents' => [
'definitions' => [App\Agents\SupportAgent::class],
],
'tools' => [
'registered' => [App\Tools\LookupOrder::class],
],