[Platform][Cache] Fix MessageBag handling#1742
Conversation
Guikingone
commented
Mar 10, 2026
| Q | A |
|---|---|
| Bug fix? | yes |
| New feature? | no |
| Docs? | no |
| Issues | Fix #1734 |
| License | MIT |
MessageBag on CachePlatformMessageBag on CachePlatform
cf0385f to
15170b1
Compare
MessageBag on CachePlatformMessageBag on ``
MessageBag on ``MessageBag handling
|
Thank you Guillaume. |
| $normalizedInput = match (true) { | ||
| \is_string($input) => md5($input), | ||
| \is_array($input) => json_encode($input), | ||
| $input instanceof MessageBag => $input->getId()->toString(), |
There was a problem hiding this comment.
@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?
There was a problem hiding this comment.
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" ... 🤔