agentflow4j icon indicating copy to clipboard operation
agentflow4j copied to clipboard

Per-node execution timeout on AgentGraph

Open ahmed-sekka opened this issue 5 months ago • 0 comments

Problem

There is currently no way to cap how long a single node may run. A slow LLM call or a hanging tool can block the graph indefinitely. RetryPolicy handles failures after the fact, but a timeout is needed to bound the wait.

Proposed API

AgentGraph graph = AgentGraph.builder()
    .addNode("analyse", analyst)
    .nodeTimeout("analyse", Duration.ofSeconds(30))  // per-node
    .defaultNodeTimeout(Duration.ofSeconds(15))        // graph-wide fallback
    .build();

When the timeout fires, the node fails with a NodeTimeoutException which the FailureClassifier can classify as TRANSIENT (retry) or PERMANENT (abort).

Acceptance criteria

  • AgentGraph.Builder accepts nodeTimeout(String, Duration) and defaultNodeTimeout(Duration)
  • Timeout fires a NodeTimeoutException extends RuntimeException
  • DefaultFailureClassifier classifies NodeTimeoutException as TRANSIENT
  • onNodeError listener fires with the timeout exception
  • Unit test: node that sleeps beyond its timeout is aborted and classified correctly

ahmed-sekka avatar Jun 08 '26 07:06 ahmed-sekka