Skip to content

Conversation

@marco-jouwweb
Copy link

Q A
Bug fix? No
New feature? No
Docs? No
Issues Fix #922
License MIT

Description
The Chat::submit() function didn't support streaming. I have added support for this through:

  1. Creating the AccumulatingStreamResult wrapper which allows callback chaining and accumulates the full message (callbacks are fired once Generator in inner StreamResult is exhausted, aka when stream has completed)
  2. Wrap StreamResult classes with this wrapper inside the Chat::submit() function
  3. Create a small callback function which updates the Storage with a new AssistantMessage built from the accumulated message (as non-stream responses are also automatically added to storage in Chat::submit())

Other changes:

  • Added StreamableStoreInterface which indicates a Store implementation supports streaming. Currently added to all stores except SessionStorage (due to inherent issues with headers being already sent; deferred updates through callbacks go against nature of header/session lifecycles in Symfony; discussed with @Guikingone)
  • Fixed bug where metadata was not persisted in Chat::submit() (metadata was not transferred to new AssistantMessage we created)
  • Added tests for streaming and Chat::submit() combination

@carsonbot carsonbot changed the title Feature/stream support chat storage Feature/stream support chat storage Nov 21, 2025
@marco-jouwweb marco-jouwweb marked this pull request as draft November 21, 2025 11:36
@marco-jouwweb marco-jouwweb marked this pull request as ready for review November 21, 2025 12:11
foreach ($innerResult->getMetadata()->all() as $key => $metadataValue) {
$this->getMetadata()->add($key, $metadataValue);
}
$this->getMetadata()->set($innerResult->getMetadata()->all());
Copy link
Member

Choose a reason for hiding this comment

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

this is a behavior change since this is overwriting all metadata instead of extending it, right?

@OskarStark OskarStark changed the title Feature/stream support chat storage Added streaming support to Chat API & persistence to storage through accumulator callback chaining Nov 22, 2025
@OskarStark OskarStark added the Chat Issues & PRs about the AI Chat component label Nov 22, 2025
@carsonbot carsonbot changed the title Added streaming support to Chat API & persistence to storage through accumulator callback chaining [Chat] Added streaming support to Chat API & persistence to storage through accumulator callback chaining Nov 22, 2025
@OskarStark OskarStark changed the title [Chat] Added streaming support to Chat API & persistence to storage through accumulator callback chaining [Chat] Add streaming support & persistence to storage through accumulator callback chaining Nov 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Chat Issues & PRs about the AI Chat component Status: Needs Review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Chat][Store] Chat API & storage support for streaming

4 participants