Repository navigation
fix: context button for an LLM node cannot be interacted with within an agent workflow - #8216
Conversation
…an agent workflow
| enableException: typeof args.enable_exception === 'boolean' ? args.enable_exception : Boolean(node.properties.enableException), | ||
| }) | ||
| if (defaultMissing) { | ||
| return new ErrorResult( |
There was a problem hiding this comment.
Review
1. Bugs / correctness
a) Hard failure on unrelated updates (regression risk)
if (enableContext && !contextVariable.length) {
return new ErrorResult('开启「上下文」需要先绑定入参 materials ...')
}enableContext falls back to Boolean(nodeData.enable_context). For any node that already has enable_context === true but no materials binding (legacy nodes, or nodes configured before this change), every update call now fails — including updates to prompt, tools, is_result, etc. — until the user either binds materials or explicitly passes enable_context: false. That breaks the documented contract of update ("只传要设置的字段,其余保持不变") and is a silent behavior break for existing workflows.
Fix: only validate when the user is changing context state, e.g.
const contextExplicit = typeof args.enable_context === 'boolean' || materialRefs.length > 0
if (contextExplicit && enableContext && !contextVariable.length) { ... }or auto-disable instead of erroring:
const enableContext = materialRefs.length ? (args.enable_context ?? true) : falseb) Silent data loss with multiple materials refs
const contextVariable = materialRefs.length ? [...materialRefs[0]!] : ...context_variable is a single [nodeId, field] reference, but materialRefs is a list. If the parent binds more than one, all but the first are dropped without warning. Either:
- error/warn when
materialRefs.length > 1, or - change
context_variableto an array and store all refs.
c) Silent clearing of an existing context_variable
: Array.isArray(nodeData.context_variable) ? [...nodeData.context_variable] : []If context_variable is currently a non-array shape (legacy/object/string), Array.isArray is false → it becomes [], i.e. the value is wiped on an unrelated update. Safer: only write the key when you actually have something to write:
const patch: Record<string, unknown> = {}
if (materialRefs.length) patch.context_variable = [...materialRefs[0]!]
// otherwise leave the existing value untouchedd) materials type changed to an invalid JSON Schema type
- type: 'array', items: {}, description: '...'
+ type: 'any',"any" is not a valid JSON Schema type. With Ajv (or any spec-compliant validator) this throws schema is invalid: data/properties/materials/type must be equal to one of the allowed values at compile time — the whole update tool would break. Use one of:
materials: { description: '...', 'x-bind': 'context_variable' } // untyped
materials: { type: ['string', 'array', 'object'], description: '...' } // draft-07 style
materials: { anyOf: [{ type: 'string' }, { type: 'array' }, { type: 'object' }] }If your validator is custom and accepts 'any', at least document that — it's non-standard and will confuse anyone reading it as JSON Schema.
e) Schema/doc contradiction
materials now says "可为字符串、数组或对象 … 绑定后写到 context_variable", but the comment says context_variable is a single [节点ID, 字段] reference. The description implies the caller can pass a literal value or multiple entries, which the implementation cannot honor. Align the wording with the actual constraint (a single bound upstream variable).
2. Type-safety / robustness
[...materialRefs[0]!]— the non-null assertion is required bynoUncheckedIndexedAccess, but note the spread producesstring[], not a tuple. If the backend expects exactly[nodeId, field], a ref like[nodeId, 'a', 'b']will produce an invalid 3-element value. Destructure explicitly and validate length.node.properties.enableException— will throw ifpropertiesis ever undefined. Usenode.properties?.enableException. Also verify the field really lives undernode.properties(camelCase) rather thannode_data: everything else isnode_data+ snake_case, and this asymmetry is a likely source of a "setting silently doesn't persist" bug. Consider a helper (readExceptionFlag(node)/writeExceptionFlag(node, v)) so read and write locations can't drift.Boolean(nodeData.enable_context)vs the previous(nodeData.enable_context ?? false)is equivalent — no issue, just noise in the diff.- Nested ternary:
typeof args.enable_context === 'boolean' ? args.enable_context : materialRefs.length ? true : Boolean(...)Correct but trips no-nested-ternary; prefer:
const enableContext =
typeof args.enable_context === 'boolean' ? args.enable_context
: materialRefs.length ? true
: Boolean(nodeData.enable_context)context_variableis written even whenenable_contextisfalse. Decide whether that's intentional (keeps binding for a later toggle) or should be cleared; document it either way.
3. Prompt / tool-description consistency
- The condensed system prompt drops guidance for
model_params_setting,tools_location, andenable_context. The model now has no instruction on those fields beyond the schema descriptions — acceptable, but fortools_location("customize" vs "reference") andmodel_params_settingthe schema text is terse; consider keeping a one-line hint or the model will guess. - The prompt references
get_field_options, and theupdatedescription promises auto-validation — make sureget_field_optionsis actually registered in this agent'stoolsarray (the diff only showsupdate). If it isn't, the model will call a non-existent tool. enable_exceptionis added to the schema and to theupdatedescription, but the system prompt never mentions exception handling. Minor, but worth a clause so the model knows when to enable it.
4. Optimization suggestions
- Replace the ad-hoc boolean/normalization logic with small helpers, e.g.
pickBoolean(args.x, fallback)andtoContextRef(materialRefs). - Build a single
patchobject and write once, so you can omit keys you don't intend to change (context_variable,model_params_setting) instead of always writing defaults — reduces accidental overwrites and diff noise. - Add a
console.warn/telemetry whenmaterialRefs.length > 1and only the first is used, so the truncation is observable. - For
enable_exception, prefer reading the same source you write to, and add a unit test assertingupdate({prompt})does not mutateenableExceptionorcontext_variable. - Add tests for the four cases: (i) materials bound + no
enable_contextarg → on; (ii) materials unbound +enable_context: true→ error; (iii) legacy node withenable_context: true, no materials, unrelated update → should succeed; (iv) multiple materials → defined behavior (error or all stored). - Error message could include the concrete remedy ("bind
materialsor passenable_context: false") — it partially does; make it explicit thatfalseis allowed.
fix: context button for an LLM node cannot be interacted with within an agent workflow