agentscope-ai / agentscope-ai/agentscope-java

[Feature]: Add Hooks to SessionManager and Implement Memory Limits

未关闭
#295 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
area/core/memory enhancement
主要语言
Java
星标
5.6k
派生
1.3k
平均合并
4 天 12 小时
30 天内合并 PR
77

描述

1. **Add a hooks mechanism to SessionManager**

Allow developers to inject custom logic at key lifecycle stages (e.g., before/after state updates, on save/load).
Refactor internal state to be strongly typed for better developer experience and safer operations.

2. **Introduce configurable memory limits**
Support setting max message count and max token limit per session or memory instance.
Provide eviction strategies (e.g., FIFO, LRU) to automatically trim history when limits are reached.

**Use Cases & Benefits**

- **External Storage & Memory Control**:
We use Minio for external session storage. With hooks, we can precisely enforce token/window limits—keeping short-term memory lightweight while preserving long-term context separately.

- **Dual Storage for Business Needs**: We store full conversation history in a relational database (by message) for on-demand paginated access. Hooks allow clean extraction and persistence without wrapping layers or workarounds.

- **Prevent OOM**: Enforcing token/message limits ensures system stability in long-running or high-volume conversation scenarios.

**Suggested Implementation Outline**

- Define a SessionManagerHooks interface with methods like onStateUpdate, beforeSave, afterLoad.
- Add MemoryLimitConfig with maxMessages and maxTokens options, coupled with a trimming mechanism.
- Refactor state to use typed structures instead of map.

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。