feat(agent): 实现 Phase 4c 会话级记忆功能
- 新增 `SessionMemory` 结构体,基于 `MemoryStore` 按 namespace 隔离键值数据 - `AgentBuilder` 增加 `session_memory_backend` 配置入口 - `RuntimeBundle` 透传 `session_memory_backend` 字段 - `AgentSession` 将内联 `HashMap` 替换为完整的 `SessionMemory`,`set_session_data` 和 `get_session_data` 改为异步方法 - 新增 3 个内联测试,全量测试从 113 增至 116,clippy 0 警告
This commit is contained in:
@@ -68,6 +68,11 @@ pub struct RuntimeBundle {
|
||||
/// 传入时可在 `submit_turn` 内部将检索能力作为工具暴露给 LLM。
|
||||
pub retriever: Option<Arc<MemoryRetriever>>,
|
||||
|
||||
/// SessionMemory 后端(选填)。
|
||||
/// 传入时 `SessionMemory` 使用该后端(支持跨进程共享);
|
||||
/// 不传时 `AgentSession` 内部自动创建 `InMemoryStore` 作为进程级隔离的后端。
|
||||
pub session_memory_backend: Option<Arc<dyn MemoryStore>>,
|
||||
|
||||
/// 运行时配置。
|
||||
pub config: AgentConfig,
|
||||
}
|
||||
@@ -79,6 +84,10 @@ impl std::fmt::Debug for RuntimeBundle {
|
||||
.field("tool_names", &self.tool_registry.list_tools())
|
||||
.field("has_memory_store", &self.memory_store.is_some())
|
||||
.field("has_retriever", &self.retriever.is_some())
|
||||
.field(
|
||||
"has_session_memory_backend",
|
||||
&self.session_memory_backend.is_some(),
|
||||
)
|
||||
.field("config", &self.config)
|
||||
.finish()
|
||||
}
|
||||
@@ -96,6 +105,7 @@ impl RuntimeBundle {
|
||||
hook_executor: Arc<HookExecutor>,
|
||||
memory_store: Option<Arc<dyn MemoryStore>>,
|
||||
retriever: Option<Arc<MemoryRetriever>>,
|
||||
session_memory_backend: Option<Arc<dyn MemoryStore>>,
|
||||
config: AgentConfig,
|
||||
) -> Self {
|
||||
Self {
|
||||
@@ -104,6 +114,7 @@ impl RuntimeBundle {
|
||||
hook_executor,
|
||||
memory_store,
|
||||
retriever,
|
||||
session_memory_backend,
|
||||
config,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user