feat: add async support to MemorySessionManager#478
Conversation
✅ No Breaking Changes DetectedNo public API breaking changes found in this PR. |
c11771c to
228790d
Compare
Hweinstock
left a comment
There was a problem hiding this comment.
changes LGTM! I think an integ test for this flag would be awesome (perhaps as a follow-up), and perhaps worth getting @jariy17 to take a look.
| "Sync invocation will raise RuntimeError from Strands' hook registry." | ||
| ) | ||
|
|
||
| registry.add_callback(AgentInitializedEvent, lambda event: self.initialize(event.agent)) |
There was a problem hiding this comment.
note (for my own understanding): because this path doesn't call RepositorySessionManager.register_hooks, we must manually register the initialize hook: https://github.com/strands-agents/sdk-python/blob/main/src/strands/session/session_manager.py#L43.
In other words, we pick this synchronous hook from that implementation and leave out the rest to overwrite them with our own async hooks.
| if self.config.batch_size > 1: | ||
| registry.add_callback(AfterInvocationEvent, lambda event: self._flush_messages()) | ||
|
|
||
| async def _on_after_invocation_flush(event: AfterInvocationEvent) -> None: |
There was a problem hiding this comment.
nit: could we add a small helper to reduce boilerplate here?
Issue #, if available:
#452
Description of changes:
async_mode: bool = Falseon AgentCoreMemoryConfig. Opt-in; default preserves existing behavior.register_hooksinstalls async callbacks that wrap the existing sync methods inasyncio.to_thread()register_hookstime whenasync_mode=Truepointing users tostream_async/invoke_async— sync invocation will raise RuntimeError from Strands.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.