Skip to content

feat: add async support to MemorySessionManager#478

Open
nborges-aws wants to merge 1 commit into
mainfrom
fireAndForget
Open

feat: add async support to MemorySessionManager#478
nborges-aws wants to merge 1 commit into
mainfrom
fireAndForget

Conversation

@nborges-aws
Copy link
Copy Markdown
Contributor

Issue #, if available:
#452

Description of changes:

  • New async_mode: bool = False on AgentCoreMemoryConfig. Opt-in; default preserves existing behavior.
  • When True, register_hooks installs async callbacks that wrap the existing sync methods in asyncio.to_thread()
  • logger.warning at register_hooks time when async_mode=True pointing users to stream_async / invoke_async — sync invocation will raise RuntimeError from Strands.
  • 7 new tests covering newly added logic

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 12, 2026

✅ No Breaking Changes Detected

No public API breaking changes found in this PR.

Copy link
Copy Markdown
Contributor

@Hweinstock Hweinstock left a comment

Choose a reason for hiding this comment

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

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))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: could we add a small helper to reduce boilerplate here?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants