Skip to content

[Platform][Cache] Fix MessageBag handling#1742

Merged
OskarStark merged 1 commit into
symfony:mainfrom
Guikingone:fix/cached_platform
Mar 12, 2026
Merged

[Platform][Cache] Fix MessageBag handling#1742
OskarStark merged 1 commit into
symfony:mainfrom
Guikingone:fix/cached_platform

Conversation

@Guikingone

Copy link
Copy Markdown
Contributor
Q A
Bug fix? yes
New feature? no
Docs? no
Issues Fix #1734
License MIT

@Guikingone Guikingone changed the title [Platform] Better handling of MessageBag on CachePlatform [Platform] Fix handling of MessageBag on CachePlatform Mar 10, 2026
@Guikingone Guikingone force-pushed the fix/cached_platform branch from cf0385f to 15170b1 Compare March 10, 2026 10:38
@Guikingone Guikingone marked this pull request as ready for review March 10, 2026 10:42
@carsonbot carsonbot added Bug Something isn't working Platform Issues & PRs about the AI Platform component Status: Needs Review labels Mar 10, 2026
@OskarStark OskarStark changed the title [Platform] Fix handling of MessageBag on CachePlatform [Platform][CachePlatform] Fix handling of MessageBag on `` Mar 12, 2026
@OskarStark OskarStark changed the title [Platform][CachePlatform] Fix handling of MessageBag on `` [Platform][Cache] Fix MessageBag handling Mar 12, 2026
@OskarStark

Copy link
Copy Markdown
Contributor

Thank you Guillaume.

@OskarStark OskarStark merged commit 4fb3534 into symfony:main Mar 12, 2026
406 checks passed
@Guikingone Guikingone deleted the fix/cached_platform branch March 12, 2026 08:13
$normalizedInput = match (true) {
\is_string($input) => md5($input),
\is_array($input) => json_encode($input),
$input instanceof MessageBag => $input->getId()->toString(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Guikingone @OskarStark Sorry for not responding or suggesting a fix sooner. I've been keeping myself busy.

In your original comment #1734 (comment), you mention additional challenges in using normalizers. Is this what made you switch to using the MessageBag ID?

I don't think this is quite the right solution to the problem. IDs are freshly generated for each new bag, so this will not cache the results of the prompt even when the prompt is identical to a prior one.

I have an additional question about the new case introduced for array inputs. It no longer hashes the input, but uses its JSON-encoded string directly for the cache key. I imagine there must be limits to key length that this can violate. Has that been taken into consideration?

@Guikingone Guikingone Mar 12, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @villermen 👋🏻

You're right about the missing hash of the input when an array is submitted, I'll push a new PR for this one.

Regarding the message bag, it works if you're using the same bag over and over but you're right if the bag is updated during the process, my main concern about using normalizers is that the $input can be updated as you suggested and I wonder is the CachedPlatform should be in charge of checking this situation 🤔

One solution might be to use the latest user input as "cache key" and check if in the new bag, the input still the same, not perfect but as bags are just "bags" ... 🤔

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Continued in #1754 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working Platform Issues & PRs about the AI Platform component Status: Reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CachePlatform input gets shared when it's a MessageBag

4 participants