Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Symfony AI in Action

Symfony AI in Action

At first AI is a ton of buzzwords and hype, but how do we integrate AI in our existing products / software projects in a meaningful and realistic manner?
Let's have a look how Symfony AI enables us to bring AI-based or even agentic features, not only chatbots, into our PHP applications or scaled architecture.
If you are looking for input on how to approach AI, need ideas where to get started or find out what's realistic at first - let this talk be your inspiration!

Talk given at SymfonyCon Amsterdam 2025:
https://live.symfony.com/2025-amsterdam-con/schedule/practical-ai-integrations-with-symfony

Avatar for Christopher Hertel

Christopher Hertel

November 28, 2025
Tweet

More Decks by Christopher Hertel

Other Decks in Technology

Transcript

  1. Platform Component Abstraction Layer for Model Platforms Central Interface for

    Inference Model Platform Bridges Multi-Modal Compatible Integrated Event System 11
  2. Model Inference use Symfony\AI\Platform\Bridge\OpenAi\PlatformFactory; use Symfony\AI\Platform\Message\{Message, MessageBag}; $platform = PlatformFactory::create($apiKey);

    $input = new MessageBag( Message::forSystem('You are a pirate and you write funny.'), Message::ofUser('What is the Symfony framework?'), ); $result = $platform->invoke('gpt-5-mini', $input); echo $result->asText(); 5 6 7 8 9 10 11 12 13 14 15 16 17 18
  3. OpenAI GPT use Symfony\AI\Platform\Bridge\OpenAi\PlatformFactory; $result = $platform->invoke('gpt-5-mini', $input); 5 use

    Symfony\AI\Platform\Message\{Message, MessageBag}; 6 7 $platform = PlatformFactory::create($apiKey); 8 9 $input = new MessageBag( 10 Message::forSystem('You are a pirate and you write funny.'), 11 Message::ofUser('What is the Symfony framework?'), 12 ); 13 14 15 16 echo $result->asText(); 17 19
  4. Anthropic Claude use Symfony\AI\Platform\Bridge\Anthropic\PlatformFactory; $result = $platform->invoke('claude-sonnet-4-5-20250929', $input); 5 use

    Symfony\AI\Platform\Message\{Message, MessageBag}; 6 7 $platform = PlatformFactory::create($apiKey); 8 9 $input = new MessageBag( 10 Message::forSystem('You are a pirate and you write funny.'), 11 Message::ofUser('What is the Symfony framework?'), 12 ); 13 14 15 16 echo $result->asText(); 17 20
  5. Google Gemini use Symfony\AI\Platform\Bridge\Gemini\PlatformFactory; $result = $platform->invoke('gemini-3-pro-preview', $input); 5 use

    Symfony\AI\Platform\Message\{Message, MessageBag}; 6 7 $platform = PlatformFactory::create($apiKey); 8 9 $input = new MessageBag( 10 Message::forSystem('You are a pirate and you write funny.'), 11 Message::ofUser('What is the Symfony framework?'), 12 ); 13 14 15 16 echo $result->asText(); 17 21
  6. Mistral use Symfony\AI\Platform\Bridge\Mistral\PlatformFactory; $result = $platform->invoke('mistral-large-latest', $input); 5 use Symfony\AI\Platform\Message\{Message,

    MessageBag}; 6 7 $platform = PlatformFactory::create($apiKey); 8 9 $input = new MessageBag( 10 Message::forSystem('You are a pirate and you write funny.'), 11 Message::ofUser('What is the Symfony framework?'), 12 ); 13 14 15 16 echo $result->asText(); 17 22
  7. Streaming $result = $platform->invoke('mistral-large-latest', $input, [ 'stream' => true, ]);

    foreach ($result->asStream() as $word) { echo $word; } $input = new MessageBag( 10 Message::forSystem('You are a pirate and you write funny.'), 11 Message::ofUser('What is the Symfony framework?'), 12 ); 13 14 15 16 17 18 19 20 21 23
  8. Audio, Image & PDF Input $input = new MessageBag( Message::ofUser(

    'Describe the audio file.', Audio::fromDataUrl('data:audio/mpeg;base64,/9j/4AAQ...'), ), ); $result = $platform->invoke('gemini-2.5-flash', $input); echo $result->asText(); 10 11 12 13 14 15 16 17 18 19 Message::ofUser( 'Describe the audio file.', Audio::fromDataUrl('data:audio/mpeg;base64,/9j/4AAQ...'), ), $input = new MessageBag( 10 11 12 13 14 ); 15 16 $result = $platform->invoke('gemini-2.5-flash', $input); 17 18 echo $result->asText(); 19 24
  9. Audio, Image & PDF Input Message::ofUser( 'What is visible on

    the image?', new ImageUrl('https://example.org/elephant.jpg'), ), $input = new MessageBag( 10 11 12 13 14 ); 15 16 $result = $platform->invoke('gemini-2.5-flash', $input); 17 18 echo $result->asText(); 19 25
  10. Audio, Image & PDF Input Message::ofUser( 'Describe the content of

    the PDF file.', Document::fromFile('/path/to/document.pdf'), ), $input = new MessageBag( 10 11 12 13 14 ); 15 16 $result = $platform->invoke('gemini-2.5-flash', $input); 17 18 echo $result->asText(); 19 26
  11. Structured Output Message::forSystem('Help users as math tutor, step by step.'),

    Message::ofUser('how can I solve 8x + 7 = -23'), ); $input = new MessageBag( 10 11 12 13 14 $result = $platform->invoke('mistral-small-latest', $messages, [ 15 'response_format' => MathReasoning::class, 16 ]); 17 18 echo $result->asObject(); 19 'response_format' => MathReasoning::class, $input = new MessageBag( 10 Message::forSystem('Help users as math tutor, step by step.'), 11 Message::ofUser('how can I solve 8x + 7 = -23'), 12 ); 13 14 $result = $platform->invoke('mistral-small-latest', $messages, [ 15 16 ]); 17 18 echo $result->asObject(); 19 echo $result->asObject(); $input = new MessageBag( 10 Message::forSystem('Help users as math tutor, step by step.'), 11 Message::ofUser('how can I solve 8x + 7 = -23'), 12 ); 13 14 $result = $platform->invoke('mistral-small-latest', $messages, [ 15 'response_format' => MathReasoning::class, 16 ]); 17 18 19 27
  12. Embeddings Models Semantic Vectors are LLMs little sibling $result =

    $platform->invoke('text-embedding-3-small', $text); echo $result->asVector(); // array of floats 29
  13. Hugging Face Integration with Hugging Face's Inference Hub API use

    Symfony\AI\Platform\Bridge\HuggingFace\Task; $result = $platform->invoke('facebook/detr-resnet-50', $image, [ 'task' => Task::OBJECT_DETECTION, ]); echo $result->asObject(); // image classification result 30
  14. Bundle Configuration # config/packages/ai.yaml ai: platform: openai: # or anthropic,

    azure, google, more to come ... api_key: '%env(OPENAI_API_KEY)%' agent: default: model: 'gpt-4o-mini' prompt: 'You are a pirate and you write funny.' # more options ... store: chroma_db: symfonycon: collection: 'symfony_blog' # multi_agent, indexer, vectorizer ... 34
  15. Agent Component Multi-Step Interaction with Model Combination of Things Platform

    & Model Collection of Messages/Prompts as Context Memory, Tools, and more Various Architectures From static workflows to autonomous orchestration 36
  16. Tool Calling App Provides Tools Exposed to tool via JSON

    Schema definition as part of API call Model Invokes Tool As an intermediate response the model invokes a tool (or multiple) Tool Result Result of tool call provided as next call to model Instrumentation Log and analyze tool calls, model invocations, and results 39
  17. Tool Calling use Symfony\AI\Agent\Toolbox\Attribute\AsTool; use Symfony\Component\Clock\ClockInterface; #[AsTool('cookbook_create_recipe', 'Creates a new

    recipe in the cookbook.')] final readonly class CookbookCreateRecipe { public function __construct(private EntityManagerInterface $clock) {} /** * @param Recipe $recipe The recipe to create in the cookbook. */ public function __invoke(Recipe $recipe): string { // validate & persist recipe ... return 'Recipe created successfully!'; } } 41
  18. Multi-Agent Architectures Level of Autonomy & Context Sharing Implemented Workflows

    Solved in user land Subagents as Tools Defined subtask & isolated context Orchestration with Handoff Central orchestrator agent & handsoff with context to subagents 44
  19. Subagent as Tool # config/packages/ai.yaml ai: # Platform Configuration ...

    agent: researcher: model: 'gpt-4o' prompt: 'You do heavy research.' smalltalker: model: 'gpt-4o-mini' tools: # Agent as tool 🤯 - agent: 'researcher' name: 'research_topic' description: 'Does research on a given topic.' 45
  20. Orchestration # config/packages/ai.yaml ai: # Platform Configuration ... agent: orchestrator:

    { # agent config ... } technical: { # agent config ... } billing: { # agent config ... } fallback: { # agent config ... } multi_agent: support: orchestrator: 'orchestrator' handoffs: technical: ['bug', 'error', 'code', 'debug'] billing: ['invoice', 'payment', 'bill', 'order'] fallback: 'fallback' 46
  21. Store Component Vector Store Abstraction Layer Lifecycle Management Adding &

    Querying for Documents Document Indexing Pipeline 1. Loading 2. Filtering 3. Transforming 4. Vectorizing 50
  22. Symfony AI Roadmap Multi-Agent Architectures Agent Tracing & Benchmarking Tools

    More Bridges for Platform, Store & Tools MCP Integration into Agent Support for Protocols like A2A & AG-UI Integration with PHP-ORT extension 57
  23. PHP-ORT (Oh Really, Tensors) High-Performance Tensor Mathematics Hardware Acceleration with

    CPU/GPT Support Compatible with ONNX Enabling Native PHP Model Inference Active Development by Joe Watkins and the PHP Foundation 58
  24. Join Symfony AI Initiative Checkout symfony/ai repository Especially examples/ and

    demo/ folders Build your first feature & give feedback Join SymfonyCon Hackathon this Saturday See you there or on GitHub.com! 61