Skip to content

Commit 1654548

Browse files
committed
Add support for additional search instructions in agentic search and update prompt headers
- In `build_agent_prompt` (`apps/editor/src/features/agentic-search/utils/build-agent-prompt.ts`), move the completed tasks block inside the `# Query` section after the query text and change its heading from `# Completed tasks` to `## Completed tasks`. - when agentic search is run from prompt view, instructions used for query should have heading '## Task instructions', optional additional instructions heading '## Search instructions' - In agentic search, rename the "## Task instructions" heading to "## Instructions" and "## Past task instructions" to "## Past instructions", and pass the additional search instructions separately to `build_agent_prompt` (preserving symbol replacement) so the "## Search instructions" section is rendered after "## Past instructions". └── apps └── editor └── src ├── commands │ └── agentic-search-command │ └── agentic-search-command.ts ├── extension.ts ├── features │ └── agentic-search │ ├── agentic-search-state.ts │ ├── agentic-search.ts │ ├── index.ts │ └── utils │ ├── build-agent-prompt.ts │ ├── index.ts │ ├── prompt-for-additional-instructions.ts │ └── prompt-for-search-term.ts └── views └── prompt └── backend ├── message-handlers │ └── handle-agentic-search.ts └── prompt-view-provider.ts
1 parent e930a10 commit 1654548

3 files changed

Lines changed: 33 additions & 15 deletions

File tree

‎apps/editor/src/features/agentic-search/agentic-search.ts‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export const agentic_search = async (params: {
9393
build_prompt: async () => {
9494
while (true) {
9595
let current_query = query
96+
let additional_instructions = ''
9697

9798
if (
9899
first_run &&
@@ -125,9 +126,9 @@ export const agentic_search = async (params: {
125126

126127
first_run = false
127128

128-
if (additional_instructions_result.value.trim() !== '') {
129-
current_query = `${query}\n\nAdditional instructions:\n${additional_instructions_result.value}`
130-
}
129+
current_query = `## Instructions\n\n${query.trim()}`
130+
additional_instructions =
131+
additional_instructions_result.value.trim()
131132
} else {
132133
const query_result = await prompt_for_search_term(query, {
133134
show_back_button: true,
@@ -165,11 +166,14 @@ export const agentic_search = async (params: {
165166
LAST_AGENTIC_SEARCH_QUERY_STATE_KEY,
166167
{
167168
instructions: params.current_instructions,
168-
query: current_query
169+
query
169170
}
170171
)
171172

172-
const instructions_to_process = [current_query]
173+
const instructions_to_process = [
174+
current_query,
175+
additional_instructions
176+
]
173177
if (params.completed_tasks) {
174178
instructions_to_process.push(...params.completed_tasks)
175179
}
@@ -183,7 +187,8 @@ export const agentic_search = async (params: {
183187
})
184188

185189
const processed_query = processed_queries[0]
186-
const processed_completed_tasks = processed_queries.slice(1)
190+
const processed_additional_instructions = processed_queries[1]
191+
const processed_completed_tasks = processed_queries.slice(2)
187192

188193
const final_query = skill_definitions
189194
? `${processed_query}\n\n${skill_definitions}`
@@ -201,7 +206,11 @@ export const agentic_search = async (params: {
201206
params.workspace_provider
202207
)
203208

204-
return build_agent_prompt(final_query, processed_completed_tasks)
209+
return build_agent_prompt(
210+
final_query,
211+
processed_completed_tasks,
212+
processed_additional_instructions
213+
)
205214
}
206215
}
207216
})

‎apps/editor/src/features/agentic-search/utils/build-agent-prompt.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { ai_file_search_format_instructions } from '@/constants/instructions'
33

44
export const build_agent_prompt = (
55
query: string,
6-
completed_tasks?: string[]
6+
completed_tasks?: string[],
7+
search_instructions?: string
78
) => {
89
const config = vscode.workspace.getConfiguration('codeWebChat')
910
const task_instructions =
@@ -13,12 +14,16 @@ export const build_agent_prompt = (
1314

1415
let prompt = `# Task\n\n${task_instructions}\n\n# Output formatting\n\n${ai_file_search_format_instructions}`
1516

17+
prompt += `\n\n# Query\n\n${query}`
18+
1619
if (completed_tasks && completed_tasks.length > 0) {
1720
const tasks_str = completed_tasks.map((t) => `- [x] ${t}`).join('\n')
18-
prompt += `\n\n# Completed tasks\n\n${tasks_str}`
21+
prompt += `\n\n## Past instructions\n\n${tasks_str}`
1922
}
2023

21-
prompt += `\n\n# Query\n\n${query}`
24+
if (search_instructions && search_instructions.trim() !== '') {
25+
prompt += `\n\n## Search instructions\n\n${search_instructions.trim()}`
26+
}
2227

2328
return prompt
2429
}

‎apps/editor/src/utils/prompt-builder.ts‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export namespace PromptBuilder {
9797
const tasks_str = params.completed_tasks
9898
.map((t) => `- [x] ${t}`)
9999
.join('\n')
100-
top_sys += `# Completed tasks\n\n${tasks_str}\n\n`
100+
top_sys += `# Past task instructions\n\n${tasks_str}\n\n`
101101
}
102102
}
103103

@@ -122,10 +122,14 @@ export namespace PromptBuilder {
122122
)
123123
if (has_files) {
124124
if (params.files_context_part1) {
125-
part1 = (top_sys ? top_sys : '') + `# Files\n\n${params.files_context_part1}`
125+
part1 =
126+
(top_sys ? top_sys : '') +
127+
`# Files\n\n${params.files_context_part1}`
126128
part2 += `${params.files_context_part2 || ''}${active_file_context}`
127129
} else {
128-
part2 += (top_sys ? top_sys : '') + `# Files\n\n${params.files_context_part2 || ''}${active_file_context}`
130+
part2 +=
131+
(top_sys ? top_sys : '') +
132+
`# Files\n\n${params.files_context_part2 || ''}${active_file_context}`
129133
}
130134
full_prompt = part1 + part2
131135
} else {
@@ -160,8 +164,8 @@ export namespace PromptBuilder {
160164
const tasks_str = params.completed_tasks
161165
.map((t) => `- [x] ${t}`)
162166
.join('\n')
163-
part2 += `# Completed tasks\n\n${tasks_str}\n\n`
164-
full_prompt += `# Completed tasks\n\n${tasks_str}\n\n`
167+
part2 += `# Past task instructions\n\n${tasks_str}\n\n`
168+
full_prompt += `# Past task instructions\n\n${tasks_str}\n\n`
165169
}
166170

167171
if (part1.length > 0 || part2.length > 0 || full_prompt.length > 0) {

0 commit comments

Comments
 (0)