MCPcopy Index your code
hub / github.com/coder/coder / buildSystemPrompt

Function buildSystemPrompt

coderd/x/chatd/chatd.go:6725–6761  ·  view source on GitHub ↗

buildSystemPrompt applies system-level prompt injections in the canonical order. It is used by both the initial prompt assembly and the ReloadMessages callback to keep them in sync.

(
	prompt []fantasy.Message,
	subagentInstruction string,
	instruction string,
	resolvedSkills []skillspkg.ResolvedSkill,
	userPrompt string,
	behaviorContext systemPromptBehaviorContext,
)

Source from the content-addressed store, hash-verified

6723// canonical order. It is used by both the initial prompt assembly
6724// and the ReloadMessages callback to keep them in sync.
6725func buildSystemPrompt(
6726 prompt []fantasy.Message,
6727 subagentInstruction string,
6728 instruction string,
6729 resolvedSkills []skillspkg.ResolvedSkill,
6730 userPrompt string,
6731 behaviorContext systemPromptBehaviorContext,
6732) []fantasy.Message {
6733 if subagentInstruction != "" {
6734 prompt = chatprompt.InsertSystem(prompt, subagentInstruction)
6735 }
6736 if instruction != "" {
6737 prompt = chatprompt.InsertSystem(prompt, instruction)
6738 }
6739 if skillIndex := chattool.FormatResolvedSkillIndex(resolvedSkills); skillIndex != "" {
6740 prompt = chatprompt.InsertSystem(prompt, skillIndex)
6741 }
6742 if userPrompt != "" {
6743 prompt = chatprompt.InsertSystem(prompt, userPrompt)
6744 }
6745 if isExploreSubagentMode(behaviorContext.chatMode) {
6746 prompt = chatprompt.InsertSystem(prompt, ExploreSubagentOverlayPrompt)
6747 return prompt
6748 }
6749 isPlanModeTurn := behaviorContext.planMode.Valid && behaviorContext.planMode.ChatPlanMode == database.ChatPlanModePlan
6750 if isPlanModeTurn {
6751 if behaviorContext.isRootChat {
6752 prompt = chatprompt.InsertSystem(prompt, PlanningOverlayPrompt())
6753 if behaviorContext.planModeInstructions != "" {
6754 prompt = chatprompt.InsertSystem(prompt, behaviorContext.planModeInstructions)
6755 }
6756 } else {
6757 prompt = chatprompt.InsertSystem(prompt, PlanningSubagentOverlayPrompt)
6758 }
6759 }
6760 return prompt
6761}
6762
6763func removeSkillIndexMessages(prompt []fantasy.Message) []fantasy.Message {
6764 out := make([]fantasy.Message, 0, len(prompt))

Calls 4

InsertSystemFunction · 0.92
FormatResolvedSkillIndexFunction · 0.92
isExploreSubagentModeFunction · 0.85
PlanningOverlayPromptFunction · 0.85