@@ -28,26 +28,61 @@ var defaultRetryConfig = RetryConfig{
2828 },
2929}
3030
31+ // DefaultRetryConfig returns a copy of the default retry policy
32+ // (5 attempts, 1s initial delay, 60s cap, 2x backoff, full jitter,
33+ // retry every error). Override fields on the returned value to
34+ // customise:
35+ //
36+ // rc := workflow.DefaultRetryConfig()
37+ // rc.MaxAttempts = 10
38+ // cfg := workflow.NodeConfig{RetryConfig: rc}
3139func DefaultRetryConfig () * RetryConfig {
3240 cfg := defaultRetryConfig
3341 return & cfg
3442}
3543
3644// NodeConfig defines the configuration for a node.
45+ //
46+ // All fields are optional. The pointer-typed fields (RerunOnResume,
47+ // WaitForOutput) are tri-state: nil means "use the engine default for
48+ // this node kind", which mirrors Python's per-node-type defaults
49+ // (e.g. AgentNode in task mode defaults WaitForOutput to true while
50+ // other nodes default to false). Use the *Or accessor helpers to
51+ // read these values with an explicit per-call-site default.
3752type NodeConfig struct {
38- // Enables data parallelism (runs node concurrently for each item in input collection)
53+ // ParallelWorker, when true, runs the node concurrently for each
54+ // item of a list-typed input. The engine collects per-item
55+ // outputs and emits a single aggregate output event.
3956 ParallelWorker bool
40- // Re-runs node on resume. Defaults to true for AgentNode
57+
58+ // RerunOnResume controls human-in-the-loop resume behaviour. When
59+ // true, an interrupted node re-runs from scratch on resume; when
60+ // false, the resume payload is treated as the node's output.
61+ // nil means "use the engine default", which is true for AgentNode
62+ // and false elsewhere.
4163 RerunOnResume * bool
42- // Wait for output before triggering edges. Defaults to true for Task agents
64+
65+ // WaitForOutput, when true, keeps the node in NodeWaiting
66+ // (re-triggerable) until it actually yields an event carrying an
67+ // "output" key in Actions.StateDelta, instead of moving it to
68+ // NodeCompleted on first return. JoinNode and any custom fan-in
69+ // node sets this. nil means "use the engine default" — false for
70+ // most node kinds.
4371 WaitForOutput * bool
44- // Retry configuration on failure
72+
73+ // RetryConfig, when non-nil, makes the scheduler retry this node
74+ // on failure per the policy. nil means "no retries".
4575 RetryConfig * RetryConfig
46- // Max duration for node to complete. Optional for global defaults
47- Timeout * time.Duration
76+
77+ // Timeout, when > 0, bounds a single activation of the node via
78+ // context.WithTimeout on the per-node context. Zero (the default)
79+ // means the node is bounded only by the parent invocation
80+ // context's deadline, if any.
81+ Timeout time.Duration
4882}
4983
5084// RetryConfig defines the parameters for retrying a failed node.
85+ //
5186// Recommended construction is via DefaultRetryConfig and override
5287// the fields you want to customize:
5388//
@@ -59,17 +94,30 @@ type NodeConfig struct {
5994// but discouraged: any unset field defaults to its zero value, not
6095// to DefaultRetryConfig's value. The zero RetryConfig is a valid
6196// "no retry, no backoff, no jitter" policy.
97+ //
98+ // The struct shape is deliberately a flat set of plain values: no
99+ // dependency on cenkalti/backoff/v5.
62100type RetryConfig struct {
63101 // Maximum number of attempts, including the original request. If 0 or 1, it means no retries. If not specified, default to 5.
64102 MaxAttempts int
103+
65104 // Initial delay before the first retry, in fractions of a second. If not specified, default to 1 second.
66105 InitialDelay time.Duration
106+
67107 // Maximum delay between retries, in fractions of a second. If not specified, default to 60 seconds.
68108 MaxDelay time.Duration
69- // Multiplier by which the delay increases after each attempt. If not specified, default to 2.0.
109+
110+ // BackoffFactor is the per-attempt multiplier applied to the
111+ // delay. A factor of 1.0 means a constant InitialDelay between
112+ // retries; 2.0 means classic exponential backoff. Values < 1.0
113+ // shrink the delay each attempt (rare but permitted).
70114 BackoffFactor float64
71- // Randomness factor for the delay. Use 0.0 to remove randomness. If not specified, default to 1.0.
115+
116+ // Jitter is a randomness factor in [0.0, 1.0]. The actual delay
117+ // is sampled from delay * (1 ± Jitter). Zero means deterministic
118+ // delays.
72119 Jitter float64
120+
73121 // Predicate that defines when to retry (true means retry). If not specified, default to true.
74122 ShouldRetry func (error ) bool
75123}
0 commit comments