symfony/ai-agent
Experimental Symfony AI Agent component for building AI agents on top of the Platform and Store components. Create agents that interact with users, perform tasks, and orchestrate workflows, with optional tool bridges (search, scraping, maps, weather, files).
The Symfony AI Agent package offers a modular, pipeline-driven architecture that aligns well with Laravel’s service container, middleware, and event systems, making it a strong fit for Laravel applications requiring AI-driven automation, tool orchestration, or multi-agent workflows.
Strengths:
ToolCallRequested events align with Laravel’s event system, enabling observability and human-in-the-loop validation.Gaps/Challenges:
HttpClient, Serializer) could introduce version conflicts or require Laravel-specific wrappers.High feasibility for Laravel applications targeting:
Critical Integration Points:
Symfony Platform Dependency:
symfony/ai-platform (v0.8+), which may pull in non-Laravel-compatible packages (e.g., symfony/clock).illuminate/support to mock or wrap Symfony services where needed.Tool Bridges:
symfony/ai-serp-api-tool) are Laravel-agnostic but can be adapted via Laravel’s service container.$this->app->bind(
\Symfony\Component\Ai\Tool\SerpApiTool::class,
fn() => new SerpApiTool(config('services.serpapi.key'))
);
Memory Storage:
symfony/ai-store (e.g., for PostgreSQL/Redis vectors). TPMs can abstract this behind Laravel’s cache or a custom repository.Event System:
ToolCallRequested → dispatch a Laravel event).Technical Risks:
HttpClient or Platform requires custom test doubles (e.g., MockPlatform in PHPUnit).symfony/ai-platform clash with Laravel’s illuminate/http or guzzlehttp/guzzle?symfony/ai-filesystem-tool) critical, or can custom tools be built?Speech support), or is text-only sufficient?Best Fit For:
HttpClient, Serializer) or willing to adopt them.Avoid If:
| Phase | Action | Laravel-Specific Considerations |
|---|---|---|
| Evaluation | Install symfony/ai-agent and symfony/ai-platform in a sandbox. Test basic agent workflows (e.g., a chatbot with Wikipedia tool). |
Use Laravel’s config() to override Symfony defaults (e.g., API keys). |
| Dependency Setup | Resolve conflicts via composer.json overrides or Laravel’s aliases/bindings. |
Example: Bind Symfony’s Clock to Laravel’s Carbon for consistency. Use composer require symfony/clock --dev if only needed for testing. |
| Core Integration | Register the agent as a Laravel service and integrate with routes/controllers. | Use Laravel’s Route::middleware() to secure agent endpoints. Example: |
| ```php | ||
| // routes/web.php | ||
| Route::middleware(['auth:sanctum'])->post('/agent/chat', [AgentController::class, 'chat']); | ||
| ``` | ||
| Tool Integration | Adapt tool bridges to Laravel’s service container. For custom tools, extend AbstractTool and register via AppServiceProvider. |
Example: Wrap SerpApiTool in a Laravel command for CLI access or a facade for direct use. |
| ```php | ||
| // app/Providers/AppServiceProvider.php | ||
| public function register() { | ||
| $this->app->singleton(SerpApiTool::class, fn() => new SerpApiTool(config('services.serpapi.key'))); | ||
| } | ||
| Memory Setup | Choose a memory provider. For vector storage, integrate symfony/ai-store with Laravel’s cache or a custom repository. |
Use Laravel’s cache drivers (e.g., Redis) for StaticMemoryProvider or integrate a vector store like Weaviate via a custom EmbeddingProvider. |
| Event Integration | Map Symfony’s ToolCallRequested to Laravel events for observability. |
Example: Dispatch a custom AgentToolCalled event in a middleware or service. |
| Testing | Write unit tests for agents, tools, and processors. Use Laravel’s testing helpers (e.g., actingAs, assertDatabaseHas). |
Mock Symfony services with Laravel’s Mockery or PHPUnit’s createMock. Example: |
| ```php | ||
| public function test_agent_with_tool() { | ||
| $agent = $this->app->make(AgentInterface::class); | ||
| $this->mock(PlatformInterface::class)->shouldReceive('process')->andReturn(...); | ||
| } | ||
| Deployment | Deploy agents as Laravel jobs (for async) or API endpoints (for real-time). | Use Laravel Horizon for queue monitoring and scaling. Example: |
| ```php | ||
| // app/Console/Commands/RunAgentJob.php | ||
| class RunAgentJob implements ShouldQueue { | ||
How can I help you explore Laravel packages today?