Commit f23adaf9 by sunqi02 Committed by 胡悦

将后端服务与agent服务的代码进行物理隔离

1 parent 9589ef25
Showing 19 changed files with 38 additions and 277 deletions
......@@ -10,7 +10,7 @@
1. 分层规范:
- 接口层:app/api/,只做参数校验和请求转发
- 服务层:app/service/,业务逻辑
- 服务层:app/service/,业务逻辑(Agent 核心运行时在 app/agent_core/,与 app/service/ 物理隔离)
- 基础设施层:app/infrastructure/,基础设施(DB、Redis、HTTP、消息队列)
- 配置层:app/config/,配置相关
- 数据层:app/model/,数据库ORM模型
......
......@@ -8,10 +8,10 @@ from pathlib import Path
from typing import Dict, List, Optional, Any
from app.config.loader import ConfigLoader
from app.config.settings import AgentConfig
from app.service.active_session_service import ActiveSessionService
from app.agent_core.active_session_service import ActiveSessionService
from agentscope.tool import Toolkit
from app.hooks.post_reply import PostReplyHook
from app.service.memory import SessionMemory
from app.agent_core.memory import SessionMemory
from agentscope.model import OpenAIChatModel
from agentscope.formatter import OpenAIChatFormatter as _OpenAIChatFormatter
from agentscope.message import Msg
......@@ -181,7 +181,7 @@ async def _bg_finalize_sub_agent(
channel="sub_agent",
)
sub_memory_msgs = await sub_agent.memory.get_memory()
from app.service.memory import SessionMemory
from app.agent_core.memory import SessionMemory
sub_session_memory = SessionMemory(
session_id=sub_session_id,
store=hub.session_service.store,
......
......@@ -12,7 +12,7 @@ from typing import Any, Dict, List, Optional
from app.config.loader import ConfigLoader
from app.hooks.post_reply import PostReplyHook
from app.service.active_session_service import ActiveSessionService
from app.agent_core.active_session_service import ActiveSessionService
logger = logging.getLogger(__name__)
......@@ -72,7 +72,7 @@ class MessageGate:
async def append_messages(self, session_id: str, messages: List[Dict[str, Any]]) -> None:
"""追加消息到 session buffer,使用 per-session 锁保证并发安全。"""
from app.service.session_buffer import SessionBuffer
from app.agent_core.session_buffer import SessionBuffer
from app.infrastructure.session_store import SessionStore
async with self._get_lock(session_id):
......@@ -98,7 +98,7 @@ class MessageGate:
bot_id_mapping: 由 endpoint 注入的 agent_key → bot_id 映射
wait_seconds: 等待窗口(默认 6 秒,测试时可缩短)
"""
from app.service.session_buffer import SessionBuffer
from app.agent_core.session_buffer import SessionBuffer
from app.infrastructure.session_store import SessionStore
store = SessionStore()
......@@ -201,7 +201,7 @@ class MessageGate:
pending: List[Dict[str, Any]],
) -> None:
"""chat 分支:追加用户消息到 conversation_history,不触发 AgentHub,不发 IM。"""
from app.service.memory import SessionMemory
from app.agent_core.memory import SessionMemory
from app.infrastructure.session_store import SessionStore
store = SessionStore()
......@@ -265,7 +265,7 @@ class MessageGate:
"""casual 分支:直接发 IM 回复,并记录 user + assistant 到 history。"""
if not decision.reply:
return
from app.service.memory import SessionMemory
from app.agent_core.memory import SessionMemory
from app.infrastructure.session_store import SessionStore
store = SessionStore()
merged_text = "\n".join(
......
......@@ -7,7 +7,7 @@ from typing import Any, Dict, List, Optional, TYPE_CHECKING
from app.infrastructure.session_store import SessionStore
if TYPE_CHECKING:
from app.service.active_session_service import ActiveSessionService
from app.agent_core.active_session_service import ActiveSessionService
logger = logging.getLogger(__name__)
......
......@@ -2,8 +2,8 @@ import logging
from fastapi import APIRouter, BackgroundTasks, Depends, HTTPException
from pydantic import BaseModel, Field
from typing import Optional, List
from app.service.agent_hub import AgentHub
from app.service.message_gate import MessageGate
from app.agent_core.agent_hub import AgentHub
from app.agent_core.message_gate import MessageGate
logger = logging.getLogger(__name__)
......
......@@ -40,10 +40,10 @@ from app.model.wecom_sync import ( # noqa: F401
WeComSyncCheckpoint,
)
from app.schema.common import error_response_payload, is_wrapped_payload, success_response_payload
from app.service.agent_hub import AgentHub
from app.service.active_session_service import ActiveSessionService
from app.service.console_im_service import ConsoleIMService
from app.service.im_service import IMService
from app.agent_core.agent_hub import AgentHub
from app.agent_core.active_session_service import ActiveSessionService
from app.agent_core.console_im_service import ConsoleIMService
from app.agent_core.im_service import IMService
agent_hub_instance = None
message_gate_instance = None
......@@ -101,7 +101,7 @@ async def lifespan(app: FastAPI):
)
# ── MessageGate 实例化 ──
from app.service.message_gate import MessageGate
from app.agent_core.message_gate import MessageGate
from app.hooks.post_reply import PostReplyHook
main_agent_key = next((k for k, v in agents.items() if v.is_steward), "main")
......
# Agent 服务层说明
> **本目录包含大量服务文件,但 Agent 相关(我们负责)的只有以下几个。其余服务属于管理后台/官网/群管理等模块,不需要我们修改。**
## 我们负责的文件
### 消息入口与门控
| 文件 | 类 | 职责 |
|------|----|------|
| `message_gate.py` | `MessageGate` | **消息门控层** — 激活识别(chat/pass) |
封装流程:
1. `evaluate()` 锁外检查 `_running_tasks`(有在途任务则走 busy 分支,不排队)
2. 获取 session 锁(`_get_lock` 按 session 串行化),等待非 text 消息的补充窗口(默认 6s)
3. `_classify_and_rewrite()` — 当前为直通桩(直接放行所有消息,跳过 LLM 分类)。MessageGate 激活识别功能暂时搁置,待后续重新启用。
4. 根据 intent 分支:
- `chat` → `_handle_chat()` 只追加用户消息到 conversation_history,不触发 AgentHub,不发 IM("已读不回")
- `pass` → `_handle_actionable()` 提取 query/file_url,调用 `AgentHub.process_message()`
5. 在途任务忙碌:`busy` → `_handle_busy()` 保存用户消息到 `intent_session`(隔离字段,不写 `conversation_history`),发固定告知回复(`BUSY_REPLY`),不排队
6. `_running_tasks[session_id] = asyncio.current_task()` 标记在途,`finally` 清理
| 文件 | 类 | 职责 |
|------|----|------|
| `session_buffer.py` | `SessionBuffer` | **pending_messages 缓冲区** — 封装消息的追加/读取/清除 |
封装流程:
- `append(message)` — 追加消息到 `pending_messages`
- `get_pending()` — 返回当前 pending 消息列表副本
- `clear_pending()` — 清空缓冲区
- `remove_by_msg_ids(ids)` — 按 msg_id 移除指定消息(ignore 场景)
- `has_text_message()` — 检查是否有 text/other 类型消息
- `_ensure_session_exists()` — KV miss 时先尝试 DB 冷恢复,避免 conversation_history 丢失
### 核心调度
| 文件 | 类 | 职责 |
|------|----|------|
| `agent_hub.py` | `AgentHub` | **中央调度器** — 唯一运行的 Agent 运行时 |
封装流程:
1. 接收 `process_message()` 调用(由 MessageGate pass 分支调用,或兜底直接调用)
2. `get_or_create_session()` 获取/创建会话
3. 消费 `intent_session` 积压消息(busy 分支写入的),拼入 `user_query` 前置,清空 KV 字段
4. `SessionMemory.get_messages()` 加载历史消息
5. `_build_main_prompt()` 组装 system prompt(DB prompt + 子Agent职责列表 + soul_guide 回复风格框架)
6. 创建 `ReActAgent`(AgentScope),注入 `InMemoryMemory` + 专属 `Toolkit`(`agent_toolkits[code]`),主 Agent 用 `self.model`,子 Agent 用 `self.sub_model` (temp=0.2)
7. `agent.reply(user_msg)` 执行 ReAct 循环(推理→工具调用→观察→再推理)
8. `_call_sub_agent()` 子 Agent 创建与执行(通过 `call_sub_agent` 工具触发,使用 `self.sub_model`)
- 自调用防护:拒绝调用 steward 自己的 code,引导调用发言人 Agent
- 子Agent ReAct 消息通过 `_save_tool_interactions()` 写入 SessionMemory,落 DB
- 子Agent 通过 `PostReplyHook` 直接发送自己的处理结果(用自身 bot_id),**不走发言人 Agent 转发**
- 口 Agent(code: -1)排除 `call_sub_agent` 工具,纯总结回复
9. 回复处理(`call_count` 机制 — 解决 LLM 在 tool_result 后总是继续输出的问题):
- `call_count >= 1`:主Agent 静默——`memory.remove_last()` 剔除主Agent 最终回复,不发送 IM。子Agent 已各自发送,主Agent 无需再说一次
- `call_count == 0`:主Agent 直接回复——正常写入 + 存 DB + PostReplyHook 发 IM
- 发言人 Agent(code -1):当主Agent 在已派发子Agent 后仍有**子Agent 未覆盖的剩余内容**时调用,由主Agent 在 ReAct 循环中自行决定是否触发
10. `save_to_db()` 持久化会话
### 会话管理
| 文件 | 类 | 职责 |
|------|----|------|
| `active_session_service.py` | `ActiveSessionService` | **活跃会话生命周期** |
封装流程:
- `get_or_create_session()` — 先查内存 KV(热路径)→ 再查 DB 冷恢复(`with db_factory() as db:` 短 session)→ 都没有则新建
- `save_to_db()` — 内存 KV → DB 持久化(`with db_factory() as db:` 短 session,修 Broken pipe),写 `conversation_history` JSON
- 构造函数持有 `db_factory: Callable[[], Session]`(非长生命周期 db 实例)
- 内存 KV 由 `SessionStore`(`infrastructure/session_store.py`)提供,TTL 30 分钟
### 消息历史
| 文件 | 类 | 职责 |
|------|----|------|
| `memory.py` | `SessionMemory` | **会话消息存取与压缩** |
封装流程:
- `add(role, content, agent_code)` — 追加一条消息到 `conversation_history`
- `get_messages(max_rounds)` — 获取历史,超限时自动 summarize_truncation(早期消息压缩为摘要)
- `mark(label)` — 插入检查点标记
- 底层读写 `SessionStore` 中的 `conversation_history` 数组
### IM 发送
| 文件 | 类 | 职责 |
|------|----|------|
| `im_service.py` | `IMService` | **生产环境 IM 发送** — 调用自建 IM 服务 API |
| `console_im_service.py` | `ConsoleIMService` | **测试/调试 IM** — 打印到控制台,不实际发送 |
两者实现相同接口 `send_message(bot_id, content, contact_id, at_list)`,通过 `IMSender` Protocol 解耦。
## 不属于我们的文件(不要修改)
| 文件 | 所属模块 |
|------|---------|
| `agent_service.py` | Agent 管理后台(CRUD 配置) |
| `agent_group_helper_service.py` | Agent 群管理(渠道活码、一客一群) |
| `analytics_service.py` | 数据分析 |
| `file_service.py` | 文件上传与文本提取(仅 `routing.py` 端点使用) |
| `methodology_service.py` | 方法论展示 |
| `official_site_*.py` | 官网各页面 |
| `position_tag_service.py` | 岗位标签管理 |
| `qrcode_channel_service.py` | 渠道活码 |
| `routing_service.py` | 路由配置 |
| `skill_service.py` | 技能管理后台 |
| `wecom_*.py` | 企微同步/群编排 |
## 关联目录
| 目录 | Agent 相关文件 | 说明 |
|------|---------------|------|
| `app/api/v1/endpoints/agent_hub.py` | 是 | API 入口,解析 `ChatRequest` → 追加到 SessionBuffer → 后台调 MessageGate |
| `app/hooks/` | 是 | `PostReplyHook`(回复后 IM 发送)、`Hook` 基类 |
| `app/infrastructure/session_store.py` | 是 | `SessionStore` 内存 KV,`ActiveSessionService` 和 `SessionBuffer` 的底层存储 |
| `app/infrastructure/file_parser.py` | 是 | `FileParser` + `OSSClient`,`FileService` 的底层依赖 |
| `app/config/loader.py` | 是 | `ConfigLoader` 加载 models/settings JSON 配置,Agent 从 DB `ai_agents` 表加载 |
| `app/model/session.py` | 是 | `Session`、`ConversationHistory` ORM 模型 |
| `ai_agents` 表 | 是 | Agent 配置(name, code, description, is_steward),通过 `ai_agent_skills` 关联 skills |
| `config/models.json` | 是 | 模型配置(main/thinking_summary/message_gate/meeting_minutes) |
| `skills/` | 是 | Skill 目录,每个子目录有 `SKILL.md`,由 `Toolkit.register_agent_skill()` 加载 |
| `soul/` | 是 | 回复风格(agent.md)和 thinking 摘要提示词(thinking-summarize.md),启动时加载注入 prompt |
## Agent 调用完整流程
```
用户消息 (企微/微信)
│
▼
IM 网关 (5s 聚合窗口)
│
▼
POST /api/v1/chat/completions ← app/api/v1/endpoints/agent_hub.py
│ 解析 ChatRequest: group, agents, messages
│ 提取 query, user_id, bot_id_mapping
│ 追加消息到 SessionBuffer
│ 后端自动补全发言人 Agent code (-1) 到 allowed_agent_codes
│
▼
BackgroundTasks.add_task() ← 异步后台处理,HTTP 立即返回 200
│
▼
MessageGate.evaluate() ← app/service/message_gate.py
│
├── 检查 _running_tasks(锁外,有在途任务则立即返回)
│ └── busy → _handle_busy()
│ 保存用户消息到 intent_session(隔离字段,不写 history)
│ 不调 save_to_db()
│ 发固定告知回复(BUSY_REPLY)→ IM 发送
│ 不排队,不触发 AgentHub
│
├── 获取 session 锁(按 session_id 串行化)
├── 等待非 text 消息补充窗口(默认 6s)
├── _classify_and_rewrite() → 当前为直通桩(直接返回 pass),跳过 LLM 分类
│
├── intent=chat → _handle_chat()
│ 追加用户消息到 conversation_history → save_to_db()
│ 不触发 AgentHub,不发 IM("已读不回")
│
└── intent=pass → _handle_actionable()
│
▼
AgentHub.process_message() ← app/service/agent_hub.py
│
├── ActiveSessionService.get_or_create_session()
│ 内存 KV → DB 冷恢复 → 新建
│
├── 消费 intent_session 积压消息(busy 分支写入的)
│ 读取 KV.intent_session,拼入 user_query 前置
│ 消费后清空,防止重复消费
│
├── SessionMemory.get_messages()
│ 加载 conversation_history,超限自动压缩
│
├── _build_main_prompt()
│ DB prompt + 子Agent职责列表 + soul/agent.md 回复风格框架
│
├── 创建 ReActAgent (AgentScope)
│ 主 Agent 用 self.model,子 Agent 用 self.sub_model (temp=0.2)
│ toolkit = basic 工具 + agent 专属 skills
│ 口 Agent (-1): 排除 call_sub_agent 工具,纯总结回复
│
├── agent.reply(user_msg) ← ReAct 循环
│ │
│ ├── [推理] LLM 生成 thinking + tool_use
│ │ → post_reasoning hook: _summarize_thinking()
│ │ 用 thinking_summary_model (deepseek-v4-flash)
│ │ 摘要化后发送到 IM,不泄露内部推理细节
│ │ (call_sub_agent tool_result 后的 reasoning 跳过,避免与最终回复重复)
│ │
│ ├── [调度] call_sub_agent → 子Agent ReAct 执行
│ │ │
│ │ ├── 自调用防护:拒绝 steward 自己的 code
│ │ ├── 创建子 ReActAgent + 执行
│ │ ├── 子Agent 通过 PostReplyHook 直接发送结果(用自身 bot_id)
│ │ ├── 子Agent ReAct 消息写入 SessionMemory(通过 _current_route_ctx)
│ │ └── 调用顺序由主Agent ReAct 推理决定,非固定链式
│ │
│ ├── [观察] 工具返回结果,注入 memory
│ │
│ └── 重复,直到 LLM 输出最终回复(无 tool_use)
│
├── 回复判断(call_count — 抑制 LLM 在 tool_result 后继续输出的问题)
│ ├── call_count >= 1 → 主Agent 静默
│ │ `memory.remove_last()` 剔除最终回复,不发送 IM
│ │ 子Agent 已各自直接发送,发言人口按需由主Agent 自行触发
│ └── call_count == 0 → 主Agent 直接回复
│ SessionMemory.add("assistant", response)
│ → save_to_db()
│ → PostReplyHook.execute() → IM 发送
│
└── ActiveSessionService.save_to_db()
```
### MessageGate 兜底逻辑
当 MessageGate 评估异常时,endpoint 的 `_process_message_async_via_gate` 会 catch 异常并兜底直接调用 `AgentHub.process_message()`,确保消息不会丢失。
| 模型架构
> **暂时搁置:** `_classify_and_rewrite()` 当前为直通桩,不做 LLM 分类。`_handle_casual()` 和 `_handle_incomplete()` 方法保留在代码中但未被调用,待后续重新启用消息过滤功能。
### 模型架构
| 实例 | 模型 | temperature | 用途 |
|------|------|-------------|------|
| `self.model` | qwen3.6-plus | 默认 | 主 Agent ReAct 推理 |
| `self.sub_model` | qwen3.6-plus | 0.2 | 子 Agent ReAct 推理 |
| `self.thinking_summary_model` | deepseek-v4-flash | 默认 | thinking 摘要化(快、便宜) |
| MessageGate 模型 | deepseek-v4-flash | 默认 | 暂时搁置(当前直通不放行分类,_classify_and_rewrite 为桩) |
### Prompt 装配顺序
```
_build_main_prompt: agent.prompt (DB角色定义+调度规则) → 子Agent职责列表 → soul_guide (回复风格框架)
_build_sub_agent_prompt: agent.prompt → soul_guide
```
调度规则(原 DISPATCH_GUIDE)已集成到 DB `ai_agents.prompt` 中,不再作为独立常量拼接。
......@@ -7,9 +7,9 @@ from app.main import app as fastapi_app
# ── AgentHub 测试实例 ────────────────────────────────────────────
from app.config.settings import AgentConfig
from app.service.active_session_service import ActiveSessionService
from app.service.agent_hub import AgentHub, AgentHubError, _route_context_var, _background_tasks
from app.service.memory import SessionMemory
from app.agent_core.active_session_service import ActiveSessionService
from app.agent_core.agent_hub import AgentHub, AgentHubError, _route_context_var, _background_tasks
from app.agent_core.memory import SessionMemory
async def _drain_background_tasks():
......@@ -98,7 +98,7 @@ def _override_get_agent_hub():
def _override_get_message_gate():
from unittest.mock import MagicMock, AsyncMock
from app.service.message_gate import MessageGate, GateDecision
from app.agent_core.message_gate import MessageGate, GateDecision
mock_gate = MagicMock(spec=MessageGate)
mock_gate.evaluate = AsyncMock(return_value=None)
# 让 evaluate 同步调用 agent_hub.process_message(模拟 actionable 分支)
......@@ -897,7 +897,7 @@ async def test_summarize_thinking_long_text_calls_model():
@pytest.mark.asyncio
async def test_hook_summarizes_thinking_before_send():
"""hook 应在发送 IM 前对长 thinking 调用摘要化。"""
from app.service.agent_hub import _im_post_reasoning_hook
from app.agent_core.agent_hub import _im_post_reasoning_hook
mock_im = AsyncMock()
mock_im.send_message.return_value = {"code": 200}
......@@ -930,7 +930,7 @@ async def test_hook_summarizes_thinking_before_send():
@pytest.mark.asyncio
async def test_hook_summarizes_even_short_thinking():
"""即使是短 thinking,也应走摘要化(不直接暴露内部推理)。"""
from app.service.agent_hub import _im_post_reasoning_hook
from app.agent_core.agent_hub import _im_post_reasoning_hook
mock_im = AsyncMock()
mock_im.send_message.return_value = {"code": 200}
......@@ -960,7 +960,7 @@ async def test_hook_summarizes_even_short_thinking():
@pytest.mark.asyncio
async def test_hook_skips_after_call_sub_agent_result():
"""call_sub_agent 工具结果后的 post_reasoning 应跳过 IM 发送。"""
from app.service.agent_hub import _im_post_reasoning_hook
from app.agent_core.agent_hub import _im_post_reasoning_hook
mock_im = AsyncMock()
mock_summarize = AsyncMock()
......
......@@ -20,7 +20,7 @@ def _make_test_agents():
class TestSkillRegistration:
def test_agent_hub_registers_skills_on_init(self):
"""AgentHub.__init__ should register skills to Toolkit via register_agent_skill."""
from app.service.agent_hub import AgentHub
from app.agent_core.agent_hub import AgentHub
mock_loader = MagicMock()
mock_model_config = MagicMock()
......@@ -42,7 +42,7 @@ class TestSkillRegistration:
def test_agent_hub_skills_loaded_from_toolkit(self):
"""Skills dict should come from load_skills_from_toolkit, not load_skills."""
from app.service.agent_hub import AgentHub
from app.agent_core.agent_hub import AgentHub
expected_skills = {
"buddy-sings": {
......
"""SessionMemory unit tests — message add/get/truncation/mark."""
import pytest
from datetime import datetime, timezone
from app.service.memory import SessionMemory
from app.agent_core.memory import SessionMemory
from app.infrastructure.session_store import SessionStore, clear_default_store_for_tests
......@@ -50,7 +50,7 @@ class TestSessionMemory:
# Insert 50 messages (total 52 with the 2 seeded) via memory.add()
memory = SessionMemory(active_session, store, max_rounds=5)
for i in range(50):
memory.add("user", f"msg {i}", agent_code="main")
memory.add("user", f"msg {i}")
msgs = memory.get_messages()
# Should contain summary + at most 10 recent messages (5 rounds × 2)
assert len(msgs) <= 11 # 1 summary + 10 msgs
......
"""MessageGate 激活识别测试。"""
import pytest
from unittest.mock import MagicMock, AsyncMock
from app.service.message_gate import MessageGate, GateDecision
from app.agent_core.message_gate import MessageGate, GateDecision
def test_message_gate_can_be_constructed():
......@@ -124,7 +124,7 @@ async def test_handle_actionable_calls_agent_hub():
def test_extract_query_and_file_url_text_only():
"""仅包含文本消息时,提取 query 且 file_url 为 None。"""
from app.service.message_gate import MessageGate
from app.agent_core.message_gate import MessageGate
pending = [{"msg_type": "text", "msg_content": "帮我整理纪要"}]
query, file_url = MessageGate._extract_query_and_file_url(pending)
assert query == "帮我整理纪要"
......@@ -133,7 +133,7 @@ def test_extract_query_and_file_url_text_only():
def test_extract_query_and_file_url_with_file():
"""混合文本+文件消息时,提取 query 和 file_url。"""
from app.service.message_gate import MessageGate
from app.agent_core.message_gate import MessageGate
pending = [
{"msg_type": "text", "msg_content": "分析这份报表"},
{"msg_type": "file", "msg_content": "https://oss.example.com/report.xlsx"},
......@@ -145,7 +145,7 @@ def test_extract_query_and_file_url_with_file():
def test_extract_query_and_file_url_append_url():
"""文本中已含 URL 时,不重复追加。"""
from app.service.message_gate import MessageGate
from app.agent_core.message_gate import MessageGate
pending = [
{"msg_type": "text", "msg_content": "看下这个 https://example.com/doc"},
]
......@@ -157,7 +157,7 @@ def test_extract_query_and_file_url_append_url():
def test_extract_query_and_file_url_empty():
"""空 pending 返回空 query。"""
from app.service.message_gate import MessageGate
from app.agent_core.message_gate import MessageGate
query, file_url = MessageGate._extract_query_and_file_url([])
assert query == ""
assert file_url is None
......
......@@ -5,8 +5,8 @@ import shutil
from pathlib import Path
from unittest.mock import MagicMock, AsyncMock
from app.service.active_session_service import ActiveSessionService
from app.service.agent_hub import AgentHub
from app.agent_core.active_session_service import ActiveSessionService
from app.agent_core.agent_hub import AgentHub
from agentscope.message._message_block import TextBlock
......
"""SessionBuffer 单元测试 - 测试 pending_messages 的存取。"""
import pytest
from app.infrastructure.session_store import SessionStore
from app.service.session_buffer import SessionBuffer
from app.agent_core.session_buffer import SessionBuffer
@pytest.fixture
......
......@@ -6,7 +6,7 @@ from app.infrastructure.session_store import (
SessionStore, SESSION_TTL_SECONDS, active_session_key,
)
from app.infrastructure.kv_store import InMemoryKeyValueStore
from app.service.active_session_service import ActiveSessionService, ActiveSessionInfo
from app.agent_core.active_session_service import ActiveSessionService, ActiveSessionInfo
class TestSessionStoreTTLRefresh:
......@@ -152,7 +152,7 @@ class TestDatabasePersistence:
def test_restore_preserves_conversation_history(self, svc, db):
"""恢复后 conversation_history 完整保留"""
from app.service.memory import SessionMemory
from app.agent_core.memory import SessionMemory
svc.get_or_create_session("db_hist", room_id="room_001")
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!