-
-
Notifications
You must be signed in to change notification settings - Fork 102
[Chat] Introduce a new component #675
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/.github export-ignore | ||
/tests export-ignore | ||
.gitattributes export-ignore | ||
.gitignore export-ignore | ||
phpstan.dist.neon export-ignore | ||
phpunit.xml.dist export-ignore | ||
CLAUDE.md export-ignore | ||
AGENTS.md export-ignore |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
composer.lock | ||
vendor | ||
.phpunit.cache |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# AGENTS.md | ||
|
||
AI agent guidance for the Chat component. | ||
|
||
## Component Overview | ||
|
||
Library for building chats with agents using messages. Built on Platform and Agent components. | ||
|
||
## Architecture | ||
|
||
### Core Classes | ||
- **Chat** (`src/Chat.php`): Main orchestration class | ||
- **ChatInterface**: Contract for implementations | ||
- **MessageStoreInterface** High-level conversation storage interface | ||
|
||
### Key Features | ||
- **Bridge** (`src/Bridge/`): Storage capacity for messages and conversations | ||
|
||
## Essential Commands | ||
|
||
### Testing | ||
```bash | ||
vendor/bin/phpunit | ||
vendor/bin/phpunit tests/ChatTest.php | ||
vendor/bin/phpunit --coverage-html coverage/ | ||
``` | ||
|
||
### Code Quality | ||
```bash | ||
vendor/bin/phpstan analyse | ||
cd ../../.. && vendor/bin/php-cs-fixer fix src/chat/ | ||
``` | ||
|
||
## Processing Architecture | ||
|
||
### Built-in bridges | ||
- **CacheStore**: PSR-16 compliant storage | ||
- **InMemoryStore**: In-memory storage | ||
- **SessionStore**: Symfony HttpFoundation session storage | ||
|
||
## Dependencies | ||
|
||
- **Platform component**: Required for AI communication | ||
- **Agent component**: Required for agent interaction | ||
- **Symfony**: HttpFoundation | ||
|
||
## Testing Patterns | ||
|
||
- Use `MockHttpClient` over response mocking | ||
- Test bridges independently | ||
- Prefer `self::assert*` in tests | ||
|
||
## Development Notes | ||
|
||
- Component is experimental (BC breaks possible) | ||
- Add `@author` tags to new classes | ||
- Use component-specific exceptions from `src/Exception/` | ||
- Follow `@Symfony` PHP CS Fixer rules |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CHANGELOG | ||
========= | ||
|
||
0.1 | ||
--- | ||
|
||
* Introduce the component |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# CLAUDE.md | ||
|
||
This file provides guidance to Claude Code (claude.ai/code) when working with code in the Agent component. | ||
|
||
## Component Overview | ||
|
||
Library for building chats with agents using messages. Built on Platform and Agent components. | ||
|
||
## Architecture | ||
|
||
### Core Classes | ||
- **Chat** (`src/Chat.php`): Main orchestration class | ||
- **ChatInterface**: Contract for implementations | ||
- **MessageStoreInterface** High-level conversation storage interface | ||
|
||
### Key Features | ||
- **Bridge** (`src/Bridge/`): Storage capacity for messages and conversations | ||
|
||
## Essential Commands | ||
|
||
### Testing | ||
```bash | ||
vendor/bin/phpunit | ||
vendor/bin/phpunit tests/ChatTests.php | ||
vendor/bin/phpunit --coverage-html coverage/ | ||
``` | ||
|
||
### Code Quality | ||
```bash | ||
vendor/bin/phpstan analyse | ||
cd ../../.. && vendor/bin/php-cs-fixer fix src/chat/ | ||
``` | ||
|
||
## Processing Architecture | ||
|
||
### Built-in bridges | ||
- **CacheStore**: PSR-16 compliant storage | ||
- **InMemoryStore**: In-memory storage | ||
- **SessionStore**: Symfony HttpFoundation session storage | ||
|
||
## Dependencies | ||
|
||
- **Platform component**: Required for AI communication | ||
- **Agent component**: Required for agent interaction | ||
- **Symfony**: HttpFoundation | ||
|
||
## Testing Patterns | ||
|
||
- Use `MockHttpClient` over response mocking | ||
- Test bridges independently | ||
- Prefer `self::assert*` in tests | ||
|
||
## Development Notes | ||
|
||
- All new classes should have `@author` tags | ||
- Use component-specific exceptions from `src/Exception/` | ||
- Follow Symfony coding standards with `@Symfony` PHP CS Fixer rules | ||
- The component is marked as experimental and subject to BC breaks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Symfony AI - Chat Component | ||
|
||
The Chat component provides a bridge for building chats with agents, sits on top of the Agent component, | ||
allowing you to create chats and submit messages to agents. | ||
|
||
**This Component is experimental**. | ||
[Experimental features](https://symfony.com/doc/current/contributing/code/experimental.html) | ||
are not covered by Symfony's | ||
[Backward Compatibility Promise](https://symfony.com/doc/current/contributing/code/bc.html). | ||
|
||
## Installation | ||
|
||
```bash | ||
composer require symfony/ai-chat | ||
``` | ||
|
||
**This repository is a READ-ONLY sub-tree split**. See | ||
https://github.com/symfony/ai to create issues or submit pull requests. | ||
|
||
## Resources | ||
|
||
- [Documentation](doc/index.rst) | ||
- [Report issues](https://github.com/symfony/ai/issues) and | ||
[send Pull Requests](https://github.com/symfony/ai/pulls) | ||
in the [main Symfony AI repository](https://github.com/symfony/ai) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"name": "symfony/ai-chat", | ||
"description": "PHP library for building chats with agents.", | ||
"license": "MIT", | ||
"type": "library", | ||
"keywords": [ | ||
"ai", | ||
"llm", | ||
"agent", | ||
"chat" | ||
], | ||
"authors": [ | ||
{ | ||
"name": "Christopher Hertel", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Oskar Stark", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": ">=8.2", | ||
"symfony/ai-agent": "@dev" | ||
}, | ||
"require-dev": { | ||
"phpstan/phpstan": "^2.0", | ||
"phpstan/phpstan-strict-rules": "^2.0", | ||
"phpunit/phpunit": "^11.5.13", | ||
"symfony/http-foundation": "^7.3|^8.0", | ||
"psr/cache": "^3.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Symfony\\AI\\Chat\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Symfony\\AI\\Chat\\Tests\\": "tests/", | ||
"Symfony\\AI\\PHPStan\\": "../../.phpstan/" | ||
} | ||
}, | ||
"config": { | ||
"sort-packages": true | ||
}, | ||
"extra": { | ||
"thanks": { | ||
"name": "symfony/ai", | ||
"url": "https://github.com/symfony/ai" | ||
} | ||
}, | ||
"minimum-stability": "dev" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
Symfony AI - Chat Component | ||
=========================== | ||
|
||
The Chat component provides an API to interact with agents, it allows to store messages and retrieve them later | ||
for future chat and context-retrieving purposes. | ||
|
||
Installation | ||
------------ | ||
|
||
Install the component using Composer: | ||
|
||
.. code-block:: terminal | ||
|
||
$ composer require symfony/ai-chat | ||
|
||
Basic Usage | ||
----------- | ||
|
||
To initiate a chat, you need to instantiate the ``Symfony\AI\Chat\Chat`` along | ||
with a ``Symfony\AI\Agent\AgentInterface`` and a ``Symfony\AI\Chat\MessageStoreInterface``:: | ||
|
||
use Symfony\AI\Agent\Agent; | ||
use Symfony\AI\Chat\Bridge\Local\InMemoryStore; | ||
use Symfony\AI\Chat\Chat; | ||
use Symfony\AI\Platform\Bridge\OpenAi\Gpt; | ||
use Symfony\AI\Platform\Bridge\OpenAi\PlatformFactory; | ||
use Symfony\AI\Platform\Message\Message; | ||
|
||
$platform = PlatformFactory::create($apiKey); | ||
$model = new Gpt(Gpt::GPT_4O_MINI); | ||
|
||
$agent = new Agent($platform, $model); | ||
$chat = new Chat($agent, new InMemoryStore()); | ||
|
||
$chat->submit(Message::ofUser('Hello')); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
includes: | ||
- ../../.phpstan/extension.neon | ||
|
||
parameters: | ||
level: 6 | ||
paths: | ||
- src/ | ||
- tests/ | ||
ignoreErrors: | ||
- | ||
message: "#^Method .*::test.*\\(\\) has no return type specified\\.$#" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
cacheDirectory=".phpunit.cache" | ||
colors="true" | ||
executionOrder="depends,defects" | ||
beStrictAboutOutputDuringTests="true" | ||
failOnRisky="true" | ||
failOnWarning="true"> | ||
<testsuites> | ||
<testsuite name="symfony/ai-agent"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<source ignoreIndirectDeprecations="true" restrictNotices="true" restrictWarnings="true"> | ||
<include> | ||
<directory>src</directory> | ||
</include> | ||
</source> | ||
</phpunit> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.