Skip to content

Commit 54ff07f

Browse files
authored
Merge pull request #274 from cloudflare/feat/prompt-optimizations
Feat: Prompt optimizations and Gemini 3 flash
2 parents 8927bf0 + a269586 commit 54ff07f

File tree

12 files changed

+312
-583
lines changed

12 files changed

+312
-583
lines changed

src/routes/chat/chat.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,10 @@ export default function Chat() {
482482
hasSeenPreview.current = true;
483483
} else if (previewUrl) {
484484
const isExistingChat = urlChatId !== 'new';
485-
const shouldSwitch = behaviorType === 'agentic' || isPhase1Complete || isExistingChat;
485+
const shouldSwitch =
486+
behaviorType === 'agentic' ||
487+
(behaviorType === 'phasic' && isPhase1Complete) ||
488+
(isExistingChat && behaviorType !== 'phasic');
486489

487490
if (shouldSwitch) {
488491
setView('preview');

worker/agents/core/state.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export enum CurrentDevState {
2727
FINALIZING,
2828
}
2929

30-
export const MAX_PHASES = 12;
30+
export const MAX_PHASES = 10;
3131

3232
/** Common state fields for all agent behaviors */
3333
export interface BaseProjectState {

worker/agents/inferutils/config.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ const COMMON_AGENT_CONFIGS = {
3232
temperature: 0.0,
3333
fallbackModel: AIModels.GEMINI_2_5_PRO,
3434
},
35+
templateSelection: {
36+
name: AIModels.GEMINI_2_5_FLASH_LITE,
37+
max_tokens: 2000,
38+
fallbackModel: AIModels.GROK_4_1_FAST_NON_REASONING,
39+
temperature: 1,
40+
},
3541
} as const;
3642

3743
const SHARED_IMPLEMENTATION_CONFIG = {
@@ -51,12 +57,6 @@ Cloudflare AI Gateway unified billing for seamless model access without managing
5157
*/
5258
const PLATFORM_AGENT_CONFIG: AgentConfig = {
5359
...COMMON_AGENT_CONFIGS,
54-
templateSelection: {
55-
name: AIModels.VERTEX_GPT_OSS_120,
56-
max_tokens: 2000,
57-
fallbackModel: AIModels.GEMINI_2_5_FLASH_LITE,
58-
temperature: 0.6,
59-
},
6060
blueprint: {
6161
name: AIModels.GEMINI_3_PRO_PREVIEW,
6262
reasoning_effort: 'medium',
@@ -72,18 +72,18 @@ const PLATFORM_AGENT_CONFIG: AgentConfig = {
7272
fallbackModel: AIModels.GEMINI_2_5_PRO,
7373
},
7474
phaseGeneration: {
75-
name: AIModels.GROK_4_1_FAST,
75+
name: AIModels.GEMINI_3_FLASH_PREVIEW,
7676
reasoning_effort: 'medium',
7777
max_tokens: 8000,
78-
temperature: 1,
78+
temperature: 0.7,
7979
fallbackModel: AIModels.OPENAI_5_MINI,
8080
},
8181
firstPhaseImplementation: {
82-
name: AIModels.GEMINI_2_5_PRO,
82+
name: AIModels.GEMINI_3_FLASH_PREVIEW,
8383
...SHARED_IMPLEMENTATION_CONFIG,
8484
},
8585
phaseImplementation: {
86-
name: AIModels.GEMINI_2_5_PRO,
86+
name: AIModels.GEMINI_3_FLASH_PREVIEW,
8787
...SHARED_IMPLEMENTATION_CONFIG,
8888
},
8989
conversationalResponse: {
@@ -104,11 +104,11 @@ const PLATFORM_AGENT_CONFIG: AgentConfig = {
104104
name: AIModels.GROK_4_1_FAST_NON_REASONING,
105105
reasoning_effort: 'low',
106106
max_tokens: 16000,
107-
temperature: 0.2,
107+
temperature: 0.0,
108108
fallbackModel: AIModels.GROK_CODE_FAST_1,
109109
},
110110
agenticProjectBuilder: {
111-
name: AIModels.GEMINI_2_5_PRO,
111+
name: AIModels.GEMINI_3_FLASH_PREVIEW,
112112
reasoning_effort: 'medium',
113113
max_tokens: 8000,
114114
temperature: 1,
@@ -129,26 +129,26 @@ const DEFAULT_AGENT_CONFIG: AgentConfig = {
129129
temperature: 0.6,
130130
},
131131
blueprint: {
132-
name: AIModels.GEMINI_2_5_PRO,
132+
name: AIModels.GEMINI_3_PRO_PREVIEW,
133133
reasoning_effort: 'medium',
134134
max_tokens: 64000,
135135
fallbackModel: AIModels.GEMINI_2_5_FLASH,
136-
temperature: 0.7,
136+
temperature: 1,
137137
},
138138
projectSetup: {
139-
name: AIModels.GEMINI_2_5_PRO,
139+
name: AIModels.GEMINI_3_FLASH_PREVIEW,
140140
...SHARED_IMPLEMENTATION_CONFIG,
141141
},
142142
phaseGeneration: {
143-
name: AIModels.GEMINI_2_5_PRO,
143+
name: AIModels.GEMINI_3_FLASH_PREVIEW,
144144
...SHARED_IMPLEMENTATION_CONFIG,
145145
},
146146
firstPhaseImplementation: {
147-
name: AIModels.GEMINI_2_5_PRO,
147+
name: AIModels.GEMINI_3_FLASH_PREVIEW,
148148
...SHARED_IMPLEMENTATION_CONFIG,
149149
},
150150
phaseImplementation: {
151-
name: AIModels.GEMINI_2_5_PRO,
151+
name: AIModels.GEMINI_3_FLASH_PREVIEW,
152152
...SHARED_IMPLEMENTATION_CONFIG,
153153
},
154154
conversationalResponse: {
@@ -159,14 +159,14 @@ const DEFAULT_AGENT_CONFIG: AgentConfig = {
159159
fallbackModel: AIModels.GEMINI_2_5_PRO,
160160
},
161161
deepDebugger: {
162-
name: AIModels.GEMINI_2_5_PRO,
162+
name: AIModels.GEMINI_3_PRO_PREVIEW,
163163
reasoning_effort: 'high',
164164
max_tokens: 8000,
165165
temperature: 0.5,
166166
fallbackModel: AIModels.GEMINI_2_5_FLASH,
167167
},
168168
fileRegeneration: {
169-
name: AIModels.GEMINI_2_5_PRO,
169+
name: AIModels.GEMINI_3_FLASH_PREVIEW,
170170
reasoning_effort: 'low',
171171
max_tokens: 32000,
172172
temperature: 0,

worker/agents/inferutils/config.types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ const MODELS_MASTER = {
101101
contextSize: 1048576,
102102
}
103103
},
104+
GEMINI_3_FLASH_PREVIEW: {
105+
id: 'google-ai-studio/gemini-3-flash-preview',
106+
config: {
107+
name: 'Gemini 3.0 Flash Preview',
108+
size: ModelSize.REGULAR,
109+
provider: 'google-ai-studio',
110+
creditCost: 2, // $0.5
111+
contextSize: 1048576, // 1M Context
112+
}
113+
},
104114

105115
// --- Anthropic Models ---
106116
CLAUDE_3_7_SONNET_20250219: {

worker/agents/operations/PhaseGeneration.ts

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const SYSTEM_PROMPT = `<ROLE>
2525
<TASK>
2626
You are given the blueprint (PRD) and the client query. You will be provided with all previously implemented project phases, the current latest snapshot of the codebase, and any current runtime issues or static analysis reports.
2727
28-
**Your primary task:** Design the next phase of the project as a deployable milestone leading to project completion or to address any user feedbacks or reported bugs (runtime error fixing is the highest priority).
28+
**Your primary task:** Design the next phase of the project as a deployable milestone leading to project completion or to address any user feedbacks or reported bugs (runtime error fixing is the highest priority). Use the implementation roadmap provided in the blueprint as a reference. Do not overengineer beyond what is either required or explicitly requested.
2929
3030
**Phase Planning Process:**
3131
1. **ANALYZE** current codebase state and identify what's implemented vs. what remains
@@ -40,8 +40,12 @@ const SYSTEM_PROMPT = `<ROLE>
4040
4141
Plan the phase name and description appropriately. They don't have to strictly adhere to the blueprint's roadmap as unforeseen issues may occur.
4242
43-
The project needs to be fully ready to ship in a reasonable amount of time. Plan accordingly.
44-
If no more phases are needed, conclude by putting blank fields in the response.
43+
Plan the next phase to advance toward completion. Set lastPhase: true when:
44+
- The blueprint's implementation roadmap is complete
45+
- All core features are working
46+
- No critical runtime errors remain
47+
48+
Do not add phases for polish, optimization, or hypothetical improvements - users can request those via feedback.
4549
Follow the <PHASES GENERATION STRATEGY> as your reference policy for building and delivering projects.
4650
4751
**Configuration File Guidelines:**
@@ -54,6 +58,12 @@ const SYSTEM_PROMPT = `<ROLE>
5458
✅ Icon libraries: lucide-react, heroicons (from dependencies)
5559
❌ Binary files (.png, .jpg, .svg files) cannot be generated in phases
5660
61+
**Preinstalled UI Components:**
62+
- src/components/ui/* files are preinstalled shadcn primitives (Button, Card, Tabs, etc.)
63+
- DO NOT include them in phase file lists - they already exist. Rewriting/modifying them might result in runtime errors.
64+
- Import directly: import { Tabs } from "@/components/ui/tabs"
65+
- If a component is missing, add install command: bunx shadcn@latest add tabs
66+
5767
**REMEMBER: This is not a toy or educational project. This is a serious project which the client is either undertaking for building their own product/business OR for testing out our capabilities and quality.**
5868
</TASK>
5969
@@ -65,10 +75,6 @@ ${PROMPT_UTILS.UI_GUIDELINES}
6575
6676
${PROMPT_UTILS.COMMON_DEP_DOCUMENTATION}
6777
68-
<CLIENT REQUEST>
69-
"{{query}}"
70-
</CLIENT REQUEST>
71-
7278
<BLUEPRINT>
7379
{{blueprint}}
7480
</BLUEPRINT>
@@ -113,7 +119,7 @@ Adhere to the following guidelines:
113119
- You would be provided with the diff of the last phase. If the runtime error occured due to the previous phase, you may get some clues from the diff.
114120
• Thoroughly review all the previous phases and the current implementation snapshot. Verify the frontend elements, UI, and backend components.
115121
- **Understand what has been implemented and what remains** We want a fully finished product eventually! No feature should be left unimplemented if its possible to implement it in the current project environment with purely open source tools and free tier services (i.e, without requiring any third party paid/API key service).
116-
- Each phase should work towards achieving the final product. **ONLY** mark as last phase if you are sure the project is at least >97% finished already.
122+
- Each phase should advance toward the final product. **ONLY** mark as last phase if you are sure the project is at least >97% finished already.
117123
- If a certain feature can't be implemented due to constraints, use mock data or best possible alternative that's still possible.
118124
- Thoroughly review the current codebase and identify and fix any bugs, incomplete features or unimplemented stuff.
119125
• **BEAUTIFUL UI PRIORITY**: Next phase should cover fixes (if any), development, AND significant focus on creating visually stunning, professional-grade UI/UX with:
@@ -131,11 +137,22 @@ Adhere to the following guidelines:
131137
• Use the <PHASES GENERATION STRATEGY> section to guide your phase generation.
132138
• Ensure the next phase logically and iteratively builds on the previous one, maintaining visual excellence with modern design patterns, smooth interactions, and professional UI polish.
133139
• Provide a clear, concise, to the point description of the next phase and the purpose and contents of each file in it.
134-
• Keep all the description fields very short and concise.
140+
• Keep all the description fields very short and concise but unambiguous so the coding agent can implement them effectively and accurately.
135141
• If there are any files that were supposed to be generated in the previous phase, but were not, please mention them in the phase description and suggest them in the phase.
136142
• Always suggest phases in sequential ordering - Phase 1 comes after Phase 0, Phase 2 comes after Phase 1 and so on.
137143
• **Every phase must be deployable with all views/pages working properly and looking professional.**
138144
• IF you need to get any file to be deleted or cleaned, please set the \`changes\` field to \`delete\` for that file.
145+
• **\`changes\` field format:**
146+
- WHAT (user-visible behavior) + HOW (conceptual approach) + CONSTRAINTS — but NO code/syntax
147+
148+
❌ "openWindow('finder', file.name, FinderWindow, {dirId: file.id})"
149+
✅ "Double-click folder navigates within same window (update dir state, not new window). Breadcrumbs show path, clickable to ancestors."
150+
151+
❌ "Add useState for loading, show Skeleton, catch error and setError"
152+
✅ "Fetch files on mount with loading/error states. Skeleton during load, error with retry on failure, empty state with create prompt."
153+
154+
❌ "onPointerDown check e.target === e.currentTarget before dragControls.start"
155+
✅ "Drag from title bar area only, not from buttons or title text. Use existing drag controls."
139156
• **Visual assets:** Use external image URLs, canvas elements, or icon libraries. Reference these in file descriptions as needed.
140157
</SUGGESTING NEXT PHASE>
141158

0 commit comments

Comments
 (0)