Skip to content

Integrate LLM Chain Bundle as AI Bundle #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 84 commits into from
Jun 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
33a2b61
feat: initial bundle setup
chr-hertel Jun 23, 2024
770bc12
feat: extend config to support different runtimes
chr-hertel Aug 18, 2024
01e5d8e
feat: make runtime config on model optional with single runtime
chr-hertel Aug 18, 2024
d3b078f
feat: add store config with ChromaDB
chr-hertel Aug 25, 2024
12aefbe
feat: add support for azure ai search store
chr-hertel Aug 26, 2024
6c26690
Use better example + typo fix
OskarStark Sep 21, 2024
2f04f8e
Require `llm-php/llm-chain`
OskarStark Sep 21, 2024
cdcae66
Merge pull request #1 from OskarStark/feature/example
chr-hertel Sep 21, 2024
202b715
Merge pull request #2 from OskarStark/feature/require-lib
chr-hertel Sep 21, 2024
fad354c
feat: introducing profiler
chr-hertel Sep 21, 2024
a545828
docs: fix examples & introduce profiler (#4)
chr-hertel Sep 21, 2024
a31f428
feat: adopt universal chain rework (#5)
chr-hertel Sep 21, 2024
218a067
docs: update after chain rework (#6)
chr-hertel Sep 21, 2024
0c0def2
feat: improved chain and tool rendering in profiler (#7)
chr-hertel Sep 21, 2024
a895253
feat: improving tool rendering in profiler (#8)
chr-hertel Sep 21, 2024
b6dc6b8
docs: readme fix for correctness and completeness (#9)
chr-hertel Sep 21, 2024
7d45b5b
fix: README (#10)
OskarStark Sep 22, 2024
96ed013
chore: require PHP 8.2 (#12)
OskarStark Sep 22, 2024
306d7d8
fix: readme typo (#14)
OskarStark Sep 22, 2024
c8756fb
fix: rename profiler tab (#13)
OskarStark Sep 22, 2024
2004ec6
fix: remove `composer.lock` (#11)
OskarStark Sep 22, 2024
322011b
fix: adopt to lib changes and bring in pipeline (#15)
chr-hertel Sep 22, 2024
33a69cb
chore: normalize composer.json (#16)
OskarStark Sep 23, 2024
1c23797
docs: update README.md for version 0.1 (#17)
OskarStark Sep 23, 2024
f3e2918
Require `php-llm/llm-chain:^0.1` (#19)
OskarStark Sep 24, 2024
21d9fc9
docs: better README (#21)
OskarStark Sep 25, 2024
6f9c1ed
refactor: rename `Runtime` to `Platform` (#20)
OskarStark Sep 25, 2024
ed6be06
fix: message visualization in profiler (#22)
chr-hertel Sep 25, 2024
b1450f5
chore: handle image support (#26)
chr-hertel Sep 26, 2024
8405efb
fix: chroma db namespace (#27)
chr-hertel Sep 26, 2024
b2802ee
feat: Add support for new MongoDB store (#24)
OskarStark Sep 26, 2024
1425851
feat: add pinecone store support (#28)
chr-hertel Sep 26, 2024
ebc1596
fix: Fix key (#29)
OskarStark Sep 27, 2024
a5dc93a
fix: set default values (#30)
OskarStark Sep 27, 2024
48d65fb
fix: Fix check for text property in user message content output (#31)
DZunke Sep 27, 2024
399917f
chore: phpunit setup (#32)
chr-hertel Sep 28, 2024
2399abb
chore: require `php-llm/llm-chain` 0.4 (#33)
OskarStark Sep 28, 2024
9f31a40
Require `php-llm/llm-chain` 0.5 (#34)
OskarStark Sep 30, 2024
363300a
ci: add PHP 8.4 to pipeline (#36)
chr-hertel Oct 1, 2024
3a08f92
refactor: namespace of `AsTool` attribute (#35)
chr-hertel Oct 2, 2024
ba527bf
chore: Require `php-llm/llm-chain` 0.7.0 (#38)
OskarStark Oct 3, 2024
8cfacf6
chore: update to latest llmchain changes (#39)
chr-hertel Oct 5, 2024
ac666de
feat: register processor interfaces for autoconfiguration (#40)
chr-hertel Oct 5, 2024
5a51a9f
feat: Describe version config (#41)
OskarStark Oct 15, 2024
485c97d
chore: limit llm-chain version for now to 0.7 (#43)
chr-hertel Nov 23, 2024
51de504
ci: surpress php cs fixer warning about php 8.4 (#44)
chr-hertel Nov 23, 2024
b264309
chore: phpstan 2.0 (#45)
chr-hertel Dec 7, 2024
1a3d710
feat: only render toolbar piece when llm chain is used (#46)
chr-hertel Dec 7, 2024
ca77abb
feat: adopt after release 0.8 & 0.9 (#42)
chr-hertel Dec 12, 2024
c3a8981
feat: Use class defaults if not set (#47)
OskarStark Dec 16, 2024
fa34561
Allo php-llm/llm-chain 0.10 (#48)
OskarStark Dec 19, 2024
ec4119e
fix: bundle should not throw errors on empty config (#51)
chr-hertel Dec 28, 2024
f7a9bf2
fix: readd processor tags for structured output and tools for default…
chr-hertel Dec 28, 2024
e81727c
fix: convert platform to lazy services (#53)
chr-hertel Dec 28, 2024
9ffa8d4
chore: update to llm-chain 0.11 (#54)
chr-hertel Dec 28, 2024
52746aa
feat: allow to use `false` for "no tools" (#55)
OskarStark Dec 29, 2024
d4e2ac3
feat: structured output in config of chain (#50)
chr-hertel Dec 30, 2024
f11f245
fix: consolidate tool config and make it work again (#56)
chr-hertel Dec 30, 2024
78d28bb
fix: adopt to ToolBox interface change (#59)
chr-hertel Jan 5, 2025
e427048
refactor: use plural for variable (#58)
OskarStark Jan 5, 2025
3406794
feat: make system prompt for chain configurable (#57)
OskarStark Jan 5, 2025
bf0a893
fix: processor var name (#60)
chr-hertel Jan 5, 2025
4bbfd7e
feat: extend logging and support event feature (#61)
chr-hertel Jan 5, 2025
2f0d8b7
fix: require symfony/string explicitly (#62)
OskarStark Jan 6, 2025
12a0cef
chore: require `php-llm/llm-chain` 0.14 (#63)
OskarStark Jan 6, 2025
5a06fd4
Fix: Embedder wiring (#64)
OskarStark Jan 9, 2025
ddc3a22
chore: lib update (#66)
chr-hertel Feb 5, 2025
81beb5c
feat: update for 0.16 - gemini & fault tolerant toolbox (#67)
chr-hertel Feb 22, 2025
e7889ee
chore: prepare with release 0.17 (#69)
chr-hertel Mar 7, 2025
cfb0f16
style: add rector (#70)
chr-hertel Mar 7, 2025
34c0838
ci: streamline with lib (#71)
chr-hertel Mar 7, 2025
48e1850
feat: support include tools feature to system prompt (#68)
OskarStark Mar 7, 2025
53fdc4e
chore: lib update (#73)
chr-hertel Mar 13, 2025
1e10544
chore: 0.19 compatibility (#74)
chr-hertel Mar 20, 2025
3aa39fd
feat: add inline tool definition and chain in chain 🤯 (#75)
chr-hertel Mar 20, 2025
ae3de42
fix: remove unwanted tools in system prompt by autowire (#77)
chr-hertel Apr 13, 2025
87db6c0
chore(dependencies): require `php-llm/llm-chain` 0.20 (#78)
OskarStark Apr 28, 2025
9132003
fix: model name argument on bundle extension/injection (#80)
chr-hertel Apr 28, 2025
345ad70
fix: profiler when using files as platform input (#81)
chr-hertel May 13, 2025
e8f7809
chore: support LLM Chain 0.21 (#84)
chr-hertel Jun 1, 2025
6c48c4f
chore: support LLM Chain 0.22 (#85)
chr-hertel Jun 1, 2025
e83812e
fix: support for 0.22 (#86)
chr-hertel Jun 1, 2025
2489972
refactor: restructure
chr-hertel Jun 13, 2025
a0c8943
refactor: integration llm-chain-bundle as ai-bundle into Symfony AI
chr-hertel Jun 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/ai-bundle/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/.github export-ignore
/tests export-ignore
.gitattributes export-ignore
.gitignore export-ignore
phpstan.dist.neon export-ignore
phpunit.xml.dist export-ignore
8 changes: 8 additions & 0 deletions src/ai-bundle/.github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Please do not submit any Pull Requests here. They will be closed.
---

Please submit your PR here instead:
https://github.com/symfony/ai

This repository is what we call a "subtree split": a read-only subset of that main repository.
We're looking forward to your PR there!
20 changes: 20 additions & 0 deletions src/ai-bundle/.github/workflows/close-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Close Pull Request

on:
pull_request_target:
types: [opened]

jobs:
run:
runs-on: ubuntu-latest
steps:
- uses: superbrothers/close-pull-request@v3
with:
comment: |
Thanks for your Pull Request! We love contributions.

However, you should instead open your PR on the main repository:
https://github.com/symfony/ai

This repository is what we call a "subtree split": a read-only subset of that main repository.
We're looking forward to your PR there!
5 changes: 5 additions & 0 deletions src/ai-bundle/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
vendor
composer.lock
.php-cs-fixer.cache
.phpunit.cache
coverage
19 changes: 19 additions & 0 deletions src/ai-bundle/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2025-present Fabien Potencier

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
176 changes: 176 additions & 0 deletions src/ai-bundle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
# Symfony AI Bundle

Integration bundle for Symfony AI components.

## Installation

```bash
composer require symfony/ai-bundle
```

## Configuration

### Simple Example with OpenAI

```yaml
# config/packages/ai.yaml
ai:
platform:
openai:
api_key: '%env(OPENAI_API_KEY)%'
agent:
default:
model:
name: 'GPT'
```

### Advanced Example with Anthropic, Azure, Google and multiple agents
```yaml
# config/packages/ai.yaml
ai:
platform:
anthropic:
api_key: '%env(ANTHROPIC_API_KEY)%'
azure:
# multiple deployments possible
gpt_deployment:
base_url: '%env(AZURE_OPENAI_BASEURL)%'
deployment: '%env(AZURE_OPENAI_GPT)%'
api_key: '%env(AZURE_OPENAI_KEY)%'
api_version: '%env(AZURE_GPT_VERSION)%'
google:
api_key: '%env(GOOGLE_API_KEY)%'
agent:
rag:
platform: 'symfony_ai.platform.azure.gpt_deployment'
structured_output: false # Disables support for "output_structure" option, default is true
model:
name: 'GPT'
version: 'gpt-4o-mini'
system_prompt: 'You are a helpful assistant that can answer questions.' # The default system prompt of the agent
include_tools: true # Include tool definitions at the end of the system prompt
tools:
# Referencing a service with #[AsTool] attribute
- 'Symfony\AI\Agent\Toolbox\Tool\SimilaritySearch'

# Referencing a service without #[AsTool] attribute
- service: 'App\Agent\Tool\CompanyName'
name: 'company_name'
description: 'Provides the name of your company'
method: 'foo' # Optional with default value '__invoke'

# Referencing a agent => agent in agent 🤯
- service: 'symfony_ai.agent.research'
name: 'wikipedia_research'
description: 'Can research on Wikipedia'
is_agent: true
research:
platform: 'symfony_ai.platform.anthropic'
model:
name: 'Claude'
tools: # If undefined, all tools are injected into the agent, use "tools: false" to disable tools.
- 'Symfony\AI\Agent\Toolbox\Tool\Wikipedia'
fault_tolerant_toolbox: false # Disables fault tolerant toolbox, default is true
store:
# also azure_search, mongodb and pinecone are supported as store type
chroma_db:
# multiple collections possible per type
default:
collection: 'my_collection'
embedder:
default:
# platform: 'symfony_ai.platform.anthropic'
# store: 'symfony_ai.store.chroma_db.default'
model:
name: 'Embeddings'
version: 'text-embedding-ada-002'
```

## Usage

### Agent Service

Use the `Agent` service to leverage models and tools:
```php
use Symfony\AI\Agent\AgentInterface;
use Symfony\AI\Platform\Message\Message;
use Symfony\AI\Platform\Message\MessageBag;

final readonly class MyService
{
public function __construct(
private AgentInterface $agent,
) {
}

public function submit(string $message): string
{
$messages = new MessageBag(
Message::forSystem('Speak like a pirate.'),
Message::ofUser($message),
);

return $this->agent->call($messages);
}
}
```

### Register Tools

To use existing tools, you can register them as a service:
```yaml
services:
_defaults:
autowire: true
autoconfigure: true

Symfony\AI\Agent\Toolbox\Tool\Clock: ~
Symfony\AI\Agent\Toolbox\Tool\OpenMeteo: ~
Symfony\AI\Agent\Toolbox\Tool\SerpApi:
$apiKey: '%env(SERP_API_KEY)%'
Symfony\AI\Agent\Toolbox\Tool\SimilaritySearch: ~
Symfony\AI\Agent\Toolbox\Tool\Tavily:
$apiKey: '%env(TAVILY_API_KEY)%'
Symfony\AI\Agent\Toolbox\Tool\Wikipedia: ~
Symfony\AI\Agent\Toolbox\Tool\YouTubeTranscriber: ~
```

Custom tools can be registered by using the `#[AsTool]` attribute:

```php
use Symfony\AI\Agent\Toolbox\Attribute\AsTool;

#[AsTool('company_name', 'Provides the name of your company')]
final class CompanyName
{
public function __invoke(): string
{
return 'ACME Corp.'
}
}
```

The agent configuration by default will inject all known tools into the agent.

To disable this behavior, set the `tools` option to `false`:
```yaml
ai:
agent:
my_agent:
tools: false
```

To inject only specific tools, list them in the configuration:
```yaml
ai:
agent:
my_agent:
tools:
- 'Symfony\AI\Agent\Toolbox\Tool\SimilaritySearch'
```

### Profiler

The profiler panel provides insights into the agent's execution:

![Profiler](./profiler.png)
48 changes: 48 additions & 0 deletions src/ai-bundle/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "symfony/ai-bundle",
"type": "symfony-bundle",
"description": "Integration bundle for Symfony AI components",
"license": "MIT",
"authors": [
{
"name": "Christopher Hertel",
"email": "[email protected]"
},
{
"name": "Oskar Stark",
"email": "[email protected]"
}
],
"require": {
"php": ">=8.2",
"symfony/ai-agent": "@dev",
"symfony/ai-platform": "@dev",
"symfony/ai-store": "@dev",
"symfony/config": "^6.4 || ^7.0",
"symfony/dependency-injection": "^6.4 || ^7.0",
"symfony/framework-bundle": "^6.4 || ^7.0",
"symfony/string": "^6.4 || ^7.0"
},
"require-dev": {
"phpstan/phpstan": "^2.1",
"phpunit/phpunit": "^11.5"
},
"config": {
"sort-packages": true
},
"autoload": {
"psr-4": {
"Symfony\\AI\\AIBundle\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Symfony\\AI\\AIBundle\\Tests\\": "tests/"
}
},
"repositories": [
{"type": "path", "url": "../agent"},
{"type": "path", "url": "../platform"},
{"type": "path", "url": "../store"}
]
}
7 changes: 7 additions & 0 deletions src/ai-bundle/phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
parameters:
level: 6
paths:
- src/
excludePaths:
analyse:
- src/DependencyInjection/Configuration.php
24 changes: 24 additions & 0 deletions src/ai-bundle/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
colors="true"
executionOrder="depends,defects"
requireCoverageMetadata="true"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
failOnRisky="true"
failOnWarning="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<source ignoreIndirectDeprecations="true" restrictNotices="true" restrictWarnings="true">
<include>
<directory>src</directory>
</include>
</source>
</phpunit>
Binary file added src/ai-bundle/profiler.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions src/ai-bundle/src/AIBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\AI\AIBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

/**
* @author Christopher Hertel <[email protected]>
*/
final class AIBundle extends Bundle
{
}
Loading