Slide 1

Slide 1 text

Agentic Applications with Symfony Christopher Hertel ‐ SymfonyLive Berlin 2025 1

Slide 2

Slide 2 text

Agenda Theory & Terminology Models, Context, RAG, and more Evolution from LLM to Agentic Code Examples with Symfony Model Context Protocol Distributed Agentic Applications 2

Slide 3

Slide 3 text

Christopher Hertel Software Engineer Focus on PHP, Symfony and GenAI Working on Tech Program of 3

Slide 4

Slide 4 text

Slides Scan and follow the slides online 4

Slide 5

Slide 5 text

Theory & Terminology Models, Context, RAG, and more 5

Slide 6

Slide 6 text

Models Language Model Trained to generate text based on text input Strong Competition & Fast Innovation OpenAI, Google, Meta, Anthropic, Mistral, and more Various Capabilities Streaming, structured output, multi-modal, real-time, tool calling Reasoning Model Decision making, less prompt engineering & more autonomous 6

Slide 7

Slide 7 text

Platforms Model Vendor OpenAI, Anthropic, Mistral, Google, ... General Cloud Provider Azure (GitHub), Google, AWS, ... Specialized Cloud Provider HuggingFace, Replicate, OpenRouter, ... Local Runtimes GPT4All, Ollama, ONNX Runtime, ... 7

Slide 8

Slide 8 text

Chain Chain of Calls Designed for multi-step interaction with models Combination of Things Platform, Models, System Prompts, Capabilities, etc. LangChain Most Famous LLM framework (Pyhton & TypeScript) 8

Slide 9

Slide 9 text

Plain Model Chain9

Slide 10

Slide 10 text

Context Stateless API Pre-trained, fine-tuned, but API "forgets" Limitation Size of context varies per model, but limited Powerful Control Mechanism Efficient to steer and evaluate the models generation 10

Slide 11

Slide 11 text

Context Example 11

Slide 12

Slide 12 text

RAG Architecture Retrieval Augmented Generation Dynamically inject information into context Improves Accuracy and Relevance More context for the model to work with, based on input Vector Stores Classic RAG combines embedding vectors and similarity search Improvement Techniques Pre-processing, Multi-Query, Reranking, and more 12

Slide 13

Slide 13 text

Simple RAG13

Slide 14

Slide 14 text

Tool Calling App Provides Tools Exposed to tool via JSON Schema definition as part of API call Model Invokes Tool As a 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 14

Slide 15

Slide 15 text

Tool Calling15

Slide 16

Slide 16 text

Agent vs. Agentic 16

Slide 17

Slide 17 text

PHP Libraries Listicle on GitHub LLPhant theodo-group/llphant Prism prism-php/prism LLM Chain php-llm/llm-chain Today 17

Slide 18

Slide 18 text

Evolution from LLM to Agent Code Examples with PHP & Symfony 18

Slide 19

Slide 19 text

Install LLM Chain composer require php-llm/llm-chain 19

Slide 20

Slide 20 text

Plain Model Chain20

Slide 21

Slide 21 text

Plain Model Chain use PhpLlm\LlmChain\Bridge\OpenAI\{GPT, PlatformFactory}; use PhpLlm\LlmChain\Chain; use PhpLlm\LlmChain\Model\Message\{Message, MessageBag}; $platform = PlatformFactory::create($apiKey); $chain = new Chain($platform, new GPT()); $messages = new MessageBag( Message::forSystem('You are a pirate and you write funny.'), Message::ofUser('What is the Symfony framework?'), ); $response = $chain->call($messages); echo $response->getContent(); 21

Slide 22

Slide 22 text

Symfony Integration composer require php-llm/llm-chain-bundle 22

Slide 23

Slide 23 text

Bundle Configuration # config/packages/llm_chain.yaml llm_chain: platform: openai: # or anthropic, azure, google, more to come ... api_key: '%env(OPENAI_API_KEY)%' chain: default: model: name: 'GPT' version: 'gpt-4o-mini' system_prompt: 'You are a pirate and you write funny.' 23

Slide 24

Slide 24 text

Usage in Symfony final readonly class SomeService { public function __construct(private ChainInterface $chain) { } public function someMethod(string $message): string { $messages = new MessageBag(Message::ofUser($message)); $response = $this->chain->call($messages); return $response->getContent(); } } 24

