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 摘要。