agentflow4j icon indicating copy to clipboard operation
agentflow4j copied to clipboard

AgentListener: add onCheckpoint and onApprovalRequest lifecycle events

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

Problem

AgentListener currently covers node enter/exit/error and graph complete. Two production-critical events are missing:

  • onCheckpoint(String graphName, String nodeName, AgentContext context) — fired each time the runtime persists a checkpoint. Useful for audit logging and observability.
  • onApprovalRequest(String graphName, String nodeName, ApprovalRequest request) — fired when an ApprovalGate pauses execution. Needed to trigger downstream notifications (Slack, email, webhook) without coupling gate logic to notification code.

Current state

public interface AgentListener {
    default void onNodeEnter(...) {}
    default void onNodeExit(...) {}
    default void onNodeError(...) {}
    default void onTransition(...) {}
    default void onGraphComplete(...) {}
}

No hook for checkpoint or approval events.

Proposed addition

default void onCheckpoint(String graphName, String nodeName, AgentContext context) {}
default void onApprovalRequest(String graphName, String nodeName, ApprovalRequest request) {}

Acceptance criteria

  • Both methods have default no-op implementations (non-breaking)
  • MicrometerAgentListener records a checkpoint counter metric
  • At least one test verifies the hooks fire at the right moment
  • Javadoc explains when each fires and what the parameters contain

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