diff --git a/backend/agent/runtime.py b/backend/agent/runtime.py index 7c24afb..61453be 100644 --- a/backend/agent/runtime.py +++ b/backend/agent/runtime.py @@ -605,7 +605,12 @@ class WorkflowRuntime: session_pk=session.id, role="assistant", content=content, sources_json=json.dumps(sources, ensure_ascii=False, default=str), workflow_id=run.workflow_id, workflow_revision_id=run.workflow_revision_id, workflow_run_id=run.id, - agent_summary_json=json.dumps({"tool_calls": counters["tool_calls"], "llm_calls": counters["llm_calls"], "duration_seconds": duration}), + agent_summary_json=json.dumps({ + "tool_calls": counters["tool_calls"], + "llm_calls": counters["llm_calls"], + "duration_seconds": duration, + "selection_mode": run.selection_mode, + }), usage_json=json.dumps(usage), )) db.commit() diff --git a/src/chatGeneration.js b/src/chatGeneration.js index 86a8ec1..7e19d02 100644 --- a/src/chatGeneration.js +++ b/src/chatGeneration.js @@ -218,16 +218,17 @@ export function createChatGenerationHandlers({ const currentSelection = getChatWorkflowForSession(sessionId) || { mode: 'direct', workflowId: null } const originalAssistant = msgs.slice(lastUserIdx + 1).find(message => message?.role === 'assistant') const originalWorkflowId = originalAssistant?.workflow_id || null + const originalSelectionMode = originalAssistant?.agent_summary?.selection_mode || null let selection = currentSelection let workflowRevisionId = null - if (currentSelection.mode === 'automatic' && originalWorkflowId) { + if (currentSelection.mode === 'automatic' && originalSelectionMode === 'automatic' && originalWorkflowId) { selection = { mode: 'explicit', workflowId: originalWorkflowId } workflowRevisionId = originalAssistant?.workflow_revision_id || null } else if ( originalWorkflowId && ( - (currentSelection.mode === 'explicit' && currentSelection.workflowId === originalWorkflowId) - || (currentSelection.mode === 'direct' && originalWorkflowId === 'input-output') + (currentSelection.mode === 'explicit' && originalSelectionMode === 'explicit' && currentSelection.workflowId === originalWorkflowId) + || (currentSelection.mode === 'direct' && originalSelectionMode === 'direct') ) ) { workflowRevisionId = originalAssistant?.workflow_revision_id || null