Skip to content

Commit d10c1c5

Browse files
committed
refactor: replace magic numbers with documented named constants
1 parent 2878d46 commit d10c1c5

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/cortex-exec/src/runner.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,25 @@ use cortex_protocol::ConversationId;
2727

2828
use crate::output::{OutputFormat, OutputWriter};
2929

30+
// ============================================================================
31+
// CONFIGURATION CONSTANTS
32+
// ============================================================================
33+
3034
/// Maximum retries for transient errors.
3135
const MAX_RETRIES: usize = 3;
3236

37+
/// Default maximum number of conversation turns before stopping.
38+
const DEFAULT_MAX_TURNS: usize = 10;
39+
40+
/// Default temperature for LLM responses (0.0 = deterministic, 1.0 = creative).
41+
const DEFAULT_TEMPERATURE: f32 = 0.7;
42+
43+
/// Default maximum output tokens for LLM responses.
44+
const DEFAULT_MAX_OUTPUT_TOKENS: u32 = 4096;
45+
46+
/// Base delay between retry attempts in milliseconds (used for exponential backoff).
47+
const RETRY_DELAY_BASE_MS: u64 = 500;
48+
3349
/// Options for headless execution.
3450
#[derive(Debug, Clone)]
3551
pub struct ExecOptions {
@@ -69,7 +85,7 @@ impl Default for ExecOptions {
6985
model: None,
7086
output_format: OutputFormat::Text,
7187
full_auto: false,
72-
max_turns: Some(10),
88+
max_turns: Some(DEFAULT_MAX_TURNS),
7389
timeout_secs: Some(DEFAULT_EXEC_TIMEOUT_SECS),
7490
request_timeout_secs: Some(DEFAULT_REQUEST_TIMEOUT_SECS),
7591
sandbox: true,
@@ -334,7 +350,7 @@ impl ExecRunner {
334350

335351
// Get tool definitions
336352
let tools = self.get_tool_definitions();
337-
let max_turns = self.options.max_turns.unwrap_or(10);
353+
let max_turns = self.options.max_turns.unwrap_or(DEFAULT_MAX_TURNS);
338354

339355
// Main execution loop
340356
while turns < max_turns {
@@ -474,8 +490,8 @@ impl ExecRunner {
474490
let request = CompletionRequest {
475491
messages: conversation.messages().to_vec(),
476492
model: client.model().to_string(),
477-
max_tokens: Some(4096),
478-
temperature: Some(0.7),
493+
max_tokens: Some(DEFAULT_MAX_OUTPUT_TOKENS),
494+
temperature: Some(DEFAULT_TEMPERATURE),
479495
seed: None,
480496
tools: tools.to_vec(),
481497
stream: self.options.streaming,
@@ -497,7 +513,7 @@ impl ExecRunner {
497513
MAX_RETRIES
498514
));
499515
// Exponential backoff
500-
tokio::time::sleep(Duration::from_millis(500 * 2u64.pow(attempt as u32))).await;
516+
tokio::time::sleep(Duration::from_millis(RETRY_DELAY_BASE_MS * 2u64.pow(attempt as u32))).await;
501517
}
502518

503519
let result = tokio::time::timeout(request_timeout, async {
@@ -760,7 +776,7 @@ mod tests {
760776

761777
assert!(opts.prompt.is_empty());
762778
assert!(opts.sandbox);
763-
assert_eq!(opts.max_turns, Some(10));
779+
assert_eq!(opts.max_turns, Some(DEFAULT_MAX_TURNS));
764780
assert_eq!(opts.timeout_secs, Some(DEFAULT_EXEC_TIMEOUT_SECS));
765781
assert!(!opts.full_auto);
766782
assert!(opts.streaming);

0 commit comments

Comments
 (0)