You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: backend/src/thinking-stream.ts
+44-7Lines changed: 44 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,9 @@
1
-
import{CostMode}from'common/constants'
1
+
import{CostMode,models}from'common/constants'
2
2
3
3
import{CoreMessage}from'ai'
4
4
import{getAgentStream}from'./prompt-agent-stream'
5
-
import{TOOL_LIST}from'./tools'
6
5
import{logger}from'./util/logger'
6
+
import{TOOL_LIST}from'./tools'
7
7
8
8
exportasyncfunctiongetThinkingStream(
9
9
messages: CoreMessage[],
@@ -16,13 +16,14 @@ export async function getThinkingStream(
16
16
userId: string|undefined
17
17
}
18
18
){
19
-
const{ getStream }=getAgentStream({
19
+
const{ getStream, model}=getAgentStream({
20
20
costMode: options.costMode,
21
21
selectedModel: 'gemini-2.5-pro',
22
22
stopSequences: [
23
23
'</think_deeply>',
24
24
'<think_deeply>',
25
25
'<read_files>',
26
+
'<write_file>',
26
27
'<end_turn>',
27
28
],
28
29
clientSessionId: options.clientSessionId,
@@ -31,7 +32,31 @@ export async function getThinkingStream(
31
32
userId: options.userId,
32
33
})
33
34
34
-
constthinkingPrompt=`You are an expert programmer. Think deeply about the user request in the message history and how to best approach it. Consider edge cases, potential issues, and alternative approaches. Only think - do not take any actions or make any changes.
35
+
constisO3=model===models.o3pro||model===models.o3
36
+
constthinkingPrompt=isO3
37
+
? `You are an expert programmer. Think deeply about the user request in the message history and how to best approach it. Consider edge cases, potential issues, and alternative approaches.
38
+
39
+
When the next action is clear, you can stop your thinking immediately. For example:
40
+
- If you realize you need to read files, say what files you should read next, and then end your thinking.
41
+
- If you realize you completed the user request, say it is time to end your response and end your thinking.
42
+
- If you already did thinking previously that outlines a plan you are continuing to implement, you can stop your thinking immediately and continue following the plan.
43
+
44
+
Guidelines:
45
+
- Respond with your analysis or plan inside a think_deeply tool call.
46
+
- Explain clearly and concisely what would be helpful for a junior engineer to know to handle the user request.
47
+
- Show key snippets of code to guide the implementation to be as clean as possible.
48
+
- Figure out the solution to any errors or bugs and give instructions on how to fix them.
49
+
- DO NOT use any tools! You are only thinking, not taking any actions. You should refer to tool calls without angle brackets when talking about them: "I should use the read_files tool" and NOT "I should use <read_files>"
50
+
- Make sure to end your response with "</thought>\n</think_deeply> and don't write anything after that."
51
+
52
+
Example:
53
+
<think_deeply>
54
+
<thought>
55
+
The next step is to read src/foo.ts and src/bar.ts
56
+
</thought>
57
+
</think_deeply>
58
+
`.trim()
59
+
: `You are an expert programmer. Think deeply about the user request in the message history and how to best approach it. Consider edge cases, potential issues, and alternative approaches. Only think - do not take any actions or make any changes.
35
60
36
61
The user cannot see anything you write, this is thinking that will be used to generate the response in the next step.
37
62
@@ -67,8 +92,18 @@ Important: Keep your thinking as short as possible! Just a few words suffices. E
67
92
onChunk(thinkDeeplyPrefix)
68
93
69
94
letwasTruncated=false
70
-
forawait(constchunkofstream){
95
+
letprefix=''
96
+
forawait(letchunkofstream){
97
+
// Remove a prefix of the the think deeply tool call if it exists.
98
+
prefix+=chunk
71
99
response+=chunk
100
+
if(thinkDeeplyPrefix.startsWith(prefix)){
101
+
continue
102
+
}
103
+
if(response.startsWith(thinkDeeplyPrefix)){
104
+
response=response.slice(thinkDeeplyPrefix.length)
105
+
chunk=chunk.slice(chunk.length-response.length)
106
+
}
72
107
73
108
// Check for any complete tool tag
74
109
for(consttoolofTOOL_LIST){
@@ -94,8 +129,10 @@ Important: Keep your thinking as short as possible! Just a few words suffices. E
0 commit comments