feat: Enhance context variable handling for Agent and LLM nodes

This commit is contained in:
zhsama
2026-01-15 23:26:19 +08:00
parent f247ebfbe1
commit f43fde5797
8 changed files with 88 additions and 65 deletions

View File

@ -67,7 +67,8 @@ const WorkflowVariableBlockComponent = ({
)()
const [localWorkflowNodesMap, setLocalWorkflowNodesMap] = useState<WorkflowNodesMap>(workflowNodesMap)
const node = localWorkflowNodesMap![variables[isRagVar ? 1 : 0]]
const isAgentContextVariable = node?.type === BlockEnum.Agent && variables[variablesLength - 1] === 'context'
const isContextVariable = (node?.type === BlockEnum.Agent || node?.type === BlockEnum.LLM)
&& variables[variablesLength - 1] === 'context'
const isException = isExceptionVariable(varName, node?.type)
const variableValid = useMemo(() => {
@ -136,7 +137,7 @@ const WorkflowVariableBlockComponent = ({
})
}, [node, reactflow, store])
if (isAgentContextVariable)
if (isContextVariable)
return <span className="hidden" ref={ref} />
const Item = (

View File

@ -123,8 +123,9 @@ export class WorkflowVariableBlockNode extends DecoratorNode<React.JSX.Element>
getTextContent(): string {
const variables = this.getVariables()
const node = this.getWorkflowNodesMap()?.[variables[0]]
const isAgentContextVariable = node?.type === BlockEnum.Agent && variables[variables.length - 1] === 'context'
const marker = isAgentContextVariable ? '@' : '#'
const isContextVariable = (node?.type === BlockEnum.Agent || node?.type === BlockEnum.LLM)
&& variables[variables.length - 1] === 'context'
const marker = isContextVariable ? '@' : '#'
return `{{${marker}${variables.join('.')}${marker}}}`
}
}