continueRun method

Future<void> continueRun()

Continue from the current transcript. The last message must be a user or tool-result message, unless queued steering/follow-up messages can start a fresh prompt run (pi's continue()).

Implementation

Future<void> continueRun() async {
  if (_activeRun != null) {
    throw StateError(
      'Agent is already processing. Wait for completion before continuing.',
    );
  }

  final messages = _state._messages;
  if (messages.isEmpty) {
    throw StateError('No messages to continue from');
  }

  if (messages.last.role == 'assistant') {
    final queuedSteering = _steeringQueue.drain();
    if (queuedSteering.isNotEmpty) {
      await _runPromptMessages(queuedSteering, skipInitialSteeringPoll: true);
      return;
    }

    final queuedFollowUps = _followUpQueue.drain();
    if (queuedFollowUps.isNotEmpty) {
      await _runPromptMessages(queuedFollowUps);
      return;
    }

    throw StateError('Cannot continue from message role: assistant');
  }

  await _runContinuation();
}