feat(runtime): add reasoning toggle for ollama

This commit is contained in:
Chummy 2026-02-19 16:51:25 +08:00
parent 8f13fee4a6
commit a5d7911923
10 changed files with 289 additions and 31 deletions

View file

@ -21,6 +21,8 @@ pub struct DelegateTool {
security: Arc<SecurityPolicy>,
/// Global credential fallback (from config.api_key)
fallback_credential: Option<String>,
/// Provider runtime options inherited from root config.
provider_runtime_options: providers::ProviderRuntimeOptions,
/// Depth at which this tool instance lives in the delegation chain.
depth: u32,
}
@ -30,11 +32,26 @@ impl DelegateTool {
agents: HashMap<String, DelegateAgentConfig>,
fallback_credential: Option<String>,
security: Arc<SecurityPolicy>,
) -> Self {
Self::new_with_options(
agents,
fallback_credential,
security,
providers::ProviderRuntimeOptions::default(),
)
}
pub fn new_with_options(
agents: HashMap<String, DelegateAgentConfig>,
fallback_credential: Option<String>,
security: Arc<SecurityPolicy>,
provider_runtime_options: providers::ProviderRuntimeOptions,
) -> Self {
Self {
agents: Arc::new(agents),
security,
fallback_credential,
provider_runtime_options,
depth: 0,
}
}
@ -47,11 +64,28 @@ impl DelegateTool {
fallback_credential: Option<String>,
security: Arc<SecurityPolicy>,
depth: u32,
) -> Self {
Self::with_depth_and_options(
agents,
fallback_credential,
security,
depth,
providers::ProviderRuntimeOptions::default(),
)
}
pub fn with_depth_and_options(
agents: HashMap<String, DelegateAgentConfig>,
fallback_credential: Option<String>,
security: Arc<SecurityPolicy>,
depth: u32,
provider_runtime_options: providers::ProviderRuntimeOptions,
) -> Self {
Self {
agents: Arc::new(agents),
security,
fallback_credential,
provider_runtime_options,
depth,
}
}
@ -190,20 +224,23 @@ impl Tool for DelegateTool {
#[allow(clippy::option_as_ref_deref)]
let provider_credential = provider_credential_owned.as_ref().map(String::as_str);
let provider: Box<dyn Provider> =
match providers::create_provider(&agent_config.provider, provider_credential) {
Ok(p) => p,
Err(e) => {
return Ok(ToolResult {
success: false,
output: String::new(),
error: Some(format!(
"Failed to create provider '{}' for agent '{agent_name}': {e}",
agent_config.provider
)),
});
}
};
let provider: Box<dyn Provider> = match providers::create_provider_with_options(
&agent_config.provider,
provider_credential,
&self.provider_runtime_options,
) {
Ok(p) => p,
Err(e) => {
return Ok(ToolResult {
success: false,
output: String::new(),
error: Some(format!(
"Failed to create provider '{}' for agent '{agent_name}': {e}",
agent_config.provider
)),
});
}
};
// Build the message
let full_prompt = if context.is_empty() {

View file

@ -227,10 +227,19 @@ pub fn all_tools_with_runtime(
let trimmed_value = value.trim();
(!trimmed_value.is_empty()).then(|| trimmed_value.to_owned())
});
tools.push(Box::new(DelegateTool::new(
tools.push(Box::new(DelegateTool::new_with_options(
delegate_agents,
delegate_fallback_credential,
security.clone(),
crate::providers::ProviderRuntimeOptions {
auth_profile_override: None,
zeroclaw_dir: root_config
.config_path
.parent()
.map(std::path::PathBuf::from),
secrets_encrypt: root_config.secrets.encrypt,
reasoning_enabled: root_config.runtime.reasoning_enabled,
},
)));
}