Skip to content

feat(harness): support ordered async memory writes#2381

Open
March-77 wants to merge 1 commit into
agentscope-ai:mainfrom
March-77:agent/issue-2334-async-memory-writes
Open

feat(harness): support ordered async memory writes#2381
March-77 wants to merge 1 commit into
agentscope-ai:mainfrom
March-77:agent/issue-2334-async-memory-writes

Conversation

@March-77

Copy link
Copy Markdown

Fixes #2334

Problem / root cause

MemoryFlushMiddleware and MemoryMaintenanceMiddleware append LLM-backed work with concatWith, so an otherwise completed agent call holds the session gate until memory extraction and consolidation finish. A naive fire-and-forget subscription would remove that latency but could reorder writes for concurrent turns and lose accepted work during shutdown.

Changes

  • add MemoryConfig.ExecutionMode.ASYNC as an opt-in while retaining BLOCKING as the compatibility default
  • queue post-call flush and maintenance by the configured isolation key, preserving per-user/session order while allowing independent keys to run concurrently
  • snapshot the completed turn before enqueueing and offload raw session JSONL before optional LLM extraction
  • drain accepted memory operations from HarnessAgent.close() before workspace resources close
  • document the async lifecycle and configuration in English and Chinese memory guides

User impact

Latency-sensitive streaming and orchestration can configure .executionMode(MemoryConfig.ExecutionMode.ASYNC) so the agent Flux completes without waiting for memory LLM calls. Writes for the same isolation key stay ordered. Existing applications retain blocking completion behavior unless they opt in.

Tests

Compatibility / risk

BLOCKING remains the default. Async mode requires applications to close HarnessAgent during shutdown; close drains all accepted operations. The scheduler serializes work only within an isolation key, so unrelated users/sessions are not globally bottlenecked.

@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

@oss-maintainer oss-maintainer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Looks good.


Automated review by "github-manager-bot"

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.

[Feature]: 希望写入记忆能异步进行

2 participants