step method

  1. @override
Future<void> step()
override

Executes a single step of the agent's main logic.

This method is called repeatedly by the orchestrator and should:

  • Check for work to do
  • Perform any necessary actions
  • Update status appropriately

Implementations should be idempotent and handle their own errors.

Implementation

@override
Future<void> step() async {
  updateStatus(AgentStatus.working);

  final allAgents = orchestrator.getAllAgents();
  final now = DateTime.now();

  for (final agent in allAgents) {
    if (agent.id == id) continue; // Don't witness yourself

    if (agent.status == AgentStatus.working) {
      final inactiveDuration = now.difference(agent.lastActivity);
      if (inactiveDuration > timeoutThreshold) {
        logger.warn(
          '[Witness $id] Agent ${agent.id} seems stuck (inactive for ${inactiveDuration.inMinutes}m).',
        );
        agent.updateStatus(AgentStatus.stuck);
      }
    }
  }

  updateStatus(AgentStatus.idle);
}