Skip to main content

steer_core/tools/
execution_context.rs

1use crate::config::LlmConfigProvider;
2use std::time::Duration;
3use tokio_util::sync::CancellationToken;
4
5/// Core execution context passed to all tool executions
6#[derive(Debug, Clone)]
7pub struct ExecutionContext {
8    pub session_id: String,
9    pub operation_id: String,
10    pub tool_call_id: String,
11    pub cancellation_token: CancellationToken,
12    pub timeout: Duration,
13    pub llm_config_provider: Option<LlmConfigProvider>,
14}
15
16/// Builder for ExecutionContext
17#[derive(Debug)]
18pub struct ExecutionContextBuilder {
19    session_id: String,
20    operation_id: String,
21    tool_call_id: String,
22    cancellation_token: CancellationToken,
23    timeout: Duration,
24    llm_config_provider: Option<LlmConfigProvider>,
25}
26
27impl ExecutionContext {
28    /// Create a new builder for ExecutionContext
29    pub fn builder(
30        session_id: String,
31        operation_id: String,
32        tool_call_id: String,
33        cancellation_token: CancellationToken,
34    ) -> ExecutionContextBuilder {
35        ExecutionContextBuilder {
36            session_id,
37            operation_id,
38            tool_call_id,
39            cancellation_token,
40            timeout: Duration::from_secs(300),
41            llm_config_provider: None,
42        }
43    }
44
45    /// Legacy constructor - prefer using builder() instead
46    pub fn new(
47        session_id: String,
48        operation_id: String,
49        tool_call_id: String,
50        cancellation_token: CancellationToken,
51    ) -> Self {
52        Self::builder(session_id, operation_id, tool_call_id, cancellation_token).build()
53    }
54
55    pub fn with_timeout(mut self, timeout: Duration) -> Self {
56        self.timeout = timeout;
57        self
58    }
59
60    pub fn with_llm_config_provider(mut self, provider: LlmConfigProvider) -> Self {
61        self.llm_config_provider = Some(provider);
62        self
63    }
64}
65
66impl ExecutionContextBuilder {
67    pub fn timeout(mut self, timeout: Duration) -> Self {
68        self.timeout = timeout;
69        self
70    }
71
72    pub fn llm_config_provider(mut self, provider: LlmConfigProvider) -> Self {
73        self.llm_config_provider = Some(provider);
74        self
75    }
76
77    pub fn build(self) -> ExecutionContext {
78        ExecutionContext {
79            session_id: self.session_id,
80            operation_id: self.operation_id,
81            tool_call_id: self.tool_call_id,
82            cancellation_token: self.cancellation_token,
83            timeout: self.timeout,
84            llm_config_provider: self.llm_config_provider,
85        }
86    }
87}