Integrating Symfony AI with Webman: Build AI‑Powered PHP Chatbots

This guide explains how to install Symfony AI components, use the Gemini platform, and create a Webman endpoint that leverages AI for chat, RAG search, and intelligent agents, providing full code examples and response handling.

Open Source Tech Hub
Open Source Tech Hub
Open Source Tech Hub
Integrating Symfony AI with Webman: Build AI‑Powered PHP Chatbots

Overview

Symfony AI provides a set of Composer packages that let PHP applications call large language models without requiring the full Symfony framework.

Version 0.1.0 was released on 2025‑12‑24 and includes four main components:

Platform Component : a unified interface supporting OpenAI, Anthropic, Google Gemini, Azure, Mistral and other providers.

Store Component : abstraction for vector storage and retrieval, enabling Retrieval‑Augmented Generation (RAG).

Agent Component : tools for building AI agents and multi‑agent systems.

AI Bundle : Symfony‑specific integration (configuration, DI, debugging). The bundle is optional when using other frameworks.

Webman framework

Webman is a high‑performance, resident‑memory PHP framework built on Workerman. It does not depend on the Symfony kernel but can load any Composer package, allowing reuse of Symfony components such as Console, RateLimiter, and Lock.

Using Symfony AI in Webman

Because the AI packages are ordinary Composer libraries, they can be required directly in a Webman project. The AI Bundle, which relies on Symfony’s configuration system, may not work out‑of‑the‑box, but the Platform and Store components are fully functional.

1. Install components

composer require symfony/ai-platform   # Unified AI platform interface (core)
composer require symfony/ai-gemini-platform   # Gemini‑specific bridge package

2. Basic usage example

<?php
declare(strict_types=1);

namespace app\controller;

use support\Request;
use support\Response;
use Symfony\AI\Platform\Bridge\Gemini\PlatformFactory;
use Symfony\AI\Platform\Exception\ExceptionInterface;
use Symfony\AI\Platform\Message\Message;
use Symfony\AI\Platform\Message\MessageBag;
use Symfony\Component\HttpClient\HttpClient;

class GeminiController
{
    /**
     * Chat endpoint that forwards the user message to Google Gemini.
     *
     * @param Request $request
     * @return Response
     * @throws ExceptionInterface
     */
    public function chat(Request $request): Response
    {
        // Retrieve API key from environment or Webman config
        $apiKey = getenv('GOOGLE_API_KEY') ?: config('app.google_api_key');

        // Initialise Gemini platform
        $platform = PlatformFactory::create(
            $apiKey,
            HttpClient::create() // default HttpClient, can be customised
        );

        $userMessage = $request->post('message', '你好,介绍一下自己');

        // Build a message bag with a system prompt and the user message
        $messages = new MessageBag(
            Message::forSystem('你好!介绍一下webman 框架'),
            Message::ofUser($userMessage)
        );

        // Invoke the model synchronously
        $response = $platform->invoke(
            'gemini-2.5-flash',
            $messages,
            ['temperature' => 0.7]
        );

        return json([
            'reply' => $response->getResult()->getContent(),
        ]);
    }
}

Access the endpoint: http://127.0.0.1:8787/gemini/chat Sample JSON response:

{
  "reply": "好的,很高兴为您介绍 **Webman 框架**。
Webman 是一个 **高性能、轻量级的 PHP 微服务框架**。
它基于 Workerman 开发,旨在提供媲美 Go 语言的性能体验,让 PHP 也能轻松构建高并发、低延迟的服务。"
}

These steps demonstrate how to integrate Symfony AI components into a Webman application to build chatbots, RAG search, or intelligent agents.

backendPHPAI integrationWebmanSymfony AI
Open Source Tech Hub
Written by

Open Source Tech Hub

Sharing cutting-edge internet technologies and practical AI resources.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.