subscribe method

void Function() subscribe(
  1. AgentListener listener
)

Subscribe to agent lifecycle events. Returns an unsubscribe function.

Listener futures are awaited in subscription order and included in the current run's settlement. agent_end is the final loop event for a run; agent_settled follows once the run and all queued follow-ups are fully idle, and the agent does not become idle until all awaited listeners for those events have settled (pi semantics).

Implementation

void Function() subscribe(AgentListener listener) {
  _listeners.add(listener);
  return () => _listeners.remove(listener);
}