Refactor workflow agent and routing components for improved functionality
- Introduce WorkflowAgentStage to manage agent stage configurations and enhance interaction with the workflow engine. - Implement WorkflowEdgeEvaluator for priority-aware edge evaluation, improving routing decisions based on conditions and user turns. - Update WorkflowBrain to handle user turns and routing more effectively, ensuring agents cannot have only one default path. - Enhance CallEndCoordinator to track speech events and manage call termination based on queued speech. - Add new models and output handling for workflow interactions, improving clarity and maintainability. - Update tests to validate the new routing logic and agent behavior under various scenarios.
This commit is contained in:
@@ -211,7 +211,7 @@ class WorkflowGraphTests(unittest.TestCase):
|
||||
"smart_turn",
|
||||
)
|
||||
|
||||
def test_start_agent_and_handoff_may_have_no_outgoing_edge(self):
|
||||
def test_start_agent_action_and_handoff_may_have_no_outgoing_edge(self):
|
||||
terminal_graphs = [
|
||||
{
|
||||
"specVersion": 3,
|
||||
@@ -277,13 +277,47 @@ class WorkflowGraphTests(unittest.TestCase):
|
||||
}
|
||||
],
|
||||
}
|
||||
self.assertEqual(validate_graph(action_without_exit), [])
|
||||
|
||||
def test_agent_cannot_have_only_one_default_path(self):
|
||||
graph = {
|
||||
"specVersion": 3,
|
||||
"settings": {},
|
||||
"nodes": [
|
||||
{"id": "start", "type": "start", "data": {}},
|
||||
{"id": "agent", "type": "agent", "data": {}},
|
||||
{"id": "end", "type": "end", "data": {}},
|
||||
],
|
||||
"edges": [
|
||||
{
|
||||
"id": "begin",
|
||||
"source": "start",
|
||||
"target": "agent",
|
||||
"data": {"mode": "always", "priority": 0},
|
||||
},
|
||||
{
|
||||
"id": "leave",
|
||||
"source": "agent",
|
||||
"target": "end",
|
||||
"data": {"mode": "always", "priority": 0},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
self.assertTrue(
|
||||
any(
|
||||
"action 的出边不能少于 1" in error
|
||||
for error in validate_graph(action_without_exit)
|
||||
"Agent 节点 agent 不能只有默认路径" in error
|
||||
for error in validate_graph(graph)
|
||||
)
|
||||
)
|
||||
|
||||
graph["edges"][1]["data"] = {
|
||||
"mode": "llm",
|
||||
"priority": 10,
|
||||
"condition": "当前阶段已经完成",
|
||||
}
|
||||
self.assertEqual(validate_graph(graph), [])
|
||||
|
||||
def test_all_source_nodes_allow_multiple_conditional_paths(self):
|
||||
expression = {
|
||||
"combinator": "and",
|
||||
@@ -448,6 +482,41 @@ class WorkflowGraphTests(unittest.TestCase):
|
||||
self.assertNotIn("服务 王先生", custom_prompt)
|
||||
self.assertIn("处理订单", custom_prompt)
|
||||
|
||||
def test_missing_variable_only_matches_explicit_exists_rule(self):
|
||||
engine = WorkflowEngine(valid_graph())
|
||||
values = {}
|
||||
|
||||
self.assertFalse(
|
||||
engine.expression_matches(
|
||||
{
|
||||
"combinator": "and",
|
||||
"rules": [
|
||||
{
|
||||
"variable": "order_status",
|
||||
"operator": "neq",
|
||||
"value": "paid",
|
||||
}
|
||||
],
|
||||
},
|
||||
values,
|
||||
)
|
||||
)
|
||||
self.assertTrue(
|
||||
engine.expression_matches(
|
||||
{
|
||||
"combinator": "and",
|
||||
"rules": [
|
||||
{
|
||||
"variable": "order_status",
|
||||
"operator": "exists",
|
||||
"value": False,
|
||||
}
|
||||
],
|
||||
},
|
||||
values,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user