disable agent message tools for ui background tasks

This commit is contained in:
jxxghp
2026-04-29 23:30:59 +08:00
parent ef5bd29759
commit 7586a2cd42
11 changed files with 48 additions and 99 deletions
+20
View File
@@ -79,6 +79,15 @@ class MoviePilotToolFactory:
MoviePilot工具工厂
"""
_MESSAGE_TOOL_CLASSES = frozenset(
{
SendMessageTool,
AskUserChoiceTool,
SendLocalFileTool,
SendVoiceMessageTool,
}
)
@staticmethod
def _should_enable_choice_tool(channel: str = None) -> bool:
if not channel:
@@ -100,6 +109,7 @@ class MoviePilotToolFactory:
username: str = None,
stream_handler: Callable = None,
agent_context: dict = None,
allow_message_tools: bool = True,
) -> List[MoviePilotTool]:
"""
创建MoviePilot工具列表
@@ -181,6 +191,11 @@ class MoviePilotToolFactory:
)
# 创建内置工具
for ToolClass in tool_definitions:
if (
not allow_message_tools
and ToolClass in MoviePilotToolFactory._MESSAGE_TOOL_CLASSES
):
continue
tool = ToolClass(session_id=session_id, user_id=user_id)
tool.set_message_attr(channel=channel, source=source, username=username)
tool.set_stream_handler(stream_handler=stream_handler)
@@ -196,6 +211,11 @@ class MoviePilotToolFactory:
tool_classes = plugin_info.get("tools", [])
for ToolClass in tool_classes:
try:
if (
not allow_message_tools
and ToolClass in MoviePilotToolFactory._MESSAGE_TOOL_CLASSES
):
continue
# 验证工具类是否继承自 MoviePilotTool
if not issubclass(ToolClass, MoviePilotTool):
logger.warning(