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

@@ -23,6 +23,8 @@ class AgentStageConfig:
knowledge_mode: str
knowledge_top_n: int
knowledge_score_threshold: float
enable_interrupt: bool
turn_config: dict[str, Any]
class WorkflowEngine:
@@ -106,6 +108,12 @@ class WorkflowEngine:
asr_key = "defaultAsrResourceId" if inherits_global else "asrResourceId"
tts_key = "defaultTtsResourceId" if inherits_global else "ttsResourceId"
knowledge_base_id = str(source.get("knowledgeBaseId") or "")
global_turn_config = self.settings.get("turnConfig")
if not isinstance(global_turn_config, dict):
global_turn_config = {}
turn_config = source.get("turnConfig", global_turn_config)
if not isinstance(turn_config, dict):
turn_config = global_turn_config
return AgentStageConfig(
inherits_global=inherits_global,
llm_resource_id=str(source.get(llm_key) or ""),
@@ -122,6 +130,13 @@ class WorkflowEngine:
knowledge_score_threshold=float(
source.get("knowledgeScoreThreshold") or 0.0
),
enable_interrupt=bool(
source.get(
"enableInterrupt",
self.settings.get("enableInterrupt", True),
)
),
turn_config=dict(turn_config),
)
def prompt_for(self, node_id: str, store: DynamicVariableStore) -> str: