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:
@@ -79,6 +79,58 @@ class DynamicVariableTests(unittest.TestCase):
|
||||
"Bearer private",
|
||||
)
|
||||
|
||||
def test_optional_workflow_variable_renders_empty_but_remains_unset(self):
|
||||
cfg = AssistantConfig(
|
||||
type="workflow",
|
||||
graph={
|
||||
"specVersion": 3,
|
||||
"settings": {"globalPrompt": "称呼 {{nickname}}"},
|
||||
"nodes": [
|
||||
{
|
||||
"id": "start",
|
||||
"type": "start",
|
||||
"data": {"greeting": "您好 {{nickname}}"},
|
||||
}
|
||||
],
|
||||
"edges": [],
|
||||
},
|
||||
greeting="",
|
||||
dynamic_variable_definitions={
|
||||
"nickname": {
|
||||
"type": "string",
|
||||
"required": False,
|
||||
"default": None,
|
||||
}
|
||||
},
|
||||
)
|
||||
prepared = prepare_dynamic_config(cfg, {}, assistant_id="asst_workflow")
|
||||
store = DynamicVariableStore.from_config(prepared)
|
||||
|
||||
self.assertEqual(store.render("您好 {{nickname}}"), "您好 ")
|
||||
self.assertNotIn("nickname", store.values)
|
||||
with self.assertRaisesRegex(DynamicVariableError, "缺少动态变量"):
|
||||
store.render("{{not_defined}}")
|
||||
|
||||
def test_exact_placeholder_keeps_action_argument_type(self):
|
||||
store = DynamicVariableStore(
|
||||
{"count": 3, "confirmed": True},
|
||||
variable_types={"count": "number", "confirmed": "boolean"},
|
||||
)
|
||||
|
||||
rendered = store.render_data(
|
||||
{
|
||||
"count": "{{count}}",
|
||||
"confirmed": "{{confirmed}}",
|
||||
"label": "数量 {{count}}",
|
||||
}
|
||||
)
|
||||
self.assertEqual(rendered["count"], 3)
|
||||
self.assertIs(rendered["confirmed"], True)
|
||||
self.assertEqual(rendered["label"], "数量 3")
|
||||
|
||||
with self.assertRaisesRegex(DynamicVariableError, "类型应为 number"):
|
||||
store.assign("count", "four")
|
||||
|
||||
def test_tool_assignment_and_system_history(self):
|
||||
store = DynamicVariableStore(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user