Skip to content

feat: Add automatic flush for batched messages, on AfterInvocationEvent hook and interval-based periodical flush#291

Merged
padmak30 merged 1 commit intomainfrom
batch-memory-auto-flush
Mar 3, 2026
Merged

feat: Add automatic flush for batched messages, on AfterInvocationEvent hook and interval-based periodical flush#291
padmak30 merged 1 commit intomainfrom
batch-memory-auto-flush

Conversation

@padmak30
Copy link
Contributor

@padmak30 padmak30 commented Mar 3, 2026

Description of changes:
Add automatic flush mechanisms for batched messages

Add two automatic flush mechanisms to AgentCoreMemorySessionManager
to ensure messages are persisted without manual intervention:

  1. AfterInvocationEvent hook: Automatically flushes buffered messages after agent invocation completes. Only registered when batching is enabled (batch_size > 1) to avoid unnecessary overhead.

  2. Interval-based flush: Periodically flushes messages at configurable intervals for long-running agents. Controlled by new optional flush_interval_seconds config parameter (default: None/disabled).

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

@padmak30 padmak30 requested review from a team and jariy17 March 3, 2026 03:57
Copy link
Contributor

@jariy17 jariy17 left a comment

Choose a reason for hiding this comment

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

Good. Just add nit that would reduce code complexity

pending = self.pending_message_count()
if pending > 0:
logger.debug("Interval flush triggered: %d message(s) pending", pending)
self._flush_messages()
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: __flush_messages will return early if the buffer is empty. Therefore, we don't need to precheck the buffer.

@padmak30 padmak30 merged commit bb4a1b7 into main Mar 3, 2026
20 checks passed
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