Skip to content

Commit 386d129

Browse files
committed
Add prompting about edits from users
1 parent 828fbfd commit 386d129

File tree

2 files changed

+41
-18
lines changed

2 files changed

+41
-18
lines changed

backend/src/main-prompt.ts

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -129,22 +129,26 @@ export const mainPrompt = async (
129129
costMode,
130130
allMessagesTokens
131131
)
132-
const { addedFiles, readFilesMessage, clearReadFileToolResults } =
133-
await getFileVersionUpdates(
134-
ws,
135-
messagesWithUserMessage,
136-
searchSystem,
137-
fileContext,
138-
null,
139-
{
140-
skipRequestingFiles: !prompt,
141-
clientSessionId,
142-
fingerprintId,
143-
userInputId: promptId,
144-
userId,
145-
costMode,
146-
}
147-
)
132+
const {
133+
addedFiles,
134+
readFilesMessage,
135+
clearReadFileToolResults,
136+
updatedFilePaths,
137+
} = await getFileVersionUpdates(
138+
ws,
139+
messagesWithUserMessage,
140+
searchSystem,
141+
fileContext,
142+
null,
143+
{
144+
skipRequestingFiles: !prompt,
145+
clientSessionId,
146+
fingerprintId,
147+
userInputId: promptId,
148+
userId,
149+
costMode,
150+
}
151+
)
148152

149153
if (clearReadFileToolResults) {
150154
for (const message of messagesWithUserMessage) {
@@ -159,10 +163,19 @@ export const mainPrompt = async (
159163
}
160164

161165
if (addedFiles.length > 0) {
166+
const [updatedFiles, newFiles] = partition(addedFiles, (f) =>
167+
updatedFilePaths.includes(f.path)
168+
)
169+
const hasUpdatedFiles = updatedFiles.length > 0
162170
const readFilesToolResult = {
163171
id: generateCompactId(),
164172
name: 'read_files',
165-
result: renderReadFilesResult(addedFiles),
173+
result:
174+
renderReadFilesResult(newFiles) +
175+
(hasUpdatedFiles
176+
? `\nThe following files had modifications made by you or the user. Try to accommodate these changes going forward:\n`
177+
: '') +
178+
renderReadFilesResult(updatedFiles),
166179
}
167180
messagesWithUserMessage.push({
168181
role: 'assistant' as const,
@@ -722,6 +735,7 @@ async function getFileVersionUpdates(
722735
addedFiles: newFiles,
723736
existingNewFilePaths,
724737
nonExistingNewFilePaths,
738+
updatedFilePaths: updatedFiles,
725739
readFilesMessage,
726740
clearReadFileToolResults: true,
727741
}
@@ -740,6 +754,7 @@ async function getFileVersionUpdates(
740754
addedFiles,
741755
existingNewFilePaths,
742756
nonExistingNewFilePaths,
757+
updatedFilePaths: updatedFiles,
743758
readFilesMessage,
744759
clearReadFileToolResults: false,
745760
}

backend/src/system-prompt/agent-instructions.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@ Use the tools to work toward accomplishing the user request, and do not forget t
1010

1111
# Files
1212

13-
The <files> tag shows files you have previously created or read from previous iterations. Multiple copies of the same file may be included — each represents a distinct version arranged in chronological order. Pay particular attention to the last copy of a file as that one is current.
13+
The <read_file> tool result shows files you have previously read from <read_files> tool calls.
14+
15+
If you write to a file, or if the user modifies a file, new copies of a file will be included in <read_file> tool results.
16+
17+
Thus, multiple copies of the same file may be included over the course of a conversation. Each represents a distinct version in chronological order.
18+
19+
Important:
20+
- Pay particular attention to the last copy of a file as that one is current!
21+
- You are not the only one making changes to files. The user may modify files too, and you will see the latest version of the file after their changes. You must base you future write_file edits off of the latest changes. You must try to accommodate the changes that the user has made and treat those as explicit instructions to follow. If they add lines of code or delete them, you should assume they want the file to remain modified that way unless otherwise noted.
1422

1523
# Subgoals
1624

0 commit comments

Comments
 (0)