Skip to content

Commit 3cd93ed

Browse files
gladychr-hertel
authored andcommitted
Rewrite output processors from Agent side used by Platform
- Introduced a separate output processor, that accepts a result handler and gives the result of the Output data container to this handler. - removed dependency to symfony/ai-agent from composer file within platform subtree - added deptrac check
1 parent bc7036a commit 3cd93ed

File tree

19 files changed

+148
-2
lines changed

19 files changed

+148
-2
lines changed

.github/workflows/deptrac.yaml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: deptrac
2+
3+
on:
4+
push:
5+
paths-ignore:
6+
- 'src/*/doc/**'
7+
- 'src/**/*.md'
8+
pull_request:
9+
paths-ignore:
10+
- 'src/*/doc/**'
11+
- 'src/**/*.md'
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
15+
cancel-in-progress: true
16+
17+
jobs:
18+
deptrac:
19+
name: deptrac
20+
runs-on: ubuntu-latest
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
php-version: [ '8.4' ]
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v5
28+
29+
- name: Configure environment
30+
run: |
31+
echo COLUMNS=120 >> $GITHUB_ENV
32+
echo COMPOSER_UP='composer update --no-progress --no-interaction --ansi --ignore-platform-req=ext-mongodb' >> $GITHUB_ENV
33+
34+
- name: Setup PHP
35+
uses: shivammathur/setup-php@v2
36+
with:
37+
php-version: ${{ matrix.php-version }}
38+
39+
- name: Get composer cache directory
40+
id: composer-cache
41+
run: |
42+
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
43+
44+
- name: Cache packages dependencies
45+
uses: actions/cache@v4
46+
with:
47+
path: ${{ steps.composer-cache.outputs.dir }}
48+
key: ${{ runner.os }}-composer-packages-${{ matrix.php-version }}-${{ hashFiles('src/**/composer.json') }}
49+
restore-keys: |
50+
${{ runner.os }}-composer-packages-${{ matrix.php-version }}
51+
52+
- name: Install root dependencies
53+
uses: ramsey/composer-install@v3
54+
55+
- name: Build root packages
56+
run: php .github/build-packages.php
57+
58+
- name: Run DEPTRAC
59+
run: $COMPOSER_UP && vendor/bin/deptrac

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
],
88
"require-dev": {
99
"php": ">=8.2",
10+
"deptrac/deptrac": "^4.2",
1011
"php-cs-fixer/shim": "^3.75",
1112
"phpstan/phpstan-strict-rules": "^2.0",
1213
"symfony/filesystem": "^7.3|^8.0",

deptrac.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
deptrac:
2+
paths:
3+
- ./src
4+
exclude_files:
5+
- '#.*test.*#'
6+
layers:
7+
- name: Agent
8+
collectors:
9+
- type: classLike
10+
value: Symfony\\AI\\Agent.*
11+
- name: Platform
12+
collectors:
13+
- type: classLike
14+
value: Symfony\\AI\\Platform.*
15+
- name: Store
16+
collectors:
17+
- type: classLike
18+
value: Symfony\\AI\\Store.*
19+
ruleset:
20+
Platform: ~
21+
Agent:
22+
- Platform
23+
- orm
24+
- Store
25+
Store:
26+
- Platform
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\AI\Agent\OutputProcessor;
13+
14+
use Symfony\AI\Agent\Output;
15+
use Symfony\AI\Agent\OutputProcessorInterface;
16+
use Symfony\AI\Platform\Result\ResultHandlerInterface;
17+
18+
readonly class ResultOutputProcessor implements OutputProcessorInterface
19+
{
20+
public function __construct(
21+
private ResultHandlerInterface $resultProcessor,
22+
) {
23+
}
24+
25+
public function processOutput(Output $output): void
26+
{
27+
$this->resultProcessor->handleResult($output->result);
28+
}
29+
}

src/ai-bundle/tests/DependencyInjection/AiBundleTest.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,9 +683,23 @@ public function testTokenUsageProcessorTags()
683683

684684
$agentId = 'ai.agent.tracked_agent';
685685

686+
// Token usage determiner must exist for OpenAI platform
687+
$tokenUsageDeterminer = $container->getDefinition('ai.platform.token_usage_result_handler.openai');
688+
$outputTags = $tokenUsageDeterminer->getTag('ai.agent.token_usage_result_handler');
689+
690+
$foundTag = false;
691+
foreach ($outputTags as $tag) {
692+
if (($tag['agent'] ?? '') === $agentId) {
693+
$foundTag = true;
694+
break;
695+
}
696+
}
697+
698+
$this->assertTrue($foundTag, 'Token usage determiner should have output tag with full agent ID');
699+
686700
// Token usage processor must exist for OpenAI platform
687-
$tokenUsageProcessor = $container->getDefinition('ai.platform.token_usage_processor.openai');
688-
$outputTags = $tokenUsageProcessor->getTag('ai.agent.output_processor');
701+
$tokenOutputProcessor = $container->getDefinition('ai.platform.token_usage_processor.openai');
702+
$outputTags = $tokenOutputProcessor->getTag('ai.platform.token_usage_processor');
689703

690704
$foundTag = false;
691705
foreach ($outputTags as $tag) {

0 commit comments

Comments
 (0)