Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
ai
/
ai-workflow
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit f23adaf9
authored
Jun 29, 2026
by
sunqi02
Committed by
胡悦
Jul 01, 2026
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
将后端服务与agent服务的代码进行物理隔离
1 parent
9589ef25
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
38 additions
and
38 deletions
workspace/agent-admin/backend/AGENTS.md
workspace/agent-admin/backend/app/agent_core/__init__.py
workspace/agent-admin/backend/app/service/active_session_service.py → workspace/agent-admin/backend/app/agent_core/active_session_service.py
workspace/agent-admin/backend/app/service/agent_hub.py → workspace/agent-admin/backend/app/agent_core/agent_hub.py
workspace/agent-admin/backend/app/service/console_im_service.py → workspace/agent-admin/backend/app/agent_core/console_im_service.py
workspace/agent-admin/backend/app/service/im_service.py → workspace/agent-admin/backend/app/agent_core/im_service.py
workspace/agent-admin/backend/app/service/memory.py → workspace/agent-admin/backend/app/agent_core/memory.py
workspace/agent-admin/backend/app/service/message_gate.py → workspace/agent-admin/backend/app/agent_core/message_gate.py
workspace/agent-admin/backend/app/service/session_buffer.py → workspace/agent-admin/backend/app/agent_core/session_buffer.py
workspace/agent-admin/backend/app/api/v1/endpoints/agent_hub.py
workspace/agent-admin/backend/app/main.py
workspace/agent-admin/backend/app/service/CLAUDE.md
workspace/agent-admin/backend/tests/test_agent_hub.py
workspace/agent-admin/backend/tests/test_main.py
workspace/agent-admin/backend/tests/test_memory.py
workspace/agent-admin/backend/tests/test_message_gate.py
workspace/agent-admin/backend/tests/test_read_file_tool.py
workspace/agent-admin/backend/tests/test_session_buffer.py
workspace/agent-admin/backend/tests/test_session_persistence.py
workspace/agent-admin/backend/AGENTS.md
View file @
f23adaf
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
1.
分层规范:
1.
分层规范:
-
接口层:app/api/,只做参数校验和请求转发
-
接口层:app/api/,只做参数校验和请求转发
-
服务层:app/service/,业务逻辑
-
服务层:app/service/,业务逻辑
(Agent 核心运行时在 app/agent_core/,与 app/service/ 物理隔离)
-
基础设施层:app/infrastructure/,基础设施(DB、Redis、HTTP、消息队列)
-
基础设施层:app/infrastructure/,基础设施(DB、Redis、HTTP、消息队列)
-
配置层:app/config/,配置相关
-
配置层:app/config/,配置相关
-
数据层:app/model/,数据库ORM模型
-
数据层:app/model/,数据库ORM模型
...
...
workspace/agent-admin/backend/app/agent_core/__init__.py
0 → 100644
View file @
f23adaf
File mode changed
workspace/agent-admin/backend/app/
servic
e/active_session_service.py
→
workspace/agent-admin/backend/app/
agent_cor
e/active_session_service.py
View file @
f23adaf
File moved
workspace/agent-admin/backend/app/
servic
e/agent_hub.py
→
workspace/agent-admin/backend/app/
agent_cor
e/agent_hub.py
View file @
f23adaf
...
@@ -8,10 +8,10 @@ from pathlib import Path
...
@@ -8,10 +8,10 @@ from pathlib import Path
from
typing
import
Dict
,
List
,
Optional
,
Any
from
typing
import
Dict
,
List
,
Optional
,
Any
from
app.config.loader
import
ConfigLoader
from
app.config.loader
import
ConfigLoader
from
app.config.settings
import
AgentConfig
from
app.config.settings
import
AgentConfig
from
app.
servic
e.active_session_service
import
ActiveSessionService
from
app.
agent_cor
e.active_session_service
import
ActiveSessionService
from
agentscope.tool
import
Toolkit
from
agentscope.tool
import
Toolkit
from
app.hooks.post_reply
import
PostReplyHook
from
app.hooks.post_reply
import
PostReplyHook
from
app.
servic
e.memory
import
SessionMemory
from
app.
agent_cor
e.memory
import
SessionMemory
from
agentscope.model
import
OpenAIChatModel
from
agentscope.model
import
OpenAIChatModel
from
agentscope.formatter
import
OpenAIChatFormatter
as
_OpenAIChatFormatter
from
agentscope.formatter
import
OpenAIChatFormatter
as
_OpenAIChatFormatter
from
agentscope.message
import
Msg
from
agentscope.message
import
Msg
...
@@ -181,7 +181,7 @@ async def _bg_finalize_sub_agent(
...
@@ -181,7 +181,7 @@ async def _bg_finalize_sub_agent(
channel
=
"sub_agent"
,
channel
=
"sub_agent"
,
)
)
sub_memory_msgs
=
await
sub_agent
.
memory
.
get_memory
()
sub_memory_msgs
=
await
sub_agent
.
memory
.
get_memory
()
from
app.
servic
e.memory
import
SessionMemory
from
app.
agent_cor
e.memory
import
SessionMemory
sub_session_memory
=
SessionMemory
(
sub_session_memory
=
SessionMemory
(
session_id
=
sub_session_id
,
session_id
=
sub_session_id
,
store
=
hub
.
session_service
.
store
,
store
=
hub
.
session_service
.
store
,
...
...
workspace/agent-admin/backend/app/
servic
e/console_im_service.py
→
workspace/agent-admin/backend/app/
agent_cor
e/console_im_service.py
View file @
f23adaf
File moved
workspace/agent-admin/backend/app/
servic
e/im_service.py
→
workspace/agent-admin/backend/app/
agent_cor
e/im_service.py
View file @
f23adaf
File moved
workspace/agent-admin/backend/app/
servic
e/memory.py
→
workspace/agent-admin/backend/app/
agent_cor
e/memory.py
View file @
f23adaf
File moved
workspace/agent-admin/backend/app/
servic
e/message_gate.py
→
workspace/agent-admin/backend/app/
agent_cor
e/message_gate.py
View file @
f23adaf
...
@@ -12,7 +12,7 @@ from typing import Any, Dict, List, Optional
...
@@ -12,7 +12,7 @@ from typing import Any, Dict, List, Optional
from
app.config.loader
import
ConfigLoader
from
app.config.loader
import
ConfigLoader
from
app.hooks.post_reply
import
PostReplyHook
from
app.hooks.post_reply
import
PostReplyHook
from
app.
servic
e.active_session_service
import
ActiveSessionService
from
app.
agent_cor
e.active_session_service
import
ActiveSessionService
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
@@ -72,7 +72,7 @@ class MessageGate:
...
@@ -72,7 +72,7 @@ class MessageGate:
async
def
append_messages
(
self
,
session_id
:
str
,
messages
:
List
[
Dict
[
str
,
Any
]])
->
None
:
async
def
append_messages
(
self
,
session_id
:
str
,
messages
:
List
[
Dict
[
str
,
Any
]])
->
None
:
"""追加消息到 session buffer,使用 per-session 锁保证并发安全。"""
"""追加消息到 session buffer,使用 per-session 锁保证并发安全。"""
from
app.
servic
e.session_buffer
import
SessionBuffer
from
app.
agent_cor
e.session_buffer
import
SessionBuffer
from
app.infrastructure.session_store
import
SessionStore
from
app.infrastructure.session_store
import
SessionStore
async
with
self
.
_get_lock
(
session_id
):
async
with
self
.
_get_lock
(
session_id
):
...
@@ -98,7 +98,7 @@ class MessageGate:
...
@@ -98,7 +98,7 @@ class MessageGate:
bot_id_mapping: 由 endpoint 注入的 agent_key → bot_id 映射
bot_id_mapping: 由 endpoint 注入的 agent_key → bot_id 映射
wait_seconds: 等待窗口(默认 6 秒,测试时可缩短)
wait_seconds: 等待窗口(默认 6 秒,测试时可缩短)
"""
"""
from
app.
servic
e.session_buffer
import
SessionBuffer
from
app.
agent_cor
e.session_buffer
import
SessionBuffer
from
app.infrastructure.session_store
import
SessionStore
from
app.infrastructure.session_store
import
SessionStore
store
=
SessionStore
()
store
=
SessionStore
()
...
@@ -201,7 +201,7 @@ class MessageGate:
...
@@ -201,7 +201,7 @@ class MessageGate:
pending
:
List
[
Dict
[
str
,
Any
]],
pending
:
List
[
Dict
[
str
,
Any
]],
)
->
None
:
)
->
None
:
"""chat 分支:追加用户消息到 conversation_history,不触发 AgentHub,不发 IM。"""
"""chat 分支:追加用户消息到 conversation_history,不触发 AgentHub,不发 IM。"""
from
app.
servic
e.memory
import
SessionMemory
from
app.
agent_cor
e.memory
import
SessionMemory
from
app.infrastructure.session_store
import
SessionStore
from
app.infrastructure.session_store
import
SessionStore
store
=
SessionStore
()
store
=
SessionStore
()
...
@@ -265,7 +265,7 @@ class MessageGate:
...
@@ -265,7 +265,7 @@ class MessageGate:
"""casual 分支:直接发 IM 回复,并记录 user + assistant 到 history。"""
"""casual 分支:直接发 IM 回复,并记录 user + assistant 到 history。"""
if
not
decision
.
reply
:
if
not
decision
.
reply
:
return
return
from
app.
servic
e.memory
import
SessionMemory
from
app.
agent_cor
e.memory
import
SessionMemory
from
app.infrastructure.session_store
import
SessionStore
from
app.infrastructure.session_store
import
SessionStore
store
=
SessionStore
()
store
=
SessionStore
()
merged_text
=
"
\n
"
.
join
(
merged_text
=
"
\n
"
.
join
(
...
...
workspace/agent-admin/backend/app/
servic
e/session_buffer.py
→
workspace/agent-admin/backend/app/
agent_cor
e/session_buffer.py
View file @
f23adaf
...
@@ -7,7 +7,7 @@ from typing import Any, Dict, List, Optional, TYPE_CHECKING
...
@@ -7,7 +7,7 @@ from typing import Any, Dict, List, Optional, TYPE_CHECKING
from
app.infrastructure.session_store
import
SessionStore
from
app.infrastructure.session_store
import
SessionStore
if
TYPE_CHECKING
:
if
TYPE_CHECKING
:
from
app.
servic
e.active_session_service
import
ActiveSessionService
from
app.
agent_cor
e.active_session_service
import
ActiveSessionService
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
...
workspace/agent-admin/backend/app/api/v1/endpoints/agent_hub.py
View file @
f23adaf
...
@@ -2,8 +2,8 @@ import logging
...
@@ -2,8 +2,8 @@ import logging
from
fastapi
import
APIRouter
,
BackgroundTasks
,
Depends
,
HTTPException
from
fastapi
import
APIRouter
,
BackgroundTasks
,
Depends
,
HTTPException
from
pydantic
import
BaseModel
,
Field
from
pydantic
import
BaseModel
,
Field
from
typing
import
Optional
,
List
from
typing
import
Optional
,
List
from
app.
servic
e.agent_hub
import
AgentHub
from
app.
agent_cor
e.agent_hub
import
AgentHub
from
app.
servic
e.message_gate
import
MessageGate
from
app.
agent_cor
e.message_gate
import
MessageGate
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
...
workspace/agent-admin/backend/app/main.py
View file @
f23adaf
...
@@ -40,10 +40,10 @@ from app.model.wecom_sync import ( # noqa: F401
...
@@ -40,10 +40,10 @@ from app.model.wecom_sync import ( # noqa: F401
WeComSyncCheckpoint
,
WeComSyncCheckpoint
,
)
)
from
app.schema.common
import
error_response_payload
,
is_wrapped_payload
,
success_response_payload
from
app.schema.common
import
error_response_payload
,
is_wrapped_payload
,
success_response_payload
from
app.
servic
e.agent_hub
import
AgentHub
from
app.
agent_cor
e.agent_hub
import
AgentHub
from
app.
servic
e.active_session_service
import
ActiveSessionService
from
app.
agent_cor
e.active_session_service
import
ActiveSessionService
from
app.
servic
e.console_im_service
import
ConsoleIMService
from
app.
agent_cor
e.console_im_service
import
ConsoleIMService
from
app.
servic
e.im_service
import
IMService
from
app.
agent_cor
e.im_service
import
IMService
agent_hub_instance
=
None
agent_hub_instance
=
None
message_gate_instance
=
None
message_gate_instance
=
None
...
@@ -101,7 +101,7 @@ async def lifespan(app: FastAPI):
...
@@ -101,7 +101,7 @@ async def lifespan(app: FastAPI):
)
)
# ── MessageGate 实例化 ──
# ── MessageGate 实例化 ──
from
app.
servic
e.message_gate
import
MessageGate
from
app.
agent_cor
e.message_gate
import
MessageGate
from
app.hooks.post_reply
import
PostReplyHook
from
app.hooks.post_reply
import
PostReplyHook
main_agent_key
=
next
((
k
for
k
,
v
in
agents
.
items
()
if
v
.
is_steward
),
"main"
)
main_agent_key
=
next
((
k
for
k
,
v
in
agents
.
items
()
if
v
.
is_steward
),
"main"
)
...
...
workspace/agent-admin/backend/app/service/CLAUDE.md
deleted
100644 → 0
View file @
9589ef2
This diff is collapsed.
Click to expand it.
workspace/agent-admin/backend/tests/test_agent_hub.py
View file @
f23adaf
...
@@ -7,9 +7,9 @@ from app.main import app as fastapi_app
...
@@ -7,9 +7,9 @@ from app.main import app as fastapi_app
# ── AgentHub 测试实例 ────────────────────────────────────────────
# ── AgentHub 测试实例 ────────────────────────────────────────────
from
app.config.settings
import
AgentConfig
from
app.config.settings
import
AgentConfig
from
app.
servic
e.active_session_service
import
ActiveSessionService
from
app.
agent_cor
e.active_session_service
import
ActiveSessionService
from
app.
servic
e.agent_hub
import
AgentHub
,
AgentHubError
,
_route_context_var
,
_background_tasks
from
app.
agent_cor
e.agent_hub
import
AgentHub
,
AgentHubError
,
_route_context_var
,
_background_tasks
from
app.
servic
e.memory
import
SessionMemory
from
app.
agent_cor
e.memory
import
SessionMemory
async
def
_drain_background_tasks
():
async
def
_drain_background_tasks
():
...
@@ -98,7 +98,7 @@ def _override_get_agent_hub():
...
@@ -98,7 +98,7 @@ def _override_get_agent_hub():
def
_override_get_message_gate
():
def
_override_get_message_gate
():
from
unittest.mock
import
MagicMock
,
AsyncMock
from
unittest.mock
import
MagicMock
,
AsyncMock
from
app.
servic
e.message_gate
import
MessageGate
,
GateDecision
from
app.
agent_cor
e.message_gate
import
MessageGate
,
GateDecision
mock_gate
=
MagicMock
(
spec
=
MessageGate
)
mock_gate
=
MagicMock
(
spec
=
MessageGate
)
mock_gate
.
evaluate
=
AsyncMock
(
return_value
=
None
)
mock_gate
.
evaluate
=
AsyncMock
(
return_value
=
None
)
# 让 evaluate 同步调用 agent_hub.process_message(模拟 actionable 分支)
# 让 evaluate 同步调用 agent_hub.process_message(模拟 actionable 分支)
...
@@ -897,7 +897,7 @@ async def test_summarize_thinking_long_text_calls_model():
...
@@ -897,7 +897,7 @@ async def test_summarize_thinking_long_text_calls_model():
@pytest.mark.asyncio
@pytest.mark.asyncio
async
def
test_hook_summarizes_thinking_before_send
():
async
def
test_hook_summarizes_thinking_before_send
():
"""hook 应在发送 IM 前对长 thinking 调用摘要化。"""
"""hook 应在发送 IM 前对长 thinking 调用摘要化。"""
from
app.
servic
e.agent_hub
import
_im_post_reasoning_hook
from
app.
agent_cor
e.agent_hub
import
_im_post_reasoning_hook
mock_im
=
AsyncMock
()
mock_im
=
AsyncMock
()
mock_im
.
send_message
.
return_value
=
{
"code"
:
200
}
mock_im
.
send_message
.
return_value
=
{
"code"
:
200
}
...
@@ -930,7 +930,7 @@ async def test_hook_summarizes_thinking_before_send():
...
@@ -930,7 +930,7 @@ async def test_hook_summarizes_thinking_before_send():
@pytest.mark.asyncio
@pytest.mark.asyncio
async
def
test_hook_summarizes_even_short_thinking
():
async
def
test_hook_summarizes_even_short_thinking
():
"""即使是短 thinking,也应走摘要化(不直接暴露内部推理)。"""
"""即使是短 thinking,也应走摘要化(不直接暴露内部推理)。"""
from
app.
servic
e.agent_hub
import
_im_post_reasoning_hook
from
app.
agent_cor
e.agent_hub
import
_im_post_reasoning_hook
mock_im
=
AsyncMock
()
mock_im
=
AsyncMock
()
mock_im
.
send_message
.
return_value
=
{
"code"
:
200
}
mock_im
.
send_message
.
return_value
=
{
"code"
:
200
}
...
@@ -960,7 +960,7 @@ async def test_hook_summarizes_even_short_thinking():
...
@@ -960,7 +960,7 @@ async def test_hook_summarizes_even_short_thinking():
@pytest.mark.asyncio
@pytest.mark.asyncio
async
def
test_hook_skips_after_call_sub_agent_result
():
async
def
test_hook_skips_after_call_sub_agent_result
():
"""call_sub_agent 工具结果后的 post_reasoning 应跳过 IM 发送。"""
"""call_sub_agent 工具结果后的 post_reasoning 应跳过 IM 发送。"""
from
app.
servic
e.agent_hub
import
_im_post_reasoning_hook
from
app.
agent_cor
e.agent_hub
import
_im_post_reasoning_hook
mock_im
=
AsyncMock
()
mock_im
=
AsyncMock
()
mock_summarize
=
AsyncMock
()
mock_summarize
=
AsyncMock
()
...
...
workspace/agent-admin/backend/tests/test_main.py
View file @
f23adaf
...
@@ -20,7 +20,7 @@ def _make_test_agents():
...
@@ -20,7 +20,7 @@ def _make_test_agents():
class
TestSkillRegistration
:
class
TestSkillRegistration
:
def
test_agent_hub_registers_skills_on_init
(
self
):
def
test_agent_hub_registers_skills_on_init
(
self
):
"""AgentHub.__init__ should register skills to Toolkit via register_agent_skill."""
"""AgentHub.__init__ should register skills to Toolkit via register_agent_skill."""
from
app.
servic
e.agent_hub
import
AgentHub
from
app.
agent_cor
e.agent_hub
import
AgentHub
mock_loader
=
MagicMock
()
mock_loader
=
MagicMock
()
mock_model_config
=
MagicMock
()
mock_model_config
=
MagicMock
()
...
@@ -42,7 +42,7 @@ class TestSkillRegistration:
...
@@ -42,7 +42,7 @@ class TestSkillRegistration:
def
test_agent_hub_skills_loaded_from_toolkit
(
self
):
def
test_agent_hub_skills_loaded_from_toolkit
(
self
):
"""Skills dict should come from load_skills_from_toolkit, not load_skills."""
"""Skills dict should come from load_skills_from_toolkit, not load_skills."""
from
app.
servic
e.agent_hub
import
AgentHub
from
app.
agent_cor
e.agent_hub
import
AgentHub
expected_skills
=
{
expected_skills
=
{
"buddy-sings"
:
{
"buddy-sings"
:
{
...
...
workspace/agent-admin/backend/tests/test_memory.py
View file @
f23adaf
"""SessionMemory unit tests — message add/get/truncation/mark."""
"""SessionMemory unit tests — message add/get/truncation/mark."""
import
pytest
import
pytest
from
datetime
import
datetime
,
timezone
from
datetime
import
datetime
,
timezone
from
app.
servic
e.memory
import
SessionMemory
from
app.
agent_cor
e.memory
import
SessionMemory
from
app.infrastructure.session_store
import
SessionStore
,
clear_default_store_for_tests
from
app.infrastructure.session_store
import
SessionStore
,
clear_default_store_for_tests
...
@@ -50,7 +50,7 @@ class TestSessionMemory:
...
@@ -50,7 +50,7 @@ class TestSessionMemory:
# Insert 50 messages (total 52 with the 2 seeded) via memory.add()
# Insert 50 messages (total 52 with the 2 seeded) via memory.add()
memory
=
SessionMemory
(
active_session
,
store
,
max_rounds
=
5
)
memory
=
SessionMemory
(
active_session
,
store
,
max_rounds
=
5
)
for
i
in
range
(
50
):
for
i
in
range
(
50
):
memory
.
add
(
"user"
,
f
"msg {i}"
,
agent_code
=
"main"
)
memory
.
add
(
"user"
,
f
"msg {i}"
)
msgs
=
memory
.
get_messages
()
msgs
=
memory
.
get_messages
()
# Should contain summary + at most 10 recent messages (5 rounds × 2)
# Should contain summary + at most 10 recent messages (5 rounds × 2)
assert
len
(
msgs
)
<=
11
# 1 summary + 10 msgs
assert
len
(
msgs
)
<=
11
# 1 summary + 10 msgs
...
...
workspace/agent-admin/backend/tests/test_message_gate.py
View file @
f23adaf
"""MessageGate 激活识别测试。"""
"""MessageGate 激活识别测试。"""
import
pytest
import
pytest
from
unittest.mock
import
MagicMock
,
AsyncMock
from
unittest.mock
import
MagicMock
,
AsyncMock
from
app.
servic
e.message_gate
import
MessageGate
,
GateDecision
from
app.
agent_cor
e.message_gate
import
MessageGate
,
GateDecision
def
test_message_gate_can_be_constructed
():
def
test_message_gate_can_be_constructed
():
...
@@ -124,7 +124,7 @@ async def test_handle_actionable_calls_agent_hub():
...
@@ -124,7 +124,7 @@ async def test_handle_actionable_calls_agent_hub():
def
test_extract_query_and_file_url_text_only
():
def
test_extract_query_and_file_url_text_only
():
"""仅包含文本消息时,提取 query 且 file_url 为 None。"""
"""仅包含文本消息时,提取 query 且 file_url 为 None。"""
from
app.
servic
e.message_gate
import
MessageGate
from
app.
agent_cor
e.message_gate
import
MessageGate
pending
=
[{
"msg_type"
:
"text"
,
"msg_content"
:
"帮我整理纪要"
}]
pending
=
[{
"msg_type"
:
"text"
,
"msg_content"
:
"帮我整理纪要"
}]
query
,
file_url
=
MessageGate
.
_extract_query_and_file_url
(
pending
)
query
,
file_url
=
MessageGate
.
_extract_query_and_file_url
(
pending
)
assert
query
==
"帮我整理纪要"
assert
query
==
"帮我整理纪要"
...
@@ -133,7 +133,7 @@ def test_extract_query_and_file_url_text_only():
...
@@ -133,7 +133,7 @@ def test_extract_query_and_file_url_text_only():
def
test_extract_query_and_file_url_with_file
():
def
test_extract_query_and_file_url_with_file
():
"""混合文本+文件消息时,提取 query 和 file_url。"""
"""混合文本+文件消息时,提取 query 和 file_url。"""
from
app.
servic
e.message_gate
import
MessageGate
from
app.
agent_cor
e.message_gate
import
MessageGate
pending
=
[
pending
=
[
{
"msg_type"
:
"text"
,
"msg_content"
:
"分析这份报表"
},
{
"msg_type"
:
"text"
,
"msg_content"
:
"分析这份报表"
},
{
"msg_type"
:
"file"
,
"msg_content"
:
"https://oss.example.com/report.xlsx"
},
{
"msg_type"
:
"file"
,
"msg_content"
:
"https://oss.example.com/report.xlsx"
},
...
@@ -145,7 +145,7 @@ def test_extract_query_and_file_url_with_file():
...
@@ -145,7 +145,7 @@ def test_extract_query_and_file_url_with_file():
def
test_extract_query_and_file_url_append_url
():
def
test_extract_query_and_file_url_append_url
():
"""文本中已含 URL 时,不重复追加。"""
"""文本中已含 URL 时,不重复追加。"""
from
app.
servic
e.message_gate
import
MessageGate
from
app.
agent_cor
e.message_gate
import
MessageGate
pending
=
[
pending
=
[
{
"msg_type"
:
"text"
,
"msg_content"
:
"看下这个 https://example.com/doc"
},
{
"msg_type"
:
"text"
,
"msg_content"
:
"看下这个 https://example.com/doc"
},
]
]
...
@@ -157,7 +157,7 @@ def test_extract_query_and_file_url_append_url():
...
@@ -157,7 +157,7 @@ def test_extract_query_and_file_url_append_url():
def
test_extract_query_and_file_url_empty
():
def
test_extract_query_and_file_url_empty
():
"""空 pending 返回空 query。"""
"""空 pending 返回空 query。"""
from
app.
servic
e.message_gate
import
MessageGate
from
app.
agent_cor
e.message_gate
import
MessageGate
query
,
file_url
=
MessageGate
.
_extract_query_and_file_url
([])
query
,
file_url
=
MessageGate
.
_extract_query_and_file_url
([])
assert
query
==
""
assert
query
==
""
assert
file_url
is
None
assert
file_url
is
None
...
...
workspace/agent-admin/backend/tests/test_read_file_tool.py
View file @
f23adaf
...
@@ -5,8 +5,8 @@ import shutil
...
@@ -5,8 +5,8 @@ import shutil
from
pathlib
import
Path
from
pathlib
import
Path
from
unittest.mock
import
MagicMock
,
AsyncMock
from
unittest.mock
import
MagicMock
,
AsyncMock
from
app.
servic
e.active_session_service
import
ActiveSessionService
from
app.
agent_cor
e.active_session_service
import
ActiveSessionService
from
app.
servic
e.agent_hub
import
AgentHub
from
app.
agent_cor
e.agent_hub
import
AgentHub
from
agentscope.message._message_block
import
TextBlock
from
agentscope.message._message_block
import
TextBlock
...
...
workspace/agent-admin/backend/tests/test_session_buffer.py
View file @
f23adaf
"""SessionBuffer 单元测试 - 测试 pending_messages 的存取。"""
"""SessionBuffer 单元测试 - 测试 pending_messages 的存取。"""
import
pytest
import
pytest
from
app.infrastructure.session_store
import
SessionStore
from
app.infrastructure.session_store
import
SessionStore
from
app.
servic
e.session_buffer
import
SessionBuffer
from
app.
agent_cor
e.session_buffer
import
SessionBuffer
@pytest.fixture
@pytest.fixture
...
...
workspace/agent-admin/backend/tests/test_session_persistence.py
View file @
f23adaf
...
@@ -6,7 +6,7 @@ from app.infrastructure.session_store import (
...
@@ -6,7 +6,7 @@ from app.infrastructure.session_store import (
SessionStore
,
SESSION_TTL_SECONDS
,
active_session_key
,
SessionStore
,
SESSION_TTL_SECONDS
,
active_session_key
,
)
)
from
app.infrastructure.kv_store
import
InMemoryKeyValueStore
from
app.infrastructure.kv_store
import
InMemoryKeyValueStore
from
app.
servic
e.active_session_service
import
ActiveSessionService
,
ActiveSessionInfo
from
app.
agent_cor
e.active_session_service
import
ActiveSessionService
,
ActiveSessionInfo
class
TestSessionStoreTTLRefresh
:
class
TestSessionStoreTTLRefresh
:
...
@@ -152,7 +152,7 @@ class TestDatabasePersistence:
...
@@ -152,7 +152,7 @@ class TestDatabasePersistence:
def
test_restore_preserves_conversation_history
(
self
,
svc
,
db
):
def
test_restore_preserves_conversation_history
(
self
,
svc
,
db
):
"""恢复后 conversation_history 完整保留"""
"""恢复后 conversation_history 完整保留"""
from
app.
servic
e.memory
import
SessionMemory
from
app.
agent_cor
e.memory
import
SessionMemory
svc
.
get_or_create_session
(
"db_hist"
,
room_id
=
"room_001"
)
svc
.
get_or_create_session
(
"db_hist"
,
room_id
=
"room_001"
)
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment