laravel-agent-native maintained by nataondev
Description
Turn Livewire components and Laravel services into agent-ready tools with PHP 8 attributes. One definition powers your UI, LLM tool calling, and MCP endpoints.
Last update
2026/09/23 21:10
(dev-main)
License
Downloads
2
laravel-agent-native
Inspired by the Agent-Native architecture pioneered by Builder.io, brought natively to the Laravel & Livewire ecosystem.
Define an action once — a plain PHP method with an attribute. Your Livewire UI calls it, and LLM agents get it as a standards-compliant tool. No duplicated schemas, no manual tool registries.
#[AgentAction(description: 'Add a product to the shopping cart')]
public function addItem(int $productId, int $quantity = 1): void
{
$this->items[] = compact('productId', 'quantity');
}
→ auto-compiled to OpenAI/MCP tool JSON, validated and executed through the container, with Livewire state/events in sync.
Install
composer require nataondev/laravel-agent-native
php artisan vendor:publish --tag=agent-native-config
- PHP 8.2+ · Laravel 11+ · Livewire 3+ or 4+ (optional)
How it works
- Annotate —
#[AgentAction]on any public method (service or Livewire component). - Compile — reflection builds the tool schema from native types, enums, and docblocks.
- Execute —
ActionExecutorvalidates arguments, resolves the class via the container, invokes, and returns a structuredActionResult. - React —
AgentBridgenotifies your app (and listening components) that the agent acted.
Documentation
| Guide | What's inside |
|---|---|
| Installation | Requirements, setup, registering classes |
| Defining actions | #[AgentAction], #[AgentParam], #[AgentExpose], docblocks |
| Type mapping | Scalars, arrays, backed/pure enums, nullability → JSON Schema |
| Executing actions | ActionExecutor, ActionResult, error codes |
| Livewire integration | InteractsWithAgent, AgentBridge, component state |
| HTTP endpoint | AgentToolsController routes, security, payloads |
| MCP server | Optional laravel/mcp bridge — actions as standard MCP tools |
| Artisan commands | agent:inspect, agent:cache, agent:clear, agent:mcp |
| Caching | Zero-reflection production boot |
Quick example
php artisan agent:inspect --json # tool schemas, ready for your LLM
use AgentNative\Laravel\Engine\ActionExecutor;
$result = app(ActionExecutor::class)->call('addItem', ['productId' => 42]);
$result->ok; // true
$result->output; // JSON-safe return value
Testing
composer test # Pest — 35 tests
composer lint # Pint
License
MIT