buildSystemPromptWithContext function

String buildSystemPromptWithContext({
  1. required String basePrompt,
  2. String? memoryContent,
  3. String? projectInfo,
  4. List<String>? activeTools,
  5. bool planMode = false,
})

Build a system prompt with context.

Implementation

String buildSystemPromptWithContext({
  required String basePrompt,
  String? memoryContent,
  String? projectInfo,
  List<String>? activeTools,
  bool planMode = false,
}) {
  final buffer = StringBuffer(basePrompt);

  if (memoryContent != null && memoryContent.isNotEmpty) {
    buffer.writeln('\n\n<memory>\n$memoryContent\n</memory>');
  }

  if (projectInfo != null && projectInfo.isNotEmpty) {
    buffer.writeln('\n\n<project_info>\n$projectInfo\n</project_info>');
  }

  if (activeTools != null && activeTools.isNotEmpty) {
    buffer.writeln('\n\nAvailable tools: ${activeTools.join(", ")}');
  }

  if (planMode) {
    buffer.writeln(
      '\n\nYou are currently in PLAN MODE. '
      'Analyze the request and create a detailed plan. '
      'Do not execute any changes yet — only plan.',
    );
  }

  return buffer.toString();
}