Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(inference): update claude model factory logic

Steven Enamakel5ade94f9d808
diff --git a/crates/openhuman-core/src/inference/provider/factory/chat_model.rs b/crates/openhuman-core/src/inference/provider/factory/chat_model.rs
index 5cf8192f32..b16847a78d 100644
--- a/crates/openhuman-core/src/inference/provider/factory/chat_model.rs
+++ b/crates/openhuman-core/src/inference/provider/factory/chat_model.rs
@@ -121,8 +121,12 @@ impl OpenHumanModelFactory<'_> {
CLAUDE_AGENT_SDK_PROVIDER.to_owned(),
concrete,
)
- } else if let Some(result) = try_create_claude_code_chat_model_from_string(
- role, &provider, self.config, (!pin.is_empty()).then_some(pin), self.egress,
+ } else if let Some(result) = build_claude_code_model(
+ role,
+ &provider,
+ self.config,
+ (!pin.is_empty()).then_some(pin),
+ self.egress,
) {
let (model, _) = result?;
(model, "claude-code".to_owned(), pin.to_owned())
diff --git a/crates/openhuman-core/src/inference/provider/factory/subprocess_providers.rs b/crates/openhuman-core/src/inference/provider/factory/subprocess_providers.rs
index e1b6581ef4..a6bc83f4db 100644
--- a/crates/openhuman-core/src/inference/provider/factory/subprocess_providers.rs
+++ b/crates/openhuman-core/src/inference/provider/factory/subprocess_providers.rs
@@ -1,38 +1,11 @@
//! Subprocess-backed providers: the Claude Agent SDK and the Claude Code CLI.
use super::*;
-use crate::inference::provider::factory::access_gates::verify_provider_session;
+use tinyinference_providers::route::{ProviderRoute, RouteKind};
/// Build the Claude Agent SDK subprocess directly as a crate model. This is a
/// prompt-guided model: TinyAgents owns its text-tool protocol, while the
/// provider owns only subprocess transport and NDJSON decoding.
-pub(super) fn try_create_claude_agent_sdk_chat_model(
- role: &str,
- config: &Config,
- egress: &EgressLedger,
-) -> OptionalChatModelResult {
- let resolved = provider_for_role(role, config);
- try_create_claude_agent_sdk_chat_model_from_string(role, &resolved, config, egress)
-}
-
-pub(super) fn try_create_claude_agent_sdk_chat_model_from_string(
- role: &str,
- provider: &str,
- config: &Config,
- egress: &EgressLedger,
-) -> OptionalChatModelResult {
- let model = match prepare_claude_agent_sdk_chat_model(role, provider, config)? {
- Ok(model) => model,
- Err(error) => return Some(Err(error)),
- };
- emit_inference_egress(role, &format!("{CLAUDE_AGENT_SDK_PREFIX}{model}"), egress);
- let chat: Arc<dyn ChatModel<()>> = Arc::new(ClaudeAgentSdkProvider::for_model(
- (&config.claude_agent_sdk).into(),
- model.clone(),
- ));
- Some(Ok((chat, model)))
-}
-
pub(super) fn prepare_claude_agent_sdk_chat_model(
role: &str,
provider: &str,
@@ -53,80 +26,61 @@ pub(super) fn claude_agent_sdk_model_from_string(
config: &Config,
) -> Option<String> {
let provider = provider.trim();
- let model = if provider == CLAUDE_AGENT_SDK_PROVIDER {
- config.claude_agent_sdk.default_model.clone()
- } else {
- let model = provider.strip_prefix(CLAUDE_AGENT_SDK_PREFIX)?;
- model.trim().to_string()
- };
- Some(model)
-}
-
-pub(super) fn try_create_claude_code_chat_model(
- role: &str,
- config: &Config,
- model_override: Option<&str>,
- egress: &EgressLedger,
-) -> OptionalChatModelResult {
- let resolved = provider_for_role(role, config);
- try_create_claude_code_chat_model_from_string(role, &resolved, config, model_override, egress)
+ if provider == CLAUDE_AGENT_SDK_PROVIDER {
+ return config.claude_agent_sdk.default_model.clone();
+ }
+ let route = ProviderRoute::parse(provider)?;
+ matches!(route.kind(), RouteKind::ClaudeAgentSdk).then_some(route.model)
}
-pub(super) fn try_create_claude_code_chat_model_from_string(
+pub(super) fn build_claude_code_model(
role: &str,
provider: &str,
config: &Config,
model_override: Option<&str>,
egress: &EgressLedger,
-) -> OptionalChatModelResult {
- let provider = provider.trim();
- let model_with_temp =
- provider.strip_prefix(tinyagents_harness::providers::claude_code::PROVIDER_PREFIX)?;
- let (configured_model, temperature_override) = split_model_and_temperature(model_with_temp);
- if temperature_override.is_some() {
- log::warn!(
- "[providers][chat-factory] claude-code provider: per-model temperature override \
- is accepted but not wired through to the CLI — the @<temp> suffix is ignored"
- );
- }
- if configured_model.is_empty() {
- return Some(Err(anyhow::anyhow!(
- "[chat-factory] provider string '{}' for role '{}' has an empty model — \
- use 'claude-code:<model-id>'",
- provider,
- role
- )));
+) -> Option<anyhow::Result<(Arc<dyn ChatModel<()>>, String)>> {
+ let route = ProviderRoute::parse(provider)?;
+ if !matches!(route.kind(), RouteKind::ClaudeCode) {
+ return None;
}
- if let Err(error) = enforce_local_only_inference(role, provider) {
- return Some(Err(error));
- }
- if let Err(error) = verify_provider_session(config, provider) {
- return Some(Err(error));
- }
- let workspace = config
- .config_path
- .parent()
- .map(std::path::Path::to_path_buf)
- .unwrap_or_else(|| config.workspace_dir.clone());
- let effective_model = model_override.unwrap_or(&configured_model).to_string();
- emit_inference_egress(
- role,
- &format!(
- "{}{effective_model}",
- tinyagents_harness::providers::claude_code::PROVIDER_PREFIX
- ),
- egress,
- );
- let chat = match tinyagents_harness::providers::claude_code::ClaudeCodeProvider::from_env(
- effective_model,
- workspace,
- config.action_dir.clone(),
- ) {
- Ok(model) => Arc::new(model.with_mcp_provider(Arc::new(OpenHumanMcpEndpoint)))
- as Arc<dyn ChatModel<()>>,
- Err(error) => return Some(Err(error)),
- };
- Some(Ok((chat, configured_model)))
+ Some((|| {
+ if route.temperature.is_some() {
+ log::warn!(
+ "[providers][chat-factory] claude-code provider: per-model temperature override \
+ is accepted but not wired through to the CLI — the @<temp> suffix is ignored"
+ );
+ }
+ if route.model.is_empty() {
+ anyhow::bail!(
+ "[chat-factory] provider string '{}' for role '{}' has an empty model — \
+ use 'claude-code:<model-id>'",
+ provider,
+ role
+ );
+ }
+ let effective_model = model_override.unwrap_or(&route.model).to_owned();
+ emit_inference_egress(
+ role,
+ &format!(
+ "{}{effective_model}",
+ tinyagents_harness::providers::claude_code::PROVIDER_PREFIX
+ ),
+ egress,
+ );
+ let workspace = config
+ .config_path
+ .parent()
+ .map(std::path::Path::to_path_buf)
+ .unwrap_or_else(|| config.workspace_dir.clone());
+ let model = tinyagents_harness::providers::claude_code::ClaudeCodeProvider::from_env(
+ effective_model,
+ workspace,
+ config.action_dir.clone(),
+ )?
+ .with_mcp_provider(Arc::new(OpenHumanMcpEndpoint));
+ Ok((Arc::new(model) as Arc<dyn ChatModel<()>>, route.model))
+ })())
}
#[derive(Debug)]