refactor: unify system tools as resources
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import unittest
|
||||
from copy import deepcopy
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from models import AssistantConfig, RuntimeModelResource
|
||||
from fastapi import HTTPException
|
||||
from routes.assistants import _validate_workflow, _validate_workflow_references
|
||||
from routes.assistants import (
|
||||
_validate_system_tool_selection,
|
||||
_validate_workflow,
|
||||
_validate_workflow_references,
|
||||
)
|
||||
from schemas import AssistantUpsert
|
||||
from services.pipecat.service_factory import config_with_resource
|
||||
from services.node_specs import graph_references, normalize_graph, validate_graph
|
||||
@@ -363,7 +369,6 @@ class WorkflowGraphTests(unittest.TestCase):
|
||||
agent = next(node for node in graph["nodes"] if node["id"] == "agent")
|
||||
agent["data"].update(
|
||||
{
|
||||
"systemTools": ["update_state", "skip_turn"],
|
||||
"stateVariableNames": ["customer", "order_status"],
|
||||
}
|
||||
)
|
||||
@@ -374,7 +379,7 @@ class WorkflowGraphTests(unittest.TestCase):
|
||||
"defaultTtsResourceId": "tts_global",
|
||||
"visionEnabled": True,
|
||||
"visionModelResourceId": "vision_global",
|
||||
"toolIds": ["tool_global"],
|
||||
"toolIds": ["tool_global", "update_state", "skip_turn"],
|
||||
"knowledgeBaseId": "kb_global",
|
||||
"knowledgeMode": "on_demand",
|
||||
"knowledgeTopN": 8,
|
||||
@@ -395,8 +400,10 @@ class WorkflowGraphTests(unittest.TestCase):
|
||||
"vision_global",
|
||||
)
|
||||
self.assertTrue(engine.uses_vision())
|
||||
self.assertEqual(inherited.tool_ids, ("tool_global",))
|
||||
self.assertEqual(inherited.system_tools, ("update_state", "skip_turn"))
|
||||
self.assertEqual(
|
||||
inherited.tool_ids,
|
||||
("tool_global", "update_state", "skip_turn"),
|
||||
)
|
||||
self.assertEqual(
|
||||
inherited.state_variable_names,
|
||||
("customer", "order_status"),
|
||||
@@ -412,7 +419,7 @@ class WorkflowGraphTests(unittest.TestCase):
|
||||
{
|
||||
"inheritGlobalConfig": False,
|
||||
"llmResourceId": "llm_agent",
|
||||
"toolIds": ["tool_agent"],
|
||||
"toolIds": ["tool_agent", "update_state", "skip_turn"],
|
||||
"knowledgeBaseId": "",
|
||||
"visionEnabled": False,
|
||||
"visionModelResourceId": "",
|
||||
@@ -428,8 +435,10 @@ class WorkflowGraphTests(unittest.TestCase):
|
||||
self.assertFalse(custom.vision_enabled)
|
||||
self.assertIsNone(custom.vision_model_resource_id)
|
||||
self.assertFalse(engine.uses_vision())
|
||||
self.assertEqual(custom.tool_ids, ("tool_agent",))
|
||||
self.assertEqual(custom.system_tools, ("update_state", "skip_turn"))
|
||||
self.assertEqual(
|
||||
custom.tool_ids,
|
||||
("tool_agent", "update_state", "skip_turn"),
|
||||
)
|
||||
self.assertEqual(custom.knowledge_mode, "disabled")
|
||||
self.assertTrue(custom.enable_interrupt)
|
||||
self.assertEqual(
|
||||
@@ -463,7 +472,6 @@ class WorkflowGraphTests(unittest.TestCase):
|
||||
agent = next(node for node in graph["nodes"] if node["id"] == "agent")
|
||||
agent["data"].update(
|
||||
{
|
||||
"systemTools": ["update_state"],
|
||||
"stateVariableNames": ["customer"],
|
||||
}
|
||||
)
|
||||
@@ -497,8 +505,8 @@ class WorkflowGraphTests(unittest.TestCase):
|
||||
|
||||
def test_agent_update_state_tool_requires_an_authorized_variable(self):
|
||||
graph = valid_graph()
|
||||
graph["settings"]["toolIds"] = ["tool_update_state"]
|
||||
agent = next(node for node in graph["nodes"] if node["id"] == "agent")
|
||||
agent["data"]["systemTools"] = ["update_state"]
|
||||
body = AssistantUpsert(
|
||||
name="缺少授权",
|
||||
type="workflow",
|
||||
@@ -512,8 +520,19 @@ class WorkflowGraphTests(unittest.TestCase):
|
||||
graph=graph,
|
||||
)
|
||||
|
||||
_validate_workflow(body)
|
||||
system_tool = SimpleNamespace(
|
||||
id="tool_update_state",
|
||||
status="active",
|
||||
type="system",
|
||||
definition={"config": {"kind": "update_state"}},
|
||||
)
|
||||
result = SimpleNamespace(
|
||||
scalars=lambda: SimpleNamespace(all=lambda: [system_tool])
|
||||
)
|
||||
session = SimpleNamespace(execute=AsyncMock(return_value=result))
|
||||
with self.assertRaisesRegex(HTTPException, "必须授权至少一个变量"):
|
||||
_validate_workflow(body)
|
||||
asyncio.run(_validate_system_tool_selection(session, body))
|
||||
|
||||
def test_vision_resource_creates_isolated_runtime_config(self):
|
||||
base = AssistantConfig(type="workflow", model="text-only")
|
||||
|
||||
Reference in New Issue
Block a user