Slide 25

Slide 25 text

Simple RAG25

Slide 26

Slide 26 text

Tool Calling26

Slide 27

Slide 27 text

Tool Calling use PhpLlm\LlmChain\Chain\Toolbox\Attribute\AsTool; use Symfony\Component\Clock\ClockInterface; #[AsTool('clock', description: 'Returns the current date and time.')] final readonly class Clock { public function __construct(private ClockInterface $clock) { } public function __invoke(): string { return $this->clock->now()->format('Y-m-d H:i:s'); } } That's it already! 27

Slide 28

Slide 28 text

Agentic RAG28

Slide 29

Slide 29 text

Bundle Configuration # config/packages/llm_chain.yaml llm_chain: # Platform & Chain Configuration ... store: chroma_db: # or Azure Search, MongoDB, Pinecone, more to come ... symfonyblog: { collection: 'symfony_blog' } embedder: default: model: { name: 'Embeddings', version: 'text-embedding-ada-002' } services: _defaults: { autowire: true, autoconfigure: true } PhpLlm\LlmChain\Chain\Toolbox\Tool\SimilaritySearch: ~ 29

Slide 30

Slide 30 text

Agentic Application30

Slide 31

Slide 31 text

Bundle Configuration # config/packages/llm_chain.yaml llm_chain: # Platform Configuration ... chain: wikipedia: model: name: 'GPT' version: 'gpt-4o-mini' system_prompt: | Please answer the users question based on information of Wikipedia and provide a link to the article. tools: - 'PhpLlm\LlmChain\Chain\Toolbox\Tool\Wikipedia' 31

Slide 32

Slide 32 text

AI Tools32

Slide 33

Slide 33 text

Bundle Configuration Stack and isolate chains to build a more complex chain. # config/packages/llm_chain.yaml llm_chain: # Platform Configuration ... chain: complex_chain: # Model Configuration ... tools: # Chain in chain 🤯 - service: 'llm_chain.chain.blog' name: 'symfony_blog' description: 'Can answer questions based on the Symfony blog.' is_chain: true 33

Slide 34

Slide 34 text

Model Context Protocol Distributed Agentic Applications 34

Slide 35

Slide 35 text

Model Context Protocol (MCP) Open Sourced Protocol by Anthropic Only release late 2024, already exploded to everywhere Standardizes Five Aspects Resources, Prompts, Tools, Sampling, Roots Two Main Components Defines MCP Server and MCP Client JSON-RPC with Two Transports STDIO and Server-Sent-Events 35

Slide 36

Slide 36 text

General Architecture36

Slide 37

Slide 37 text

Agentic Application37

Slide 38

Slide 38 text

Model Context Protocol38

Slide 39

Slide 39 text

PHP MCP SDK No official SDK for PHP 39

Slide 40

Slide 40 text

But ... composer require php-llm/mcp-bundle 40

Slide 41

Slide 41 text

Bundle Configuration # config/packages/mcp.yaml mcp: app: 'app' # Application name to be exposed to clients version: '1.0.0' # Application version to be exposed to clients # Configure this application to act as a MCP server # For now ONLY TOOLS client_transports: stdio: true # Enable STDIO via command sse: true # Enable Server-Sent Event via controller # Configure MCP servers to be used by this application # NOT IMPLEMENTED YET servers: name: transport: 'stdio' # Transport method to use, either 'stdio' or 'sse' stdio: command: 'php /path/bin/console mcp' # Command to execute to start arguments: [] # Arguments to pass to the command sse: url: 'http://localhost:8000/sse' # URL to SSE endpoint of MCP serv 41

Slide 42

Slide 42 text

Work In Progress But let's have a look ... 42

Slide 43

Slide 43 text

Thank You! Any Questions? 43

Slide 44

Slide 44 text

Useful Links LLM Chain: github.com/php-llm/llm-chain Bundle: github.com/php-llm/llm-chain-bundle MCP SDK (WIP): github.com/php-llm/mcp-sdk Bundle (WIP): github.com/php-llm/mcp-bundle Other Libs: github.com/php-llm/ecosystem Model Context Protocol: modelcontextprotocol.io 44