maestroerror/laragent
LarAgent is an open-source AI agent framework for Laravel. Build and maintain agents with an Eloquent-style API, pluggable tools (incl. MCP server support), memory/context management, multi-agent workflows, queues, and structured output for reliable integrations.
LarAgent is a highly Laravel-native package designed to integrate seamlessly with Laravel’s ecosystem, leveraging:
make:agent) for scaffolding.config/laragent.php).Key Fit Areas:
BeforeToolExecution) enable deep integration with Laravel’s event bus.Misalignment Risks:
| Integration Vector | Feasibility | Notes |
|---|---|---|
| Existing Eloquent Models | High | Agents can query/update models via tools (e.g., #[Tool] public function fetchUser($id)). |
| Laravel Queues | High | Async agent workflows via dispatch() or queue:work. |
| API Routes | High | Built-in OpenAI-compatible API endpoint (/api/agents/{agent}). |
| Third-Party APIs | Medium | Tools can call external APIs, but requires manual HTTP client setup (e.g., Guzzle). |
| Auth Systems | High | Per-user agent contexts via forUser() or custom history names. |
| Caching (Redis) | High | Cache-backed chat history (CacheChatHistory) supported. |
| Event Broadcasting | Medium | Events fire, but WebSocket broadcasting requires Laravel Echo setup. |
| Testing | High | Pest/PHPUnit support; manual tests provided for API keys. |
Critical Dependencies:
| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| Vendor Lock-in | Medium | Abstract LLM drivers (e.g., wrap OpenAiDriver in a service interface). |
| Cost Overruns | High | Implement rate limiting, token budgeting, and fallback providers (e.g., provider = ['openai', 'gemini']). |
| Tool Execution Failures | High | Use afterToolExecution hooks to retry failed tools or log errors to Sentry. |
| Context Window Limits | High | Configure default_truncation_threshold per provider; use CacheChatHistory for persistence. |
| Event Storm Complexity | Medium | Document event flow diagrams; use Laravel’s listen macro for conditional event handling. |
| Multi-Agent Coordination | Medium | Leverage Laravel’s queues for async workflows; consider ChainableTask for sequential agents. |
| Security | High | Sanitize tool inputs (e.g., validate $location in exampleWeatherTool); restrict API keys. |
Breaking Changes:
ToolCall objects added to events/hooks (requires migration of listeners).Use Case Clarity:
Provider Strategy:
['openai', 'gemini']).gpt-3.5-turbo vs. gpt-4).Scaling Needs:
Maintenance:
AfterToolExecution event.)Compliance:
DatabaseChatHistory.)LarAgent is optimized for Laravel-centric stacks with the following synergies:
User::find() via agent tools).YourAgent::dispatch($message)->delay(now()->addMinute())).AgentResponded for analytics).Non-Laravel Stacks:
| Phase | Actions | Tools |
|---|---|---|
| Assessment | Audit existing AI/automation workflows; identify agent candidates. | Postman (API testing), Laravel Tinker (agent prototyping). |
| Scaffolding | Generate agent stubs (php artisan make:agent); configure config/laragent.php. |
Artisan, laravel-debugbar for config validation. |
| Tool Integration | Replace manual API calls with agent tools (e.g., #[Tool] public function updateOrder()). |
IDE autocompletion, Pest for tool testing. |
| Provider Setup | Configure API keys in .env; test with default provider. |
env:dump to verify keys, telescope for provider logs. |
| Event Hooks | Add listeners for AgentResponded, BeforeToolExecution (e.g., logging, analytics). |
Laravel Events, Spatie Laravel Activity Log. |
| Deployment | Deploy with queue workers (laravel-queue:work); monitor API usage. |
Laravel Horizon, OpenAI rate limit monitoring. |
| Optimization | Tune default_truncation_threshold, enable parallelToolCalls for performance. |
Blackfire, Laravel Debugbar. |
Rollout Strategy:
| Component | Compatibility | Notes |
|---|---|---|
| Laravel 10/11 | Full | Tested in CI; uses Laravel’s event system. |
| PHP 8.3+ | Full | Enums, attributes, and typed properties required. |
| OpenAI API | Full | Default driver; supports Responses API for gpt-4. |
| Gemini/Claude | Partial | Requires custom driver (extend BaseDriver). |
| Redis | Full | CacheChatHistory supported. |
| Database | Full | DatabaseChatHistory for persistent storage. |
| Queues | Full | Async agent execution via Laravel queues. |
| Livewire/Inertia | Partial | Agents can power UIs, but requires custom WebSocket setup. |
| Horizon | Full | Monitor queue jobs for agent workflows. |
How can I help you explore Laravel packages today?