Files
ecom-dmb/apps/agent/agent/runtime.py
T

48 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""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 "")