buildPrompt method

String buildPrompt({
  1. required AgentRunRequest request,
  2. required int turn,
  3. String? context,
})

Builds the prompt for request and turn.

Visible for testing.

Implementation

String buildPrompt({
  required AgentRunRequest request,
  required int turn,
  String? context,
}) {
  final attempt = request.attempt;
  final attemptLine = attempt == null
      ? 'First attempt (turn $turn of ${request.maxTurns}).'
      : 'Attempt #$attempt, turn $turn of ${request.maxTurns}.';

  final buffer = StringBuffer();
  if (context != null && context.trim().isNotEmpty) {
    buffer
      ..writeln(context)
      ..writeln();
  }
  buffer
    ..writeln('=== ATTEMPT METADATA ===')
    ..writeln(attemptLine)
    ..writeln('Workspace: ${request.workspace.path}')
    ..writeln('Branch: ${request.workspace.branchName}')
    ..writeln()
    ..writeln('=== ISSUE ===')
    ..writeln('Identifier: ${request.issue.identifier}')
    ..writeln('Title: ${request.issue.title}')
    ..writeln('State: ${request.issue.state}')
    ..writeln('Labels: ${request.issue.labels.join(', ')}')
    ..writeln()
    ..writeln('=== PROMPT TEMPLATE ===')
    ..writeln(request.renderedPrompt)
    ..writeln()
    ..writeln('=== INSTRUCTIONS ===')
    ..writeln(
      'Return the full content of each file you change wrapped in '
      '<file_content path="path/to/file"> XML tags. Paths must be relative '
      'to the workspace root. Do not include any prose outside of those '
      'tags.',
    );
  return buffer.toString();
}