1. Go to this page and download the library: Download packstub/agents 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/ */
packstub / agents example snippets
use Packstub\Agents\Facades\Agents;
public function boot(): void
{
Agents::useAgent(\App\Ai\Agents\Assistant::class);
Agents::useServer(\App\Mcp\Servers\AcmeServer::class);
Agents::authorizeUsing(fn (string $ability) => auth()->user()->can($ability));
}
#[IsReadOnly]
#[Description('Find orders by number, customer, status and date.')]
class SearchOrders extends AgentTool
{
protected ?string $ability = 'orders.view';
protected function run(Request $request): array
{
$filters = AgentResources::normalizeFilters('orders', (array) $request->get('filters'));
$query = AgentResources::apply('orders', Order::query(), $filters);
return [
'total' => $query->count(),
'rows' => $query->limit($this->limit($request))->get()->map(fn (Order $o) => Orders::agentSummary($o))->all(),
];
}
public function schema(JsonSchema $schema): array
{
return [
'filters' => $schema->object(AgentResources::filterSchema($schema, 'orders')),
'limit' => $schema->integer(),
];
}
}
class AcmeServer extends \Packstub\Agents\Mcp\AgentServer
{
protected string $name = 'Acme';
protected string $instructions = 'The back office of an online shop. Start with search-orders.';
protected array $tools = [
Tools\SearchOrders::class,
\Packstub\Agents\Mcp\Tools\DrawChart::class,
Tools\ConfirmOrder::class,
];
}
class Assistant extends Agent
{
protected function persona(): string
{
return 'You are Ask Acme, the back-office assistant of an online shop.';
}
protected function domain(): string
{
return <<<'PROMPT'
- Orders move from placed to paid to shipped; a cancelled order keeps its number.
- Warehouse staff may confirm and ship; only managers may refund.
PROMPT;
}
}
Agents::useAgent(Assistant::class); // your Agent subclass
Agents::useServer(AcmeServer::class); // the MCP server class with the tool list
Agents::useTools([...]); // or a plain tool list
Agents::addTools([...]); // tools appended to the server's own list
Agents::useResources([Orders::class]); // the AgentResource classes
Agents::useMiddleware([AuditTurns::class]); // your own agent middleware
Agents::authorizeUsing(fn (string $ability) => ...); // how an ability is checked for the current person
Agents::roleLabelUsing(fn () => ...); // the person's role, for the prompt and refusals
Agents::credentialsUsing(fn () => new WorkspaceCredentials(...)); // a workspace's own provider key
Agents::limitsAuthorizeUsing(fn () => ...); // who may edit the agent_limits rows
Agents::tenantUsing(fn () => ...); // the current workspace