Enhance conversation history and runtime variable management

- Update ConversationRecorder to include source and nodeId metadata in transcripts for better context tracking.
- Introduce optional variable handling in DynamicVariableStore, allowing for unset variables to be rendered as empty without raising errors.
- Refactor WorkflowBrain to apply turn configurations and manage interaction policies dynamically, improving agent responsiveness.
- Implement tests to ensure proper handling of updated session variables and workflow metadata in various scenarios.
This commit is contained in:
Xin Wang
2026-07-14 11:08:11 +08:00
parent 665f727796
commit f74040adf3
18 changed files with 848 additions and 194 deletions

View File

@@ -170,6 +170,11 @@ class WorkflowGraphTests(unittest.TestCase):
"knowledgeMode": "on_demand",
"knowledgeTopN": 8,
"knowledgeScoreThreshold": 0.4,
"enableInterrupt": False,
"turnConfig": {
"bargeIn": {"strategy": "transcription"},
"turnDetection": {"strategy": "silence", "silenceTimeoutSecs": 1.2},
},
}
)
engine = WorkflowEngine(graph)
@@ -177,6 +182,11 @@ class WorkflowGraphTests(unittest.TestCase):
self.assertEqual(inherited.llm_resource_id, "llm_global")
self.assertEqual(inherited.tool_ids, ("tool_global",))
self.assertEqual(inherited.knowledge_mode, "on_demand")
self.assertFalse(inherited.enable_interrupt)
self.assertEqual(
inherited.turn_config["bargeIn"]["strategy"],
"transcription",
)
engine.data("agent").update(
{
@@ -184,12 +194,22 @@ class WorkflowGraphTests(unittest.TestCase):
"llmResourceId": "llm_agent",
"toolIds": ["tool_agent"],
"knowledgeBaseId": "",
"enableInterrupt": True,
"turnConfig": {
"bargeIn": {"strategy": "vad"},
"turnDetection": {"strategy": "smart_turn"},
},
}
)
custom = engine.agent_stage_config("agent")
self.assertEqual(custom.llm_resource_id, "llm_agent")
self.assertEqual(custom.tool_ids, ("tool_agent",))
self.assertEqual(custom.knowledge_mode, "disabled")
self.assertTrue(custom.enable_interrupt)
self.assertEqual(
custom.turn_config["turnDetection"]["strategy"],
"smart_turn",
)
def test_start_agent_and_handoff_may_have_no_outgoing_edge(self):
terminal_graphs = [