feat: support setting the tool_timeout in the main config file instead of only via an environment variable
This commit is contained in:
8 files changed
+125
-23
No files matched your search
+14
-5
@@ -599,30 +599,39 @@ impl Agent {
|
||||
self.config.dynamic_instructions
|
||||
}
|
||||
|
||||
pub fn update_shared_dynamic_instructions(&mut self, force: bool) -> Result<()> {
|
||||
pub fn update_shared_dynamic_instructions(
|
||||
&mut self,
|
||||
force: bool,
|
||||
tool_timeout: Option<u64>,
|
||||
) -> Result<()> {
|
||||
if self.is_dynamic_instructions() && (force || self.shared_dynamic_instructions.is_none()) {
|
||||
self.shared_dynamic_instructions = Some(self.run_instructions_fn()?);
|
||||
self.shared_dynamic_instructions = Some(self.run_instructions_fn(tool_timeout)?);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn update_session_dynamic_instructions(&mut self, value: Option<String>) -> Result<()> {
|
||||
pub fn update_session_dynamic_instructions(
|
||||
&mut self,
|
||||
value: Option<String>,
|
||||
tool_timeout: Option<u64>,
|
||||
) -> Result<()> {
|
||||
if self.is_dynamic_instructions() {
|
||||
let value = match value {
|
||||
Some(v) => v,
|
||||
None => self.run_instructions_fn()?,
|
||||
None => self.run_instructions_fn(tool_timeout)?,
|
||||
};
|
||||
self.session_dynamic_instructions = Some(value);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn run_instructions_fn(&self) -> Result<String> {
|
||||
fn run_instructions_fn(&self, tool_timeout: Option<u64>) -> Result<String> {
|
||||
let value = run_llm_function(
|
||||
self.name().to_string(),
|
||||
vec!["_instructions".into(), "{}".into()],
|
||||
self.variable_envs(),
|
||||
Some(self.name().to_string()),
|
||||
tool_timeout,
|
||||
false,
|
||||
)?;
|
||||
match value {
|
||||
|
||||
@@ -70,6 +70,7 @@ pub struct AppConfig {
|
||||
pub summary_context_prompt: Option<String>,
|
||||
pub max_tool_result_chars: Option<usize>,
|
||||
pub max_concurrent_jobs: Option<usize>,
|
||||
pub tool_timeout: Option<u64>,
|
||||
|
||||
pub memory: Option<bool>,
|
||||
pub memory_cap_with_tools: Option<usize>,
|
||||
@@ -159,6 +160,7 @@ impl Default for AppConfig {
|
||||
summary_context_prompt: None,
|
||||
max_tool_result_chars: None,
|
||||
max_concurrent_jobs: None,
|
||||
tool_timeout: None,
|
||||
|
||||
memory: None,
|
||||
memory_cap_with_tools: None,
|
||||
@@ -249,6 +251,7 @@ impl AppConfig {
|
||||
summary_context_prompt: config.summary_context_prompt,
|
||||
max_tool_result_chars: config.max_tool_result_chars,
|
||||
max_concurrent_jobs: config.max_concurrent_jobs,
|
||||
tool_timeout: config.tool_timeout,
|
||||
|
||||
memory: config.memory,
|
||||
memory_cap_with_tools: config.memory_cap_with_tools,
|
||||
@@ -587,6 +590,9 @@ impl AppConfig {
|
||||
if let Some(v) = super::read_env_value::<usize>(&get_env_name("max_concurrent_jobs")) {
|
||||
self.max_concurrent_jobs = v;
|
||||
}
|
||||
if let Some(v) = super::read_env_value::<u64>(&get_env_name("tool_timeout")) {
|
||||
self.tool_timeout = v;
|
||||
}
|
||||
if let Some(v) = super::read_env_value::<String>(&get_env_name("summarization_prompt")) {
|
||||
self.summarization_prompt = v;
|
||||
}
|
||||
@@ -926,6 +932,49 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_config_copies_tool_timeout() {
|
||||
let cfg = Config {
|
||||
model_id: "test-model".to_string(),
|
||||
tool_timeout: Some(600),
|
||||
clients: vec![ClientConfig::default()],
|
||||
..Config::default()
|
||||
};
|
||||
|
||||
let app = AppConfig::from_config(cfg).unwrap();
|
||||
|
||||
assert_eq!(app.tool_timeout, Some(600));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial_test::serial]
|
||||
fn load_envs_overrides_tool_timeout() {
|
||||
let env_name = get_env_name("tool_timeout");
|
||||
let prev = env::var_os(&env_name);
|
||||
|
||||
let mut app = AppConfig::default();
|
||||
|
||||
unsafe { env::set_var(&env_name, "90") };
|
||||
app.load_envs();
|
||||
assert_eq!(app.tool_timeout, Some(90));
|
||||
|
||||
unsafe { env::set_var(&env_name, "0") };
|
||||
app.load_envs();
|
||||
assert_eq!(app.tool_timeout, Some(0));
|
||||
|
||||
unsafe { env::remove_var(&env_name) };
|
||||
app.tool_timeout = Some(60);
|
||||
app.load_envs();
|
||||
assert_eq!(app.tool_timeout, Some(60));
|
||||
|
||||
unsafe {
|
||||
match prev {
|
||||
Some(v) => env::set_var(&env_name, v),
|
||||
None => env::remove_var(&env_name),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn editor_returns_configured_value() {
|
||||
let configured =
|
||||
|
||||
@@ -256,6 +256,7 @@ pub struct Config {
|
||||
pub summary_context_prompt: Option<String>,
|
||||
pub max_tool_result_chars: Option<usize>,
|
||||
pub max_concurrent_jobs: Option<usize>,
|
||||
pub tool_timeout: Option<u64>,
|
||||
|
||||
pub memory: Option<bool>,
|
||||
pub memory_cap_with_tools: Option<usize>,
|
||||
@@ -342,6 +343,7 @@ impl Default for Config {
|
||||
summary_context_prompt: None,
|
||||
max_tool_result_chars: None,
|
||||
max_concurrent_jobs: None,
|
||||
tool_timeout: None,
|
||||
|
||||
memory: None,
|
||||
memory_cap_with_tools: None,
|
||||
|
||||
@@ -1173,7 +1173,7 @@ impl RequestContext {
|
||||
agent.set_shared_variables(new_variables);
|
||||
}
|
||||
if !self.info_flag {
|
||||
agent.update_shared_dynamic_instructions(false)?;
|
||||
agent.update_shared_dynamic_instructions(false, self.app.config.tool_timeout)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -1199,15 +1199,16 @@ impl RequestContext {
|
||||
};
|
||||
agent.set_session_variables(session_variables);
|
||||
if !self.info_flag {
|
||||
agent.update_session_dynamic_instructions(None)?;
|
||||
agent.update_session_dynamic_instructions(None, self.app.config.tool_timeout)?;
|
||||
}
|
||||
session.sync_agent(agent);
|
||||
} else {
|
||||
let variables = session.agent_variables();
|
||||
agent.set_session_variables(variables.clone());
|
||||
agent.update_session_dynamic_instructions(Some(
|
||||
session.agent_instructions().to_string(),
|
||||
))?;
|
||||
agent.update_session_dynamic_instructions(
|
||||
Some(session.agent_instructions().to_string()),
|
||||
self.app.config.tool_timeout,
|
||||
)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user