Skip to content

Commit f2c089d

Browse files
committed
refactor(cortex-prompt-harness): consolidate all prompts into system sections
- Remove conditional capability context checks (code_execution, file_operations, web_search flags) - Add CODE_EXECUTION, FILE_OPERATIONS, and WEB_SEARCH_CAPABILITY as proper sections - All capability contexts are now treated as sections that can be enabled/disabled - No more 'if keyword in prompt' patterns - all prompts are in the system prompt directly - Maintain backward compatibility with with_code_execution(), with_file_operations(), with_web_search() methods
1 parent e5511a7 commit f2c089d

File tree

1 file changed

+37
-33
lines changed

1 file changed

+37
-33
lines changed

src/cortex-prompt-harness/src/prompts/top_agent.rs

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,9 @@ pub const TOP_AGENT_SECTION_NAMES: &[&str] = &[
11341134
"WEB_SEARCH",
11351135
"MULTIPLE_TOOL_CALLS",
11361136
"PROCESS_MANAGEMENT",
1137+
"CODE_EXECUTION",
1138+
"FILE_OPERATIONS",
1139+
"WEB_SEARCH_CAPABILITY",
11371140
];
11381141

11391142
// =============================================================================
@@ -1166,6 +1169,9 @@ impl TopAgentSection {
11661169
/// This builder allows dynamic construction of prompts by enabling/disabling
11671170
/// sections, adding capability contexts, and customizing variables.
11681171
///
1172+
/// All capability contexts (code execution, file operations, web search) are
1173+
/// included as sections that can be enabled/disabled like any other section.
1174+
///
11691175
/// # Example
11701176
///
11711177
/// ```rust
@@ -1184,12 +1190,6 @@ pub struct TopAgentPromptBuilder {
11841190
sections: Vec<TopAgentSection>,
11851191
/// Variables for template substitution.
11861192
variables: HashMap<String, String>,
1187-
/// Enable code execution context.
1188-
code_execution: bool,
1189-
/// Enable file operations context.
1190-
file_operations: bool,
1191-
/// Enable web search context.
1192-
web_search: bool,
11931193
/// Custom instructions to append.
11941194
custom_instructions: Option<String>,
11951195
/// Persona override.
@@ -1198,8 +1198,22 @@ pub struct TopAgentPromptBuilder {
11981198

11991199
impl TopAgentPromptBuilder {
12001200
/// Create a new builder with all sections enabled by default.
1201+
///
1202+
/// All capability contexts (CODE_EXECUTION, FILE_OPERATIONS, WEB_SEARCH_CAPABILITY)
1203+
/// are disabled by default. Use `with_code_execution()`, `with_file_operations()`,
1204+
/// and `with_web_search()` to enable them.
12011205
#[must_use]
12021206
pub fn new() -> Self {
1207+
let mut code_exec_section = TopAgentSection::new("CODE_EXECUTION", CODE_EXECUTION_CONTEXT);
1208+
code_exec_section.enabled = false;
1209+
1210+
let mut file_ops_section = TopAgentSection::new("FILE_OPERATIONS", FILE_OPERATIONS_CONTEXT);
1211+
file_ops_section.enabled = false;
1212+
1213+
let mut web_search_section =
1214+
TopAgentSection::new("WEB_SEARCH_CAPABILITY", WEB_SEARCH_CONTEXT);
1215+
web_search_section.enabled = false;
1216+
12031217
Self {
12041218
sections: vec![
12051219
TopAgentSection::new("IDENTITY", SECTION_IDENTITY),
@@ -1224,11 +1238,11 @@ impl TopAgentPromptBuilder {
12241238
TopAgentSection::new("WEB_SEARCH", SECTION_WEB_SEARCH),
12251239
TopAgentSection::new("MULTIPLE_TOOL_CALLS", SECTION_MULTIPLE_TOOL_CALLS),
12261240
TopAgentSection::new("PROCESS_MANAGEMENT", SECTION_PROCESS_MANAGEMENT),
1241+
code_exec_section,
1242+
file_ops_section,
1243+
web_search_section,
12271244
],
12281245
variables: HashMap::new(),
1229-
code_execution: false,
1230-
file_operations: false,
1231-
web_search: false,
12321246
custom_instructions: None,
12331247
persona: None,
12341248
}
@@ -1271,25 +1285,22 @@ impl TopAgentPromptBuilder {
12711285
self
12721286
}
12731287

1274-
/// Enable code execution capability context.
1288+
/// Enable code execution capability context section.
12751289
#[must_use]
1276-
pub fn with_code_execution(mut self) -> Self {
1277-
self.code_execution = true;
1278-
self
1290+
pub fn with_code_execution(self) -> Self {
1291+
self.with_section("CODE_EXECUTION")
12791292
}
12801293

1281-
/// Enable file operations capability context.
1294+
/// Enable file operations capability context section.
12821295
#[must_use]
1283-
pub fn with_file_operations(mut self) -> Self {
1284-
self.file_operations = true;
1285-
self
1296+
pub fn with_file_operations(self) -> Self {
1297+
self.with_section("FILE_OPERATIONS")
12861298
}
12871299

1288-
/// Enable web search capability context.
1300+
/// Enable web search capability context section.
12891301
#[must_use]
1290-
pub fn with_web_search(mut self) -> Self {
1291-
self.web_search = true;
1292-
self
1302+
pub fn with_web_search(self) -> Self {
1303+
self.with_section("WEB_SEARCH_CAPABILITY")
12931304
}
12941305

12951306
/// Add custom instructions to the end of the prompt.
@@ -1336,6 +1347,10 @@ impl TopAgentPromptBuilder {
13361347
}
13371348

13381349
/// Build the final prompt string.
1350+
///
1351+
/// All enabled sections are included directly in the system prompt.
1352+
/// There are no conditional checks - each section is either included or not
1353+
/// based on whether it is enabled.
13391354
#[must_use]
13401355
pub fn build(&self) -> String {
13411356
let mut parts: Vec<String> = Vec::new();
@@ -1345,25 +1360,14 @@ impl TopAgentPromptBuilder {
13451360
parts.push(persona.clone());
13461361
}
13471362

1348-
// Add enabled sections
1363+
// Add all enabled sections directly to the system prompt
13491364
for section in &self.sections {
13501365
if section.enabled {
13511366
let content = self.render_template(&section.content);
13521367
parts.push(content);
13531368
}
13541369
}
13551370

1356-
// Add capability contexts
1357-
if self.code_execution {
1358-
parts.push(CODE_EXECUTION_CONTEXT.to_string());
1359-
}
1360-
if self.file_operations {
1361-
parts.push(FILE_OPERATIONS_CONTEXT.to_string());
1362-
}
1363-
if self.web_search {
1364-
parts.push(WEB_SEARCH_CONTEXT.to_string());
1365-
}
1366-
13671371
// Add custom instructions
13681372
if let Some(ref instructions) = self.custom_instructions {
13691373
parts.push(format!("## Custom Instructions\n\n{}", instructions));

0 commit comments

Comments
 (0)