({ shouldResetContext }: { shouldResetContext: boolean })
| 123 | await this.pullLatestApi() |
| 124 | |
| 125 | const executeRequest = async ({ shouldResetContext }: { shouldResetContext: boolean }) => { |
| 126 | let conversationHistory = |
| 127 | apiConversationHistory ?? |
| 128 | (await provider.koduDev?.getStateManager().apiHistoryManager.getSavedApiConversationHistory()) |
| 129 | |
| 130 | let baseSystem = [await this.getCurrentPrompts()] |
| 131 | if (customSystemPrompt?.systemPrompt) { |
| 132 | if (Array.isArray(customSystemPrompt.systemPrompt)) { |
| 133 | baseSystem = customSystemPrompt.systemPrompt |
| 134 | } else { |
| 135 | baseSystem = [customSystemPrompt.systemPrompt] |
| 136 | } |
| 137 | } |
| 138 | if (this.getModelId() === "claude-3-7-sonnet-20250219") { |
| 139 | const globalStateManager = GlobalStateManager.getInstance() |
| 140 | const thinking = globalStateManager.getGlobalState("thinking") |
| 141 | // we are going to add more critical instructions to the system prompt |
| 142 | if (thinking?.type === "enabled") { |
| 143 | baseSystem.push(`<critical_instructions> |
| 144 | In every message output you should document your current step, finalized reasoning and thoughts, your next steps, and any other relevant information. |
| 145 | This must be present in every message and should be concise and to the point. |
| 146 | You don't need to write <thinking> tags. instead you should write <thinking_summary> and <execution_plan> tags in every message. |
| 147 | so format every response as following: |
| 148 | <thinking_summary> |
| 149 | A summary of your current thoughts, reasoning, and next steps. |
| 150 | </thinking_summary> |
| 151 | <execution_plan> |
| 152 | Your plan of execution, what you are going to do next, and how you are going to do it. |
| 153 | </execution_plan> |
| 154 | <kodu_action>...the best tool call for this step...</kodu_action> |
| 155 | </critical_instructions>`) |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | let criticalMsg: string | undefined = mainPrompts.criticalMsg |
| 160 | if (customSystemPrompt) { |
| 161 | criticalMsg = customSystemPrompt.automaticReminders |
| 162 | } |
| 163 | // we want to replace {{task}} with the current task if it exists in the critical message |
| 164 | if (criticalMsg) { |
| 165 | const firstRequest = conversationHistory.at(0)?.content |
| 166 | const firstRequestTextBlock = Array.isArray(firstRequest) |
| 167 | ? firstRequest.find(isTextBlock)?.text |
| 168 | : firstRequest |
| 169 | if (firstRequestTextBlock && criticalMsg.includes("{{task}}")) { |
| 170 | criticalMsg = criticalMsg.replace("{{task}}", this.getTaskText(firstRequestTextBlock)) |
| 171 | } |
| 172 | } |
| 173 | if (shouldResetContext) { |
| 174 | // Compress the context and retry |
| 175 | const result = await manageContextWindow(provider.koduDev!, this.api, (s, msg, ...args) => |
| 176 | this.log(s, msg, ...args) |
| 177 | ) |
| 178 | if (result === "chat_finished") { |
| 179 | throw new KoduError({ code: 413 }) |
| 180 | } |
| 181 | } |
| 182 | // Process conversation history using our external utility |
nothing calls this directly
no test coverage detected