Skip to content

Commit 0356c8e

Browse files
committed
feat(sdk): add max_execution_time_ms to Node and Python SDKs
Align SDK interfaces with Rust Core by adding max_execution_time_ms configuration field to both Node.js and Python SDKs. Changes: - Node SDK: Add max_execution_time_ms to SessionOptions - Node SDK: Add conversion logic in js_session_options_to_rust - Python SDK: Add max_execution_time_ms to PySessionOptions - Python SDK: Add conversion logic in build_rust_session_options - Python SDK: Update Clone impl and new() constructor This ensures users can configure execution timeout from JavaScript and Python, preventing runaway executions and excessive API costs. Usage (Node.js): ```js agent.session('.', { maxExecutionTimeMs: 300000 // 5 minutes }); ``` Usage (Python): ```python opts = SessionOptions() opts.max_execution_time_ms = 300000 # 5 minutes session = agent.session('.', opts) ``` Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 436fd95 commit 0356c8e

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

sdk/node/src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,6 +1411,17 @@ pub struct SessionOptions {
14111411
/// });
14121412
/// ```
14131413
pub confirmation_policy: Option<ConfirmationPolicy>,
1414+
/// Maximum execution time in milliseconds.
1415+
///
1416+
/// When set, the execution loop will abort if it exceeds this duration.
1417+
/// This prevents runaway executions and excessive API costs.
1418+
///
1419+
/// ```js
1420+
/// agent.session('.', {
1421+
/// maxExecutionTimeMs: 300000 // 5 minutes
1422+
/// });
1423+
/// ```
1424+
pub max_execution_time_ms: Option<f64>,
14141425
}
14151426

14161427
/// A single message in conversation history.
@@ -1730,6 +1741,11 @@ fn js_session_options_to_rust(options: Option<SessionOptions>) -> RustSessionOpt
17301741
opts = opts.with_confirmation_policy(rust_policy);
17311742
}
17321743

1744+
// Maximum execution time configuration
1745+
if let Some(timeout_ms) = o.max_execution_time_ms {
1746+
opts.max_execution_time_ms = Some(timeout_ms as u64);
1747+
}
1748+
17331749
// AHP transport configuration
17341750
#[cfg(feature = "ahp")]
17351751
if let Some(ref transport) = o.ahp_transport {

sdk/python/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3059,6 +3059,9 @@ struct PySessionOptions {
30593059
continuation_enabled: Option<bool>,
30603060
/// Maximum continuation injections per execution (default: 3).
30613061
max_continuation_turns: Option<u32>,
3062+
/// Maximum execution time in milliseconds.
3063+
/// When set, the execution loop will abort if it exceeds this duration.
3064+
max_execution_time_ms: Option<u64>,
30623065
/// Session ID for this session (auto-generated if not set).
30633066
///
30643067
/// Set a stable ID to save and resume the session later:
@@ -3124,6 +3127,7 @@ impl Clone for PySessionOptions {
31243127
thinking_budget: self.thinking_budget,
31253128
continuation_enabled: self.continuation_enabled,
31263129
max_continuation_turns: self.max_continuation_turns,
3130+
max_execution_time_ms: self.max_execution_time_ms,
31273131
session_id: self.session_id.clone(),
31283132
auto_save: self.auto_save,
31293133
ahp_transport: pyo3::Python::with_gil(|py| {
@@ -3165,6 +3169,7 @@ impl PySessionOptions {
31653169
thinking_budget: None,
31663170
continuation_enabled: None,
31673171
max_continuation_turns: None,
3172+
max_execution_time_ms: None,
31683173
session_id: None,
31693174
auto_save: false,
31703175
ahp_transport: None,
@@ -3894,6 +3899,9 @@ fn build_rust_session_options(so: PySessionOptions) -> PyResult<RustSessionOptio
38943899
if let Some(turns) = so.max_continuation_turns {
38953900
o = o.with_max_continuation_turns(turns);
38963901
}
3902+
if let Some(timeout_ms) = so.max_execution_time_ms {
3903+
o.max_execution_time_ms = Some(timeout_ms);
3904+
}
38973905
if let Some(id) = so.session_id {
38983906
o = o.with_session_id(id);
38993907
}

0 commit comments

Comments
 (0)