feat: add system tools and state updates
This commit is contained in:
@@ -360,6 +360,13 @@ class WorkflowGraphTests(unittest.TestCase):
|
||||
|
||||
def test_agent_effective_config_inherits_then_switches_to_override(self):
|
||||
graph = valid_graph()
|
||||
agent = next(node for node in graph["nodes"] if node["id"] == "agent")
|
||||
agent["data"].update(
|
||||
{
|
||||
"systemTools": ["update_state", "skip_turn"],
|
||||
"stateVariableNames": ["customer", "order_status"],
|
||||
}
|
||||
)
|
||||
graph["settings"].update(
|
||||
{
|
||||
"defaultLlmResourceId": "llm_global",
|
||||
@@ -389,6 +396,11 @@ class WorkflowGraphTests(unittest.TestCase):
|
||||
)
|
||||
self.assertTrue(engine.uses_vision())
|
||||
self.assertEqual(inherited.tool_ids, ("tool_global",))
|
||||
self.assertEqual(inherited.system_tools, ("update_state", "skip_turn"))
|
||||
self.assertEqual(
|
||||
inherited.state_variable_names,
|
||||
("customer", "order_status"),
|
||||
)
|
||||
self.assertEqual(inherited.knowledge_mode, "on_demand")
|
||||
self.assertFalse(inherited.enable_interrupt)
|
||||
self.assertEqual(
|
||||
@@ -417,6 +429,7 @@ class WorkflowGraphTests(unittest.TestCase):
|
||||
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.knowledge_mode, "disabled")
|
||||
self.assertTrue(custom.enable_interrupt)
|
||||
self.assertEqual(
|
||||
@@ -424,6 +437,84 @@ class WorkflowGraphTests(unittest.TestCase):
|
||||
"smart_turn",
|
||||
)
|
||||
|
||||
def test_update_state_node_and_agent_state_scope_are_validated(self):
|
||||
graph = valid_graph()
|
||||
graph["nodes"].insert(
|
||||
1,
|
||||
{
|
||||
"id": "set_state",
|
||||
"type": "update_state",
|
||||
"data": {
|
||||
"name": "记录状态",
|
||||
"assignments": {"confirmed": True},
|
||||
},
|
||||
},
|
||||
)
|
||||
graph["edges"][0]["target"] = "set_state"
|
||||
graph["edges"].insert(
|
||||
1,
|
||||
{
|
||||
"id": "after_state",
|
||||
"source": "set_state",
|
||||
"target": "agent",
|
||||
"data": {"mode": "always", "priority": 0},
|
||||
},
|
||||
)
|
||||
agent = next(node for node in graph["nodes"] if node["id"] == "agent")
|
||||
agent["data"].update(
|
||||
{
|
||||
"systemTools": ["update_state"],
|
||||
"stateVariableNames": ["customer"],
|
||||
}
|
||||
)
|
||||
body = AssistantUpsert(
|
||||
name="状态工作流",
|
||||
type="workflow",
|
||||
dynamicVariableDefinitions={
|
||||
"confirmed": {
|
||||
"type": "boolean",
|
||||
"required": False,
|
||||
"default": False,
|
||||
},
|
||||
"customer": {
|
||||
"type": "string",
|
||||
"required": False,
|
||||
"default": None,
|
||||
},
|
||||
},
|
||||
graph=graph,
|
||||
)
|
||||
|
||||
_validate_workflow(body)
|
||||
normalized_state = next(
|
||||
node for node in body.graph["nodes"] if node["type"] == "update_state"
|
||||
)
|
||||
self.assertEqual(normalized_state["data"]["assignments"], {"confirmed": True})
|
||||
|
||||
normalized_state["data"]["assignments"] = {"missing": "x"}
|
||||
with self.assertRaisesRegex(HTTPException, "未声明变量:missing"):
|
||||
_validate_workflow(body)
|
||||
|
||||
def test_agent_update_state_tool_requires_an_authorized_variable(self):
|
||||
graph = valid_graph()
|
||||
agent = next(node for node in graph["nodes"] if node["id"] == "agent")
|
||||
agent["data"]["systemTools"] = ["update_state"]
|
||||
body = AssistantUpsert(
|
||||
name="缺少授权",
|
||||
type="workflow",
|
||||
dynamicVariableDefinitions={
|
||||
"customer": {
|
||||
"type": "string",
|
||||
"required": False,
|
||||
"default": None,
|
||||
}
|
||||
},
|
||||
graph=graph,
|
||||
)
|
||||
|
||||
with self.assertRaisesRegex(HTTPException, "必须授权至少一个变量"):
|
||||
_validate_workflow(body)
|
||||
|
||||
def test_vision_resource_creates_isolated_runtime_config(self):
|
||||
base = AssistantConfig(type="workflow", model="text-only")
|
||||
resource = RuntimeModelResource(
|
||||
|
||||
Reference in New Issue
Block a user