symfony/ai-agent
Framework for building AI agents on top of Symfony AI's Platform and Store components, letting agents interact with users, perform tasks and manage workflows. Experimental, not covered by Symfony's BC promise.
The Symfony AI Agent package (now v0.15.0) 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.class argument on asObject(): Improves static analysis and type safety. Teams running PHPStan/Psalm against their Laravel codebase will get better inference on tool/processor return types, reducing runtime surprises.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 at v0.8+ is now outdated — align the whole symfony/ai-* set (agent, platform, tools, store) to ^0.15 to avoid cross-version incompatibility.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:
InMemoryPlatform removed in favor of MockPlatformFactory. Any test or sandbox harness referencing InMemoryPlatform will fail on upgrade. This is confined largely to test code, but it confirms the experimental status and the need for a version-pin + upgrade cadence discipline.HttpClient or Platform requires custom test doubles. The v0.15.0 shift from InMemoryPlatform to MockPlatformFactory changes the mock pattern — update PHPUnit fixtures and any Laravel test base classes accordingly.InMemoryPlatform is a concrete example of churn to plan around.symfony/ai-platform (now ^0.15) clash with Laravel’s illuminate/http or guzzlehttp/guzzle?symfony/ai-filesystem-tool) critical, or can custom tools be built?asObject() class argument improves inference — factor it into coding standards for agent code.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 ^0.15 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. Pin all symfony/ai-* packages to the same 0.15 minor. |
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. Adopt v0.15.0 progress stage constants as the shared vocabulary for stage transitions. |
Example: Dispatch a custom AgentToolCalled event in a middleware or service; broadcast progress using the new stage constants. |
| Testing | Write unit tests for agents, tools, and processors. Replace any InMemoryPlatform usage with MockPlatformFactory (breaking change in v0.15.0). Use Laravel’s testing helpers (e.g., actingAs, assertDatabaseHas). |
Mock Symfony services with Laravel’s Mockery or PHPUnit’s createMock. Use the new asObject(class: ...) argument to improve static analysis in assertions. Example: |
| ```php | ||
| public function test_agent_with_tool() { | ||
| $agent = $this->app->make(AgentInterface::class); | ||
| $platform = (new MockPlatformFactory())->create(); | ||
| // ... | ||
| } | ||
| 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/Jobs/RunAgentJob.php | ||
| class RunAgentJob implements ShouldQueue { | ||
| use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
| public function handle(AgentInterface $agent): void { /* ... */ } | ||
| } |
symfony/ai-platform and siblings now targeted at ^0.15. Do not mix 0.14.x and 0.15.x across the family.InMemoryPlatform removed (replaced by MockPlatformFactory). asObject() gains an optional class argument (backward compatible). Progress stage constants added (additive).MockPlatformFactory in the test harness before committing to a broader rollout.symfony/ai-* packages at ^0.15.InMemoryPlatform). Budget for a per-minor upgrade review (changelog, test failures, vendor patches) rather than treating upgrades as routine.composer.lock, explicit ^0.15 constraints) is a hard requirement; floating constraints will break CI.asObject(class: ...) pattern to keep PHPStan/Psalm green as the package’s type surface evolves.InMemoryPlatform removal) — mitigate via pinned versions and a staged upgrade runbook.illuminate/* or guzzlehttp/guzzle — validate in CI on every Laravel minor bump.MockPlatformFactory) silently pass or fail; add a periodic audit of agent test fixtures.HttpClient/Serializer/Clock conventions in addition to Laravel idioms.MockPlatformFactory testing pattern and the progress stage constant vocabulary; both reduce friction once adopted.How can I help you explore Laravel packages today?