Conditionals
Many workflows include branches where the execution path depends on runtime results. GWE supports this through trigger-when conditions, boolean expressions evaluated at runtime that determine whether an agent executes or is skipped.
Trigger-When Conditions
A trigger-when condition is a boolean expression attached to an agent instance. It can only reference values that are enumerations:
- Outputs of previous agent instances that are enumerations.
- Workflow inputs that are enumerations.
If the condition evaluates to true, the agent executes normally. If false, the agent is skipped.
Example: Classification Branch
Trigger --> CLASSIFY --> [trigger-when Class1] B --> C --> D
\-> [trigger-when Class2] E --> F
If CLASSIFY produces Class1, then B, C, and D run while E and F are skipped. If it produces Class2, then E and F run while B, C, and D are skipped.
Skip Propagation
When an agent is skipped, any downstream agent that depends on its output is also skipped, or all of its inputs from the skipped agent are optional.
This allows a single branch point to control long chains without redundant configuration.
Precedence Rules
The engine evaluates skip logic in the following order of precedence for each agent instance:
- Explicit trigger-when false: If the agent has a trigger-when condition that evaluates to false, it is skipped.
- Missing required inputs: If any of the agent's required inputs come from agents that were skipped, the agent is also skipped.
- All inputs skipped: If all of the agent's inputs come from skipped agents and all are optional, the agent still runs. The exception is when the inputs are part of a Named Inputs group that is marked as required. See below.
Conditionals with Multi-Bindings
When an array input is bound to multiple upstream agents via a multi-binding, the conditional rules are:
- Each element of a multi-binding is always optional. If an upstream agent was skipped, that element is removed from the array.
- If all elements were skipped, the entire multi-binding is treated as skipped and the agent does not run. The exception is when the multi-binding input is marked optional on the agent. In that case, the agent still runs with an empty array.
Example: Reducer Pattern
Trigger --> CLASSIFY --> [trigger-when Class1] B --> C --\
+--> [multi] D
\-> [trigger-when Class2] X --> Y --/
D receives outputs from both C and Y as elements of an array. If CLASSIFY produces Class1, then C runs and Y is skipped. D receives an array with one element (from C). If neither branch runs, D's required multi-binding has zero elements, and D is skipped.
Conditionals with Named Inputs
Named Inputs groups interact with conditionals as follows:
- Each named binding can be independently marked as optional by the workflow builder.
- If all named bindings in a group are optional and none have values at runtime:
- If the Named Inputs group is optional per the agent definition, the agent can run without them.
- If the Named Inputs group is required, the agent cannot run (at least one element must be present).
- A named binding marked as non-optional within an optional group is still considered required.
Example: Named Inputs with Branches
Trigger --> CLASSIFY --> [trigger-when Class1] B --> C ---->[opt named] D --> E --> F
\-> [trigger-when Class2] X --> Y --->[opt named]-^
If the Named Inputs group on D is required, D runs only when at least one of C or Y produces a value. If neither branch provides a value, D is skipped.
Optional Agents Pattern
When an agent has all optional inputs, it runs even if all upstream agents were skipped. This can be useful in some cases but surprising in others.
Consider:
Trigger --> CLASSIFY --> [trigger-when Class1] B --> C ----->[opt] D --> E --> F
\-> [trigger-when Class2] X --> Y ----->[opt]-^
\-> [trigger-when Class3] S --> T ----->[opt]----> Output
If CLASSIFY produces Class3, then S and T run, but none of B/C or X/Y do. If D has all optional inputs, it would run with no input data, which may not be the intended behavior.
Solutions:
- Use a required multi-binding instead of separate optional inputs. With zero elements, D will not run.
- Use a required Named Inputs group with individually optional named bindings. At least one element must be present.
- Add an explicit trigger-when condition to D. Note that trigger-when currently supports only simple conditions (not OR expressions).
Current Limitations
- Trigger-when conditions currently support only simple boolean expressions. Compound conditions (e.g., "trigger when Class1 OR Class2") are not directly supported. Use multi-bindings or Named Inputs groups as workarounds.
Next: Type System