mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-23 23:19:19 +08:00
48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
"""Agent 编排:按会话 scene 装载工具。"""
|
||
|
||
from __future__ import annotations
|
||
|
||
from typing import Any
|
||
|
||
from application.memory_service import MemoryService
|
||
from config.settings import Settings
|
||
from domain.models import SCENE_ECOM_GOODS_PUBLISH, SCENE_GENERAL, Actor
|
||
|
||
|
||
async def load_tools_for_turn(
|
||
settings: Settings,
|
||
*,
|
||
actor: Actor,
|
||
memory: MemoryService,
|
||
scene: str = SCENE_GENERAL,
|
||
client_tools: list[Any] | None = None,
|
||
) -> list[Any]:
|
||
"""各场景均挂 memory_*;general 全量 MCP,发布场景仅目录/拼多多 + 前端 ui_。"""
|
||
from agent.tools.builtin import builtin_tools
|
||
from agent.tools.memory import memory_tools
|
||
from infrastructure.mcp.client import load_mcp_tools
|
||
|
||
scene_value = (scene or SCENE_GENERAL).strip() or SCENE_GENERAL
|
||
tools: list[Any] = [*builtin_tools(), *memory_tools(memory, actor)]
|
||
|
||
mcp_tools = await load_mcp_tools(
|
||
settings,
|
||
company_id=actor.company_id,
|
||
user_id=actor.user_id,
|
||
)
|
||
if scene_value == SCENE_ECOM_GOODS_PUBLISH:
|
||
# 发布场景:目录 + 拼多多渠道;不挂经营 BI
|
||
mcp_tools = [
|
||
t
|
||
for t in mcp_tools
|
||
if _tool_name(t).startswith(("catalog_", "pdd_")) or _tool_name(t) == "mcp_ping"
|
||
]
|
||
tools.extend(mcp_tools)
|
||
if client_tools:
|
||
tools.extend(client_tools)
|
||
return tools
|
||
|
||
|
||
def _tool_name(tool: Any) -> str:
|
||
return str(getattr(tool, "name", None) or "")
|