PHPackages                             johannes85/ai-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. johannes85/ai-bundle

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

johannes85/ai-bundle
====================

Adds AI support to Symfony. Allows easy calling of LLMs like Ollama, OpenAI, GoogleAI, MistralAI, Anthropic, DeepSeek. It also adds an MCP server and client.

v4.0.0(9mo ago)5775↓50%MITPHPPHP &gt;=8.2CI passing

Since Mar 20Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/johannes85/AiBundle)[ Packagist](https://packagist.org/packages/johannes85/ai-bundle)[ RSS](/packages/johannes85-ai-bundle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (12)Versions (18)Used By (0)

Symfony AI Bundle
=================

[](#symfony-ai-bundle)

[![example workflow](https://github.com/johannes85/AiBundle/actions/workflows/symfony-bundle.yml/badge.svg)](https://github.com/johannes85/AiBundle/actions/workflows/symfony-bundle.yml/badge.svg)

This PHP Symfony bundle allows to call LLM backends like OpenAI, Ollama etc. in a generic and simple way.

It also provides an MCP client and server with tool calling capabilities. This allows you to easily expose your Symfony services as MCP tools or call MCP tools provided by an MCP server.

The following backends are supported:

BackendText generationImage processingTool callingMCP Tool callingInfoOpenAI✅✅✅✅Ollama✅✅✅\*1✅GoogleAI✅✅✅✅Anthropic✅✅✅✅Mistral AI✅✅✅✅DeepSeek✅❌✅✅The **OpenAI** endpoint URL can be changed so it is possible to access different backends with an OpenAI compatible API. But be aware that not all features are supported by all backends.
=&gt; [Feedack](https://github.com/johannes85/AiBundle/issues/new) regarding the compatibility of the different backends is welcome.

- \*1: Tool choice settings other than ToolChoice::AUTO aren't supported by Ollama.

Requirements
------------

[](#requirements)

- PHP &gt;=8.2

Features
--------

[](#features)

### Backend independent generating:

[](#backend-independent-generating)

```
$messages = [
  new Message(MessageRole::HUMAN, 'Tell me about Canada')
];

$res = $opanAi->generate($messages);
...
$res = $ollama->generate($messages);
...
```

### Image processing:

[](#image-processing)

```
$messages = [
  new Message(
    MessageRole::HUMAN,
    'What is the content of this image?',
    files: [File::fromPath(FileType::IMAGE, 'image/jpg', __DIR__.'/image.jpg')]
  )
];
$res = $llm->generate($messages);
```

### Persistent message history:

[](#persistent-message-history)

See example: `AiBundle\Examples\PersistentChatCommand`

#### The following store backends are supported:

[](#the-following-store-backends-are-supported)

- PSR-6 compatible file cache: `AiBundle\Prompting\MessageStore\Psr6CacheMessageStore`

### Support for structured responses with deserialization in an object instance:

[](#support-for-structured-responses-with-deserialization-in-an-object-instance)

```
class CountryInfo {
  public string $name;

  // Usage of setter for further processing/validation of the set data
  private string $capital;
  public function setCapital(string $capital) {
    $this->capital = $capital;
  }

  // Array member type hinting via Attribute
  #[ArrayType(itemType: 'string')] public array $languages;
}

$info = $llm->generate([
  new Message(MessageRole::HUMAN, 'Tell me about Canada')
], responseDataType: CountryInfo::class);

/* Result:
CountryInfo#248 (3) {
  public string $name =>
  string(6) "Canada"
  private string $capital =>
  string(6) "Ottawa"
  public array $languages =>
  array(2) {
    [0] =>
    string(7) "English"
    [1] =>
    string(6) "French"
  }
}
*/
```

More information about how to define the schema of the response data type can be found in the [Schema Generator](docs/schema_generator.md) documentation.

### Tool calling support

[](#tool-calling-support)

```
$res = $this->llm->generate(
  [
    new Message(
      MessageRole::HUMAN,
      'What is the current weather in Karlsruhe (49° 1′ N , 8° 24′ O) and Stuttgart (48° 47′ N, 9° 11′ O), Germany'
    )
  ],
  toolbox: new Toolbox(
    [
      new CallbackTool(
        'getWeather',
        'Retrieves current weather',
        function (
          #[Description('Latitude, for example 52.52')] string $latitude,
          #[Description('Longitude, for example 13.41')] string $longitude
        ) use ($output) {
          return file_get_contents(
            'https://api.open-meteo.com/v1/forecast?latitude=' . $latitude . '&longitude=' . $longitude . '&current=temperature,windspeed'
          );
        }
      )
    ],
    toolChoice: ToolChoice::AUTO, // Can be also ToolChoice::FORCE_TOOL_USAGE or the name of a tool to enforce usage
    maxLLMCalls: 10 // Maximal number of LLM calls, set to a sensible value to avoid infinite loops or expensive calls. Default: 10
  )
)
```

More information about how to define the schema of the tool callback function be found in the [Schema Generator](docs/schema_generator.md) documentation.

### MCP tool calling

[](#mcp-tool-calling)

Calling tools provided by an MCP server via the stdio and Streamable HTTP transport is supported.

See the [MCP Client documentation](docs/mcp_client.md) for more information.

### MCP server

[](#mcp-server)

The MCP server allows to expose service methods as MCP tools via Streamable HTTP transport. It can be used to create a custom MCP server that can be called by LLMs or other clients.

See the [MCP Server documentation](docs/mcp_server.md) for more information.

Usage
-----

[](#usage)

### Configure LLM backend instances

[](#configure-llm-backend-instances)

To use a specific backend as a service, it has to be registered in the bundle config:

```
# ai.yaml
ai:
  llms:
    open_ai:
      default:
        apikey: '...'
        model: 'gpt-4o-mini'
      o3mini:
        apikey: '...'
        model: 'o3-mini'
    google_ai:
      default:
        apikey: '...'
        model: 'gemini-2.0-flash'
    mistral_ai:
      default:
        apikey: '...'
        model: 'mistral-small-latest'
    anthropic:
      default:
        apikey: '...'
        model: 'claude-3-5-sonnet-20241022'
    ollama:
      default:
        model: 'gemma3:latest'
    deep_seek:
      default:
        apikey: '...'
        model: 'deepseek-chat'
```

In this example, the following services will be registered:

- ai\_bundle.llm.open\_ai
- ai\_bundle.llm.open\_ai.o3mini
- ai\_bundle.llm.google\_ai
- ai\_bundle.llm.mistral\_ai
- ai\_bundle.llm.anthropic
- ai\_bundle.llm.ollama
- ai\_bundle.llm.deep\_seek

When configuring the "default" instance of a llm, in addition to the ID, the class itself (e.g. AiBundle\\LLM\\OpenAi\\OpenAi) will be registered as a service.

### Execute standalone examples

[](#execute-standalone-examples)

This bundle provides standalone examples of the features provided. They can be executed by a central console command similar to the Symfony console:

```
composer install
php bin/console example:... --llm= ollama
```

You can get a list of available examples by executing:

```
php bin/console
```

The llm backend to use can be set via the `--llm` option. The following values are supported:

- ollama (default)
- open\_ai
- google\_ai
- anthropic
- mistral\_ai
- deep\_seek

Before using the examples, you have to set the api key for the corresponding backend as an environment variable:

```
export MISTRAL_AI_APIKEY=...
export ANTHROPIC_APIKEY=...
export GOOGLE_AI_APIKEY=...
export OPEN_AI_APIKEY=...
export DEEP_SEEK_APIKEY=...
```

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance58

Moderate activity, may be stable

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~9 days

Total

17

Last Release

280d ago

Major Versions

0.0.12 → 1.0.02025-05-06

1.0.0 → 2.0.02025-06-22

2.0.0 → v3.0.02025-07-02

v3.0.2 → v4.0.02025-08-12

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/470531?v=4)[Johannes](/maintainers/johannes85)[@johannes85](https://github.com/johannes85)

---

Top Contributors

[![johannes85](https://avatars.githubusercontent.com/u/470531?v=4)](https://github.com/johannes85 "johannes85 (63 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/johannes85-ai-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/johannes85-ai-bundle/health.svg)](https://phpackages.com/packages/johannes85-ai-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[symfony/ai-platform

PHP library for interacting with AI platform provider.

51927.7k136](/packages/symfony-ai-platform)[web-auth/webauthn-framework

FIDO2/Webauthn library for PHP and Symfony Bundle.

50570.7k1](/packages/web-auth-webauthn-framework)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
