Beyond the Demo: Shipping Real AI Features

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →

Beyond the Demo: Shipping Real AI Features

Symfony AI gives you the components to ship AI features. It doesn't tell you how to structure them once they hit production. Human-in-the-loop approval, workflows that run for minutes instead of milliseconds, retries, cost tracking, and the extension points you reach for when the happy path stops being enough. This talk walks through the patterns that hold up in real applications, the ones that don't, and where the component boundaries actually sit. You'll leave with a working mental model for designing AI features, not just calling a model.

Talk was originally given in Nov 2026 atSymfonyCon in Warsaw.

Christopher Hertel

November 26, 2026

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

49 slides
  1. PROBLEMS What's wrong with the demo? 1 2 3 4

    Slow Performance No Validation Not Using Doctrine Flaky Results
  2. SLOW PERFORMANCE The whole chat is one agent call. App\Blog\Chat

    1 public function submitMessage(string $message): void 2 { 3 $messages = $this->loadMessages(); 4 $messages->add(Message::ofUser($message)); 5 6 $result = $this->agent->call($messages); 7 8 $messages->add( 9 Message::ofAssistant($result->getContent()), 10 ); 11 $this->saveMessages($messages); 12 } MessageBag + tools …and the request waits.
  3. SLOW PERFORMANCE Synchronous: nothing until everything. Symfony app Chat UI

    Inference API HTTP browser OpenAI · Ollama · … POST /chat messages + tools tool_call: search() tool result tool_call: fetch() run tool 200 · JSON typed.js animation tool result final answer timeouts · HTTP worker blocked time waiting… and waiting run tool
  4. FIRST LEVEL: UX The easy way: Streaming LLMs support streaming

    Symfony as well App\Stream\TwigComponent 1 public function streamContent(): EventStreamResponse 2 { 3 $messages = $this->chat->loadMessages(); Symfony UX enables Twig 4 $result = $this->agent->call($messages, ['stream' => true]); Messages chunk by chunk 6 5 return new EventStreamResponse(function () use ($result) { 7 foreach ($result->asTextStream() as $delta) { 8 // Render Twig Block 9 yield new ServerEvent($html); 10 11 12 } } });
  5. STREAMING Streaming: same wait, earlier words. Symfony app Chat UI

    Inference API HTTP browser POST /chat POST … stream: true chunk time reading along SSE data: … OpenAI · Ollama · … event: done [DONE] Symfony: still busy for the whole stream total time: unchanged
  6. STREAMING Stream more than the answer. Progress ThinkingDelta ToolCallStart BinaryDelta

    CommentaryStart AssistantMessageStreamList ener ThinkingSignature PartialObjectStreamListener ToolCallRequested DeltaEvent ToolInputDelta onStart() STAGE_TOOL_CALL ToolCallArgumentsResolved ChoiceDelta TextDelta PartialObjectDelta ToolCallSucceeded onDelta() ErrorEvent STAGE_HANDOFF WebSearchComplete STAGE_MODEL_REQUEST ToolCallFailed onComplete() ToolCallComplete ListenerInterface ThinkingComplete @fabpot ThinkingStart TraceableStreamListener CommentaryDelta TokenUsage Decision StartEvent MetadataDelta Result CommentaryComplete onError() ToolCallsExecuted @wachterjohannes ToolCall @franzwilding CompleteEvent @ghisleouf
  7. AGENT Recap: Tool Calls App\Movies\MovieFilter 1 final class MovieFilter 2

    { 3 public function __construct( 4 5 private readonly MovieRepository $movies, ) {} 6 7 #[AsTool('search_by_director', 'Find all movies of a director by their full name.')] 8 public function byDirector(string $director): array 9 { 10 11 return $this->movies->findByDirector($director); } 12 } ol to a as d re te is eg -r to au e: ut ib tr at e on + a plain service
  8. STREAMING Stream more than the answer. Commentary Tool sources 1

    $execution = $agent->call($messages, [ 1 // agent config: include_sources: true 2 2 $result = $execution->getResult(); 'stream' => true, 3 ]); 3 $sources = $result->getMetadata()->get('sources', []); 4 4 5 foreach ($execution->asStream() as $delta) { 5 foreach ($sources as $source) { 6 if ($delta instanceof CommentaryDelta) { 6 7 $note = $delta->getCommentary(); 7 $source->getReference(), 8 yield new ServerEvent($note, 'commentary'); 8 'source', 9 } 9 10 if ($delta instanceof TextDelta) { 10 } 11 12 yield new ServerEvent( ); yield new ServerEvent($delta->getText()); } 13 } "Let me search the blog…" tools add sources via HasSourcesTrait
  9. TOOL CALLS + SSE SSE updates: better UX, same blocked

    worker. Symfony app Chat UI Inference API HTTP browser OpenAI · Ollama · … POST /chat SSE running fetch() SSE answer tool_call: search() run tool tool result tool_call: fetch() run tool tool result final answer timeouts · HTTP worker blocked time sees what's happening SSE running search() messages + tools
  10. STRUCTURED OUTPUT Stream objects, not just text. Streamed object Response

    format App\Recipe\Chat App\Recipe\Data\Recipe 1 $execution = $this->agent->call($messages, [ 1 final class Recipe 2 'stream' => true, 2 { 3 'response_format' => Recipe::class, 3 /** @var string Name of the recipe */ public ?string $name = null; 4 ]); 4 5 5 6 foreach ($execution->asStreamedObject() as $recipe) { 6 /** @var int Duration in minutes */ #[Schema(minimum: 5, maximum: 240)] yield new ServerEvent(json_encode($recipe)); 7 public ?int $duration = null; 8 9 /** @var Ingredient[] List of ingredients */ public array $ingredients = []; 10 // … 7 8 } @wachterjohannes the recipe fills in, field by field 11 } the JSON schema comes from the class
  11. SECOND LEVEL: INFRASTRUCTURE The scalable way: Go Async Controller accepts

    and dispatches POST Controller dispatch Message Bus Messenger offloads to worker save Mercure brings it back to the client Different ways to slice into messages Chat UI Message Store SSE Mercure consume load · save Worker push Agent Loop
  12. ASYNC RUNTIME Accept fast. Work in the background. Push updates.

    Chat UI Mercure browser hub Symfony app HTTP Messenger queue Inference API Worker consume OpenAI · Ollama · … subscribe POST /chat 202 Accepted dispatch() free again update: running tool consume messages + tools tool_call tool result UI stays live update: answer final answer agent loop: no HTTP timeout time run tool
  13. ASYNC RUNTIME Accept in the request, answer in the worker.

    App\Movies\Chat App\Movies\AnswerHandler 1 $messages = $this->loadMessages() 1 #[AsMessageHandler] 2 2 public function __invoke(Answer $answer): void ->with(Message::ofUser($message)); 3 3 { 4 $this->messageStore->save($messages); 4 5 5 6 $this->bus->dispatch(new Answer( 6 ); 7 $messages->getId()->toRfc4122(), 7 $execution = $this->agent->call($messages, ['stream' => true]); 8 $this->getTopic(), 8 9 )); 9 @Guikingone $messages = $this->messageStore->load( UuidV7::fromString($answer->conversationId), foreach ($execution as $update) { 10 $html = $this->render($update); // a Twig block per step 11 $this->hub->publish(new Update($answer->topic, $html)); 12 } 13 } c pi to e th to ng ni te lis y ad re al is r se ow br e the request ends here: th
  14. ASYNC RUNTIME The worker brings its own problems. A redelivered

    message must not create a second answer. Don't retry a half-done answer: mark it failed. The browser must listen before the first update. Workers need their own time and memory limits. Mercure topics need authorization, too. Usual engineering problems
  15. ONE MESSAGE PER STEP Every turn is a worker message.

    dispatch(llm turn) tool_calls POST 202 Symfony app dispatch controller Orchestrator dispatch(search()) browser SSE Mercure update dispatch(fetch()) hub tool result for longer-running agent loops llm queue Tool worker tool queue Tool worker tool queue @ineersa in parallel tool result Chat UI LLM worker
  16. ONE MESSAGE PER STEP Long loops need guardrails. Symfony\AI\Agent\Agent A

    token budget, then answer-only mode A cap on the number of turns Stop on repeated tool calls A timeout for the whole run 1 public function __construct( 2 PlatformInterface $platform, 3 private readonly string $model, 4 private readonly iterable $inputProcessors = [], 5 private readonly iterable $outputProcessors = [], 6 // … 7 ?int $maxToolCalls = 50, 8 // … 9 ) {
  17. NO VALIDATION Validate the object, not just the JSON. Constraints

    Retry with the violations 1 final class Invoice 1 $invoice = $platform->invoke($model, $messages, [ 2 { 2 'response_format' => Invoice::class, 3 public function __construct( 3 'validate_response' => true, 4 #[Assert\NotBlank] 4 'validation_retries' => 2, 5 public string $number, 5 ])->asObject(); 6 #[Assert\GreaterThanOrEqual(0)] 7 public float $total, 8 /** @var LineItem[] */ 9 #[Assert\Valid, Assert\Count(min: 1)] 10 public array $lineItems, 11 re-asked with the violations, up to 2× ) {} 12 } asObject() throws on violations PR #3060 @valtzu
  18. NO VALIDATION Tool arguments get checked, too. #[Schema] on scalars

    #[Assert] on objects 1 #[AsTool('search_invoices', 'Search invoices.')] 1 final class InvoiceQuery 2 final class SearchInvoices 2 { 3 { 3 #[Assert\Regex('/^[A-Z]{2}\d{6}$/')] 4 public string $invoiceNumber; 4 public function __invoke( 5 #[Schema(pattern: '^[A-Z]{2}\d{6}$')] 5 #[Assert\Choice(['open', 'paid', 'overdue'])] 6 string $invoiceNumber, 6 public string $status; 7 #[Schema(enum: ['open', 'paid', 'overdue'])] 7 } 8 string $status, 8 9 // only reached with valid arguments 10 11 12 } 9 // in SearchInvoices ): string { 10 public function __invoke( } 11 @OskarStark @lyrixx #[MapToolArguments] InvoiceQuery $query, 12 ): string el od m e th to ck ba es go r ro er e th , ns invalid call: the tool never ru @ineersa
  19. NO VALIDATION Every step has a hook. Agent events messages

    Platform invoke() call() InputProcessor processInput() result ModelRoutingEvent InvocationEvent ResultEvent ResultConvertedEvent ResultErrorEvent loop until no tool calls event ToolCallsExecuted events tool calls OutputProcessor result Toolbox processOutput() execute() tool results ToolCallRequested ToolCallArgumentsResolved ToolCallSucceeded ToolCallFailed
  20. NOT USING DOCTRINE The blog lives in a second database.

    App DB Indexer posts embeddings ai:store:index blog filter · split · trim blog posts ahead of time Chroma DB symfony_blog question Chat UI Agent SimilaritySearch LLM + RAG Tool browser answer per question: RAG matching posts next to your app's database
  21. NOT USING DOCTRINE Your app already has a database. Doctrine

    with a relational database is already at hand PostgreSQL, MariaDB and SQLite can store vectors They can also calculate distance/similarity No extra infrastructure Enables hybrid queries on data pgvector · MariaDB 11.7+ · sqlite-vec
  22. NOT USING DOCTRINE One database for CRUD and RAG. Your

    App Doctrine ORM persist rows + embeddings entity + vector field embedded on flush forms · admin · API CRUD as usual PostgreSQL pgvector movie table + embedding question Chat UI Agent SimilaritySearch LLM + RAG Tool browser answer per question: RAG matching entities one database for both
  23. NOT USING DOCTRINE An entity, a store, a tool. App\Movies\Movie

    config/packages/ai.yaml 1 #[ORM\Entity] 1 ai: 2 class Movie 2 3 { 3 store: doctrine: 4 #[ORM\Column(type: 'vector', nullable: true)] 4 movies: 5 #[Embedding(from: [ 5 entity: 'App\Movies\Movie' vectorizer: 'ai.vectorizer.openai' 6 'title', 'year', 'director', 6 7 'cast', 'plot', 7 retriever: movies: 8 ])] 8 9 private ?VectorInterface $embedding = null; 9 store: 'ai.store.doctrine.movies' 10 vectorizer: 'ai.vectorizer.openai' 10 11 public function __construct( 11 12 #[ORM\Column] 12 13 public readonly string $title, 13 14 // … 14 15 16 } ) {} agent: movies: tools: - service: 'app.movies.similarity_search'
  24. FLAKY RESULTS From flaky to reliable. 1. Predictable agent behavior

    2. Context changes without side effects 3. Production insights & local reproduction
  25. CLOSING THE LOOP Ship. Observe. Learn. Ship again. release CI

    pipeline fix & proof production traces one trace contract local reproduction combine feedback signals pull down
  26. OBSERVABILITY · OPENTELEMETRY One trace, end to end. Chat UI

    Mercure browser hub Symfony app HTTP Messenger queue Inference API Worker consume OpenAI · Ollama · … subscribe POST /chat 202 Accepted dispatch() consume free again tool_call time update: running tool messages + tools run tool UI stays live context crosses the queue update: answer = carries traceparent tool result final answer trace view POST /chat messenger dispatch messenger consume chat tool search chat mercure publish 1 trace
  27. CLOSING THE LOOP How to close it. 1. Run context:

    one run ID through tools, events & results 2. Telemetry: traces to Langfuse, Jaeger, etc. ← OTel GenAI 3. Feedback: explicit & implicit signals per run 4. Eval: datasets, judges & gates in CI 5. Prompts & budgets: versioned rollouts, costs per run Not in v1.0, but a demo!
  28. CLOSING THE LOOP Evaluations: gate the release. Golden cases Dataset

    · YAML Context Prompt/Descriptions Evaluators Gates Tools called Pass rate Tool arguments Text assertions Limits Regressions From production Regression vs baseline Cost per case LLM judge at least nightly ai:eval:run in CI Exit 0 / 1 · Markdown · JUnit · JSON

More Decks by Christopher Hertel

Other Decks in Programming