Skip to content

Commit 2b3a901

Browse files
authored
Feat: Cost optimizations via model configs and prompt improvements (#247)
* refactor: split agent config by deployment type and reduce resource limits Split AGENT_CONFIG into platform-specific and vanilla deployments based on PLATFORM_MODEL_PROVIDERS environment variable. Add documentation comments explaining config usage. Reduce deepDebugger max tool calling depth from 100 to 50 and conversation compactification threshold from 100k to 50k tokens. Add Google Vertex AI models (GPT OSS 120B and Kimi K2 Thinking) to model catalog. Enhance blueprint system prompt to emphas * refactor: adjust blueprint and implementation agent model configurations Switch blueprint agent from Gemini 3 Pro Preview to OpenAI 5 Mini with reduced max tokens (32k). Update firstPhaseImplementation and phaseImplementation agents to use Gemini 2.5 Pro instead of Gemini 3 Pro Preview. Lower firstPhaseImplementation temperature from 1.0 to 0.2 for more consistent output. Update blueprint system prompt to clarify project seriousness by replacing "toy or educational" with "toy or demo". * refactor: extract shared agent configs and improve config organization
1 parent 3f9ccf7 commit 2b3a901

5 files changed

Lines changed: 128 additions & 55 deletions

File tree

worker/agents/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export const MAX_TOOL_CALLING_DEPTH_DEFAULT = 7;
113113
export const getMaxToolCallingDepth = (agentActionKey: AgentActionKey | 'testModelConfig') => {
114114
switch (agentActionKey) {
115115
case 'deepDebugger':
116-
return 100;
116+
return 50;
117117
default:
118118
return MAX_TOOL_CALLING_DEPTH_DEFAULT;
119119
}

worker/agents/inferutils/config.ts

Lines changed: 97 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,60 @@ import {
77
LiteModels,
88
RegularModels,
99
} from "./config.types";
10+
import { env } from 'cloudflare:workers';
1011

11-
export const AGENT_CONFIG: AgentConfig = {
12+
// Common configs - these are good defaults
13+
const COMMON_AGENT_CONFIGS = {
1214
templateSelection: {
1315
name: AIModels.GEMINI_2_5_FLASH_LITE,
1416
max_tokens: 2000,
1517
fallbackModel: AIModels.GEMINI_2_5_FLASH,
1618
temperature: 0.6,
1719
},
20+
screenshotAnalysis: {
21+
name: AIModels.DISABLED,
22+
reasoning_effort: 'medium' as const,
23+
max_tokens: 8000,
24+
temperature: 1,
25+
fallbackModel: AIModels.GEMINI_2_5_FLASH,
26+
},
27+
realtimeCodeFixer: {
28+
name: AIModels.DISABLED,
29+
reasoning_effort: 'low' as const,
30+
max_tokens: 32000,
31+
temperature: 1,
32+
fallbackModel: AIModels.GEMINI_2_5_FLASH,
33+
},
34+
fastCodeFixer: {
35+
name: AIModels.DISABLED,
36+
reasoning_effort: undefined,
37+
max_tokens: 64000,
38+
temperature: 0.0,
39+
fallbackModel: AIModels.GEMINI_2_5_PRO,
40+
},
41+
} as const;
42+
43+
const SHARED_IMPLEMENTATION_CONFIG = {
44+
reasoning_effort: 'low' as const,
45+
max_tokens: 48000,
46+
temperature: 0.2,
47+
fallbackModel: AIModels.GEMINI_2_5_PRO,
48+
};
49+
50+
//======================================================================================
51+
// ATTENTION! Platform config requires specific API keys and Cloudflare AI Gateway setup.
52+
//======================================================================================
53+
/*
54+
These are the configs used at build.cloudflare.dev
55+
You may need to provide API keys for these models in your environment or use
56+
Cloudflare AI Gateway unified billing for seamless model access without managing multiple keys.
57+
*/
58+
const PLATFORM_AGENT_CONFIG: AgentConfig = {
59+
...COMMON_AGENT_CONFIGS,
1860
blueprint: {
19-
name: AIModels.GEMINI_3_PRO_PREVIEW,
61+
name: AIModels.OPENAI_5_MINI,
2062
reasoning_effort: 'medium',
21-
max_tokens: 64000,
63+
max_tokens: 32000,
2264
fallbackModel: AIModels.GEMINI_2_5_FLASH,
2365
temperature: 1.0,
2466
},
@@ -37,18 +79,12 @@ export const AGENT_CONFIG: AgentConfig = {
3779
fallbackModel: AIModels.GEMINI_2_5_FLASH,
3880
},
3981
firstPhaseImplementation: {
40-
name: AIModels.GEMINI_3_PRO_PREVIEW,
41-
reasoning_effort: 'low',
42-
max_tokens: 48000,
43-
temperature: 1,
44-
fallbackModel: AIModels.GEMINI_2_5_PRO,
82+
name: AIModels.GEMINI_2_5_PRO,
83+
...SHARED_IMPLEMENTATION_CONFIG,
4584
},
4685
phaseImplementation: {
47-
name: AIModels.GEMINI_3_PRO_PREVIEW,
48-
reasoning_effort: 'low',
49-
max_tokens: 48000,
50-
temperature: 0.2,
51-
fallbackModel: AIModels.GEMINI_2_5_PRO,
86+
name: AIModels.GEMINI_2_5_PRO,
87+
...SHARED_IMPLEMENTATION_CONFIG,
5288
},
5389
conversationalResponse: {
5490
name: AIModels.GROK_4_FAST,
@@ -71,31 +107,65 @@ export const AGENT_CONFIG: AgentConfig = {
71107
temperature: 1,
72108
fallbackModel: AIModels.GROK_CODE_FAST_1,
73109
},
74-
// Not used right now
75-
screenshotAnalysis: {
110+
};
111+
112+
//======================================================================================
113+
// Default Gemini-only config (most likely used in your deployment)
114+
//======================================================================================
115+
/* These are the default out-of-the box gemini-only models used when PLATFORM_MODEL_PROVIDERS is not set */
116+
const DEFAULT_AGENT_CONFIG: AgentConfig = {
117+
...COMMON_AGENT_CONFIGS,
118+
blueprint: {
76119
name: AIModels.GEMINI_2_5_PRO,
77120
reasoning_effort: 'medium',
121+
max_tokens: 64000,
122+
fallbackModel: AIModels.GEMINI_2_5_FLASH,
123+
temperature: 0.7,
124+
},
125+
projectSetup: {
126+
name: AIModels.GEMINI_2_5_PRO,
127+
...SHARED_IMPLEMENTATION_CONFIG,
128+
},
129+
phaseGeneration: {
130+
name: AIModels.GEMINI_2_5_PRO,
131+
...SHARED_IMPLEMENTATION_CONFIG,
132+
},
133+
firstPhaseImplementation: {
134+
name: AIModels.GEMINI_2_5_PRO,
135+
...SHARED_IMPLEMENTATION_CONFIG,
136+
},
137+
phaseImplementation: {
138+
name: AIModels.GEMINI_2_5_PRO,
139+
...SHARED_IMPLEMENTATION_CONFIG,
140+
},
141+
conversationalResponse: {
142+
name: AIModels.GEMINI_2_5_FLASH,
143+
reasoning_effort: 'low',
144+
max_tokens: 4000,
145+
temperature: 0,
146+
fallbackModel: AIModels.GEMINI_2_5_PRO,
147+
},
148+
deepDebugger: {
149+
name: AIModels.GEMINI_2_5_PRO,
150+
reasoning_effort: 'high',
78151
max_tokens: 8000,
79-
temperature: 1,
152+
temperature: 0.5,
80153
fallbackModel: AIModels.GEMINI_2_5_FLASH,
81154
},
82-
realtimeCodeFixer: {
83-
name: AIModels.DISABLED,
155+
fileRegeneration: {
156+
name: AIModels.GEMINI_2_5_PRO,
84157
reasoning_effort: 'low',
85158
max_tokens: 32000,
86-
temperature: 1,
159+
temperature: 0,
87160
fallbackModel: AIModels.GEMINI_2_5_FLASH,
88161
},
89-
// Not used right now
90-
fastCodeFixer: {
91-
name: AIModels.DISABLED,
92-
reasoning_effort: undefined,
93-
max_tokens: 64000,
94-
temperature: 0.0,
95-
fallbackModel: AIModels.GEMINI_2_5_PRO,
96-
},
97162
};
98163

164+
export const AGENT_CONFIG: AgentConfig = env.PLATFORM_MODEL_PROVIDERS
165+
? PLATFORM_AGENT_CONFIG
166+
: DEFAULT_AGENT_CONFIG;
167+
168+
99169
export const AGENT_CONSTRAINTS: Map<AgentActionKey, AgentConstraintConfig> = new Map([
100170
['fastCodeFixer', {
101171
allowedModels: new Set([AIModels.DISABLED]),

worker/agents/inferutils/config.types.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -252,28 +252,28 @@ const MODELS_MASTER = {
252252
nonReasoning: true,
253253
}
254254
},
255-
// GROK_4_1_FAST: {
256-
// id: 'grok/grok-4.1-fast',
257-
// config: {
258-
// name: 'Grok 4.1 Fast',
259-
// size: ModelSize.LITE,
260-
// provider: 'grok',
261-
// creditCost: 0.8, // $0.20
262-
// contextSize: 2_000_000, // 2M Context
263-
// nonReasoning: true,
264-
// }
265-
// },
266-
// GROQ_GPT_120_OSS: {
267-
// id: 'groq/gpt-oss-120b',
268-
// config: {
269-
// name: 'GROQ GPT 120B OSS',
270-
// size: ModelSize.LITE,
271-
// provider: 'groq',
272-
// creditCost: 0.4, // $0.25
273-
// contextSize: 131072, // 128K Context
274-
// nonReasoning: true,
275-
// }
276-
// },
255+
256+
// --- Vertex Models ---
257+
VERTEX_GPT_OSS_120: {
258+
id: 'google-vertex-ai/openai/gpt-oss-120b',
259+
config: {
260+
name: 'Google Vertex GPT OSS 120B',
261+
size: ModelSize.LITE,
262+
provider: 'google-vertex-ai',
263+
creditCost: 0.36, // $0.09
264+
contextSize: 131072, // 128K Context
265+
}
266+
},
267+
VERTEX_KIMI_THINKING: {
268+
id: 'google-vertex-ai/moonshotai/kimi-k2-thinking',
269+
config: {
270+
name: 'Google Vertex Kimi K2 Thinking',
271+
size: ModelSize.LITE,
272+
provider: 'google-vertex-ai',
273+
creditCost: 2, // $0.50
274+
contextSize: 262144, // 256K Context
275+
}
276+
},
277277
} as const;
278278

279279
/**

worker/agents/operations/UserConversationProcessor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const CHUNK_SIZE = 64;
2525
// Compactification thresholds
2626
const COMPACTIFICATION_CONFIG = {
2727
MAX_TURNS: 40, // Trigger after 50 conversation turns
28-
MAX_ESTIMATED_TOKENS: 100000,
28+
MAX_ESTIMATED_TOKENS: 50000,
2929
PRESERVE_RECENT_MESSAGES: 10, // Always keep last 10 messages uncompacted
3030
CHARS_PER_TOKEN: 4, // Rough estimation: 1 token ≈ 4 characters
3131
} as const;

worker/agents/planning/blueprint.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,23 @@ const SYSTEM_PROMPT = `<ROLE>
1919
</ROLE>
2020
2121
<TASK>
22-
You are tasked with creating a detailed yet concise, information-dense blueprint (PRD) for a web application project for our client: designing and outlining the frontend UI/UX and core functionality of the application with exceptional focus on visual appeal and user experience.
22+
You are tasked with creating a detailed yet concise, information-dense blueprint (PRD) for a web application project for our client: designing and outlining the frontend UI/UX (user interface, user experience) and core functionality of the application with exceptional focus on visual appeal, user experience, product quality, completion and polish.
2323
The project would be built on serverless Cloudflare workers and supporting technologies, and would run on Cloudflare's edge network. The project would be seeded with a starting template.
24-
Focus on a clear and comprehensive design that prioritizes STUNNING VISUAL DESIGN, be to the point, explicit and detailed in your response, and adhere to our development process.
24+
Focus on a clear and comprehensive design that prioritizes STUNNING VISUAL DESIGN, polish and depth, be to the point, explicit and detailed in your response, and adhere to our development process.
2525
Enhance the user's request and expand on it, think creatively, be ambitious and come up with a very beautiful, elegant, feature complete and polished design. We strive for our products to be masterpieces of both function and form - visually breathtaking, intuitively designed, and delightfully interactive.
2626
27-
**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.**
27+
**REMEMBER: This is not a toy or demo 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. We do not just expect an MVP, We expect a production-ready, polished, and exceptional solution**
2828
</TASK>
2929
3030
<GOAL>
3131
Design the product described by the client and come up with a really nice and professional name for the product.
3232
Write concise blueprint for a web application based on the user's request. Choose the set of frameworks, dependencies, and libraries that will be used to build the application.
33-
This blueprint will serve as the main defining document for our whole team, so be explicit and detailed enough, especially for the initial phase.
33+
This blueprint will serve as the main defining and guiding document for our whole team, so be explicit and detailed enough, especially for the initial phase.
3434
Think carefully about the application's purpose, experience, architecture, structure, and components, and come up with the PRD and all the libraries, dependencies, and frameworks that will be required.
3535
**VISUAL DESIGN EXCELLENCE**: Design the application frontend with exceptional attention to visual details - specify exact components, navigation patterns, headers, footers, color schemes, typography scales, spacing systems, micro-interactions, animations, hover states, loading states, and responsive behaviors.
3636
**USER EXPERIENCE FOCUS**: Plan intuitive user flows, clear information hierarchy, accessible design patterns, and delightful interactions that make users want to use the application.
3737
Build upon the provided template. Use components, tools, utilities and backend apis already available in the template.
38+
Think and **BREAKDOWN** The project into multiple incremental phases that build upon each other to create a complete, polished product following our <PHASES GENERATION STRATEGY>.
3839
</GOAL>
3940
4041
<INSTRUCTIONS>
@@ -77,6 +78,7 @@ const SYSTEM_PROMPT = `<ROLE>
7778
• **TEMPLATE ENHANCEMENT:** Build upon the <STARTING TEMPLATE> while significantly elevating its visual appeal. Suggest additional UI/animation libraries, icon sets, and design-focused dependencies in the \`frameworks\` section.
7879
- Enhance existing project patterns with beautiful visual treatments
7980
- Add sophisticated styling and interaction libraries as needed
81+
- Be aware of template design/layout short-comings and take it into account during your planning and in pitfalls.
8082
8183
## Important use case specific instructions:
8284
{{usecaseSpecificInstructions}}
@@ -101,6 +103,7 @@ const SYSTEM_PROMPT = `<ROLE>
101103
</INSTRUCTIONS>
102104
103105
<KEY GUIDELINES>
106+
• **Ultra think:** Do thorough thinking internally first before writing the blueprint. Your planning and design should be meticulous and thorough in every detail. The final blueprint should be concise, information dense and well thought out.
104107
• **Completeness is Crucial:** The AI coder relies *solely* on this blueprint. Leave no ambiguity.
105108
• **Precision in UI/Layout:** Define visual structure explicitly. Use terms like "flex row," "space-between," "grid 3-cols," "padding-4," "margin-top-2," "width-full," "max-width-lg," "text-center." Specify responsive behavior.
106109
• **Explicit Logic:** Detail application logic, state transitions, and data transformations clearly.

0 commit comments

Comments
 (0)