Add system-level dynamic variables support in session management. Implement methods to generate and apply built-in variables for current session time, UTC time, and timezone. Update documentation to reflect new variables and enhance tests for dynamic variable handling in the UI components.

This commit is contained in:
Xin Wang
2026-02-27 12:08:18 +08:00
parent 71cbfa2b48
commit 6178cc05bb
5 changed files with 242 additions and 21 deletions

View File

@@ -94,3 +94,39 @@ def test_apply_dynamic_variables_no_placeholder_keeps_metadata():
assert error is None
assert resolved == metadata
def test_apply_dynamic_variables_supports_system_time_variables_without_client_payload():
session = _session()
metadata = {
"systemPrompt": "Now={{system__time}} utc={{system_utc}} tz={{system_timezone}}",
"greeting": "Clock {{system__time}}",
}
resolved, error = session._apply_dynamic_variables(metadata, {})
assert error is None
assert "{{system__time}}" not in resolved["systemPrompt"]
assert "{{system_utc}}" not in resolved["systemPrompt"]
assert "{{system_timezone}}" not in resolved["systemPrompt"]
assert "{{system__time}}" not in resolved["greeting"]
def test_apply_dynamic_variables_keeps_system_variables_reserved():
session = _session()
metadata = {
"systemPrompt": "Clock={{system__time}} Name={{customer_name}}",
"greeting": "Hi {{customer_name}}",
}
client_metadata = {
"dynamicVariables": {
"system__time": "manual_override",
"customer_name": "Alice",
}
}
resolved, error = session._apply_dynamic_variables(metadata, client_metadata)
assert error is None
assert "manual_override" not in resolved["systemPrompt"]
assert "Alice" in resolved["systemPrompt"]