-
-
Notifications
You must be signed in to change notification settings - Fork 102
[Agent][Platform] Add support for native union types and list of polymporphic* types by using DiscriminatorMap
#585
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
Conversation
DiscriminatorMap
Maybe I miss something, but why do we need the public function __invoke(
Foo|Bar $myVar,
) {} Doesn't this contain enough information to resolve it? |
It might be, but the problematic case is a If Symfony Serializer would understand how to work with annotated |
DiscriminatorMap
DiscriminatorMap
I have one question, can we simplify the fixture classes to a bare minimum and use simple terminology? I now this is from your real world use case, but for tests, maintenance too much complexity for me. if we need the enum inside the union type, fine, if not, lets remove it or lets only keep 2 values etc. Thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation looks good to me as well, agree on the complexity issue with the fixture, and would love to see an example here - basically as to proof also for its functionality
@OskarStark I'll simplify and try to make the new DTOs examples more comprehensible max 'till Tomorrow. @chr-hertel when you ask for examples - you mean like the ones in PR description or something like |
lets add |
fixtures/StructuredOutput/PolymorphicType/ListItemDiscriminator.php
Outdated
Show resolved
Hide resolved
{ | ||
public function __construct( | ||
public string $name, | ||
#[With(pattern: '^name$')] public string $type = 'name', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#[With(pattern: '^name$')] public string $type = 'name', | |
#[With(pattern: '^name$')] | |
public string $type = 'name', |
I've simplified the examples to simpler objects and organized them in separated namespaces. I'm not sure why the pipeline fails with:
Locally the test runs correctly, and I'm on version 8.4.
None of us wants to introduce a ghost error the project, it'd be good to know why it has happened, and I, at the moment, have no clue. UPDATE |
@OskarStark @chr-hertel in the release 8.0 of the symfony/serializer package DiscriminatorMap doesn't implement I'm thinking of the following solutions:
Wdyt? 7.3: https://github.com/symfony/serializer/blob/7.3/Attribute/DiscriminatorMap.php EDIT |
src/agent/CHANGELOG.md
Outdated
* Add support for polymorphic types via DiscriminatorMap | ||
* Add support for union types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Add support for polymorphic types via DiscriminatorMap | |
* Add support for union types | |
* Add support for union types and polymorphic types via DiscriminatorMap |
One minor and good to merge |
…mporphic* types by using `DiscriminatorMap`
0ed5448
to
36f5bb4
Compare
Thanks for your work on this new feature! |
It's a draft, because, primarily, I want to ask if the DiscriminatorMap approach is ok with you.
Why the discriminator map usage?
I've achieved the native
list<Foo|Bar>
union type support for agent json schema output, but Symfony Serializer wasn't working with it correctly (list<TableDataVisualizationDto|ChartDataVisualizationDto>
), outputting an array in\Symfony\Component\Serializer\SerializerInterface::deserialize::112
. If you know how to make the serializer work with the "nested" union types correctly, then let me know and we might achieve a native support without the DiscriminatorMap usage.Example
This is an example from my project I want the feature to work on.
Model I tried it with:
gpt-5-nano
with theSymfony\AI\Platform\Bridge\OpenAi\Gpt
model class.Prompt:
Schema produced:
Schema dump
The description is long enough, so I'd skip the PHP DTOs structure. They look almost identical to the ones I used in tests in the PR.
Output (the data are fake):
Output dump