From 4e63dc8cb4be309dcb022baea2667e40a3f142c3 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 12 Nov 2026 13:35:52 +0000 Subject: [PATCH 1/4] test(inference): cover native tool calling opt-in for local runtimes Add tests asserting that local-openai endpoints report native tool calling only when the operator opts in, both at session assembly and on the built model profile, and that the local AI settings patch applies the flag. This guards against gateways misreading the text protocol's tool call bodies. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- .../config/ops_model_and_local_ai_tests.rs | 2 ++ .../factory_crate_native_diagnostics_tests.rs | 33 +++++++++++++++++++ .../src/inference/turn_models_native_tests.rs | 27 +++++++++++++++ 3 files changed, 62 insertions(+) diff --git a/crates/openhuman-core/src/config/ops_model_and_local_ai_tests.rs b/crates/openhuman-core/src/config/ops_model_and_local_ai_tests.rs index edd70e5e242..9f0b3b24dbc 100644 --- a/crates/openhuman-core/src/config/ops_model_and_local_ai_tests.rs +++ b/crates/openhuman-core/src/config/ops_model_and_local_ai_tests.rs @@ -544,6 +544,7 @@ async fn apply_local_ai_settings_updates_lm_studio_provider_fields() { chat_model_id: Some(" local-chat ".into()), usage_embeddings: Some(true), api_key: None, + native_tool_calling: Some(true), }; let outcome = apply_local_ai_settings(&mut cfg, patch) @@ -560,6 +561,7 @@ async fn apply_local_ai_settings_updates_lm_studio_provider_fields() { assert_eq!(cfg.local_ai.model_id, "local-default"); assert_eq!(cfg.local_ai.chat_model_id, "local-chat"); assert!(cfg.local_ai.usage.embeddings); + assert!(cfg.local_ai.native_tool_calling); assert_eq!(outcome.value["config"]["local_ai"]["provider"], "lm_studio"); let clear_and_fallback = LocalAiSettingsPatch { diff --git a/crates/openhuman-core/src/inference/provider/factory_crate_native_diagnostics_tests.rs b/crates/openhuman-core/src/inference/provider/factory_crate_native_diagnostics_tests.rs index b3752746e66..d9e362474a8 100644 --- a/crates/openhuman-core/src/inference/provider/factory_crate_native_diagnostics_tests.rs +++ b/crates/openhuman-core/src/inference/provider/factory_crate_native_diagnostics_tests.rs @@ -228,3 +228,36 @@ async fn non_openrouter_openai_compatible_endpoints_get_no_baked_provider_option ); } } + +/// The model the turn actually runs must carry the same choice as session +/// assembly (`TurnModelSource::supports_native_tool_calling`): a profile with +/// `tool_calling = false` makes the harness strip `tools` off the wire and +/// fall back to the text protocol, whatever the prompt says. +#[tokio::test] +async fn local_openai_model_calls_tools_natively_only_when_opted_in() { + let _guard = crate::inference::inference_test_guard_async().await; + let _storage = crate::storage::test_support::install_backend_for_test( + crate::storage::test_support::memory_backend(), + ); + let _signed_out = crate::platform::llm_gate::SignedOutTestGuard::set(true); + let dir = tempfile::tempdir().unwrap(); + let mut config = Config { + config_path: dir.path().join("config.toml"), + workspace_dir: dir.path().join("workspace"), + ..Config::default() + }; + let tool_calling = |config: &Config| { + let config = config.clone(); + async move { + create_chat_model_from_string("chat", "local-openai:glm-5.3-flash", &config, 0.0) + .await + .expect("local-openai builds") + .profile() + .expect("local-openai exposes a profile") + .tool_calling + } + }; + assert!(!tool_calling(&config).await, "off by default"); + config.local_ai.native_tool_calling = true; + assert!(tool_calling(&config).await, "on when opted in"); +} diff --git a/crates/openhuman-core/src/inference/turn_models_native_tests.rs b/crates/openhuman-core/src/inference/turn_models_native_tests.rs index 3e32315640b..504a36618f7 100644 --- a/crates/openhuman-core/src/inference/turn_models_native_tests.rs +++ b/crates/openhuman-core/src/inference/turn_models_native_tests.rs @@ -366,3 +366,30 @@ async fn injected_turn_without_profile_keeps_conservative_capabilities() { assert_eq!(models.context_window(), None); assert!(models.primary.profile().is_none()); } + +/// A `local-openai` endpoint can front a hosted gateway whose model calls +/// tools natively (Teeny's builder: `glm-5.3-flash` on Surplus). Driven with +/// the JSON-in-tag text protocol there, the gateway read each `` +/// body as the tool's *name*, so every call after the first failed with +/// ``unknown tool `{"arguments": …, "name": "shell"}` ``. Session assembly +/// must report native tools for a local runtime once the operator opts in, +/// and only then. +#[test] +fn a_local_runtime_reports_native_tools_only_when_opted_in() { + let ctx = crate::core::runtime::DispatchCtx::unbound(); + let mut config = crate::config::Config::default(); + let source = |config: &crate::config::Config| { + TurnModelSource::new_crate_native_from_string( + &ctx, + "chat", + "local-openai:glm-5.3-flash", + Arc::new(config.clone()), + ) + }; + assert!( + !source(&config).supports_native_tool_calling(), + "local runtimes stay on the text protocol by default" + ); + config.local_ai.native_tool_calling = true; + assert!(source(&config).supports_native_tool_calling()); +} From 6c410264d6e17c54ff500f45e597777f408e4eaf Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 12 Nov 2026 13:38:41 +0000 Subject: [PATCH 2/4] feat(inference): add native tool calling option for local runtimes Adds a `native_tool_calling` setting to the local AI config, exposed through the settings update RPC and schema, which sends native `tools` to the local runtime and reads structured tool calls instead of the JSON-in-tag text protocol. It defaults to off because many Ollama and LM Studio models reject or mishandle `tools`, but hosted OpenAI-compatible gateways behind `local-openai` need it since their template parsing can return the tool body as the tool name. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/openhuman-core/src/config/ops/model.rs | 6 ++++++ crates/openhuman-core/src/config/schema/local_ai.rs | 13 +++++++++++++ .../src/config/schemas/controllers/inference.rs | 1 + crates/openhuman-core/src/config/schemas/helpers.rs | 1 + .../src/config/schemas/schema_defs/inference.rs | 4 ++++ .../src/inference/provider/factory/local_runtime.rs | 5 +++-- .../openhuman-core/src/inference/schemas/catalog.rs | 4 ++++ .../src/inference/schemas/settings_handlers.rs | 2 ++ crates/openhuman-core/src/inference/turn_models.rs | 13 +++++++++++-- vendor/tinyagents | 2 +- 10 files changed, 46 insertions(+), 5 deletions(-) diff --git a/crates/openhuman-core/src/config/ops/model.rs b/crates/openhuman-core/src/config/ops/model.rs index 1db518d8c3c..a155aa6570e 100644 --- a/crates/openhuman-core/src/config/ops/model.rs +++ b/crates/openhuman-core/src/config/ops/model.rs @@ -100,6 +100,8 @@ pub struct LocalAiSettingsPatch { pub chat_model_id: Option, pub usage_embeddings: Option, pub api_key: Option, + /// See [`crate::config::schema::LocalAiConfig::native_tool_calling`]. + pub native_tool_calling: Option, } /// Updates the model-related settings in the configuration. @@ -442,6 +444,10 @@ pub async fn apply_local_ai_settings( if let Some(v) = update.usage_embeddings { config.local_ai.usage.embeddings = v; } + if let Some(v) = update.native_tool_calling { + config.local_ai.native_tool_calling = v; + log::info!("[config][local_ai] native_tool_calling={v}"); + } if let Some(api_key) = update.api_key { let trimmed = api_key.trim(); config.local_ai.api_key = if trimmed.is_empty() { diff --git a/crates/openhuman-core/src/config/schema/local_ai.rs b/crates/openhuman-core/src/config/schema/local_ai.rs index 535131f9436..411b1296226 100644 --- a/crates/openhuman-core/src/config/schema/local_ai.rs +++ b/crates/openhuman-core/src/config/schema/local_ai.rs @@ -94,6 +94,17 @@ pub struct LocalAiConfig { /// All default to `false` (cloud path). #[serde(default)] pub usage: LocalAiUsage, + /// Send native `tools` to the local runtime and read its structured tool + /// calls, instead of prompting the JSON-in-tag text protocol. + /// + /// Off by default: many models on Ollama / LM Studio reject `tools` or + /// answer them badly. Turn it on for an endpoint whose model calls tools + /// natively, typically a hosted OpenAI-compatible gateway behind + /// `local-openai`. Such a gateway may also parse `` text in the + /// model's own template and hand the JSON-in-tag body back as the tool's + /// *name*, so the text protocol is not a safe fallback there. + #[serde(default)] + pub native_tool_calling: bool, } impl std::fmt::Debug for LocalAiConfig { @@ -118,6 +129,7 @@ impl std::fmt::Debug for LocalAiConfig { .field("voice_llm_cleanup_enabled", &self.voice_llm_cleanup_enabled) .field("num_ctx", &self.num_ctx) .field("usage", &self.usage) + .field("native_tool_calling", &self.native_tool_calling) .finish() } } @@ -202,6 +214,7 @@ impl Default for LocalAiConfig { voice_llm_cleanup_enabled: default_voice_llm_cleanup_enabled(), num_ctx: None, usage: LocalAiUsage::default(), + native_tool_calling: false, } } } diff --git a/crates/openhuman-core/src/config/schemas/controllers/inference.rs b/crates/openhuman-core/src/config/schemas/controllers/inference.rs index 8e911e9250e..a024ebe02e1 100644 --- a/crates/openhuman-core/src/config/schemas/controllers/inference.rs +++ b/crates/openhuman-core/src/config/schemas/controllers/inference.rs @@ -226,6 +226,7 @@ pub(super) fn handle_update_local_ai_settings( chat_model_id: update.chat_model_id, usage_embeddings: update.usage_embeddings, api_key: update.api_key, + native_tool_calling: update.native_tool_calling, }; to_json(config_rpc::load_and_apply_local_ai_settings(&ctx, patch).await?) }) diff --git a/crates/openhuman-core/src/config/schemas/helpers.rs b/crates/openhuman-core/src/config/schemas/helpers.rs index b674d4a774c..52584a2de99 100644 --- a/crates/openhuman-core/src/config/schemas/helpers.rs +++ b/crates/openhuman-core/src/config/schemas/helpers.rs @@ -143,6 +143,7 @@ pub(super) struct LocalAiSettingsUpdate { pub(super) chat_model_id: Option, pub(super) usage_embeddings: Option, pub(super) api_key: Option, + pub(super) native_tool_calling: Option, } #[derive(Debug, Deserialize)] diff --git a/crates/openhuman-core/src/config/schemas/schema_defs/inference.rs b/crates/openhuman-core/src/config/schemas/schema_defs/inference.rs index a3415262501..ca45337cfa0 100644 --- a/crates/openhuman-core/src/config/schemas/schema_defs/inference.rs +++ b/crates/openhuman-core/src/config/schemas/schema_defs/inference.rs @@ -197,6 +197,10 @@ pub(super) fn lookup(function: &str) -> Option { "usage_embeddings", "Use the local model for embedding generation (when runtime_enabled).", ), + optional_bool( + "native_tool_calling", + "Send native tools to the local runtime instead of the text tool protocol. For endpoints whose model calls tools natively.", + ), ], outputs: vec![json_output("snapshot", "Updated config snapshot.")], }), diff --git a/crates/openhuman-core/src/inference/provider/factory/local_runtime.rs b/crates/openhuman-core/src/inference/provider/factory/local_runtime.rs index 266cdcf381e..11620713c8d 100644 --- a/crates/openhuman-core/src/inference/provider/factory/local_runtime.rs +++ b/crates/openhuman-core/src/inference/provider/factory/local_runtime.rs @@ -5,7 +5,7 @@ use super::*; use crate::inference::provider::factory::access_gates::{ enforce_local_only_endpoint, is_loopback_endpoint, is_ollama_cloud_model, LocalOnlyRequestGuard, }; -use tinyinference_llm::providers::openai::build_local_runtime_chat_model; +use tinyinference_llm::providers::openai::build_local_runtime_chat_model_with_native_tools; use tinyinference_llm::providers::openai::AuthStyle as CompatAuthStyle; /// Local OpenAI-compatible runtimes (Ollama / LM Studio / MLX / OMLX / @@ -153,7 +153,7 @@ fn try_create_local_runtime_chat_model_from_string_with_identity( "[chat-factory] local runtime resolved slug={}", resolved.kind.as_str() ); - let chat = build_local_runtime_chat_model( + let chat = build_local_runtime_chat_model_with_native_tools( resolved.kind.as_str(), &resolved.endpoint, &resolved.api_key, @@ -162,6 +162,7 @@ fn try_create_local_runtime_chat_model_from_string_with_identity( &config.temperature_unsupported_models, resolved.temperature, resolved.num_ctx, + config.local_ai.native_tool_calling, ); let chat: Arc> = Arc::new(LocalOnlyRequestGuard { inner: chat, diff --git a/crates/openhuman-core/src/inference/schemas/catalog.rs b/crates/openhuman-core/src/inference/schemas/catalog.rs index 4f35c16a509..16f71031bf5 100644 --- a/crates/openhuman-core/src/inference/schemas/catalog.rs +++ b/crates/openhuman-core/src/inference/schemas/catalog.rs @@ -129,6 +129,10 @@ pub fn schemas(function: &str) -> ControllerSchema { "usage_embeddings", "Whether embeddings workload may use the local provider.", ), + optional_bool( + "native_tool_calling", + "Whether the local provider gets native tools instead of the text tool protocol.", + ), ], outputs: vec![json_output("snapshot", "Updated config snapshot.")], }, diff --git a/crates/openhuman-core/src/inference/schemas/settings_handlers.rs b/crates/openhuman-core/src/inference/schemas/settings_handlers.rs index 1a674520370..46c5c94081a 100644 --- a/crates/openhuman-core/src/inference/schemas/settings_handlers.rs +++ b/crates/openhuman-core/src/inference/schemas/settings_handlers.rs @@ -55,6 +55,7 @@ pub(super) struct InferenceUpdateLocalSettingsParams { chat_model_id: Option, usage_embeddings: Option, api_key: Option, + native_tool_calling: Option, } #[derive(Debug, Deserialize)] @@ -186,6 +187,7 @@ pub(super) fn handle_inference_update_local_settings( chat_model_id: update.chat_model_id, usage_embeddings: update.usage_embeddings, api_key: update.api_key, + native_tool_calling: update.native_tool_calling, }; to_json(crate::inference::ops::inference_update_local_settings(&ctx, patch).await?) }) diff --git a/crates/openhuman-core/src/inference/turn_models.rs b/crates/openhuman-core/src/inference/turn_models.rs index 9a28e6af593..719ffc7bd6d 100644 --- a/crates/openhuman-core/src/inference/turn_models.rs +++ b/crates/openhuman-core/src/inference/turn_models.rs @@ -336,7 +336,7 @@ impl TurnModelSource { .unwrap_or_else(|| { crate::inference::provider::provider_for_role(&source.role, &source.config) }); - return !tinyinference_local::profile::is_local_provider_string(&provider_string); + return provider_string_native_tools(&provider_string, &source.config); } false } @@ -609,7 +609,7 @@ impl TurnModelSource { }; ( provider_id, - !is_local, + provider_string_native_tools(&provider_string, &cn.config), !is_local, is_local, self_hosted, @@ -711,6 +711,15 @@ impl TurnModelSource { } } +/// Whether a provider string's model gets native tools: cloud providers do; a +/// local runtime does only when the operator opted in with +/// `local_ai.native_tool_calling`. The local-runtime model factory reads the +/// same flag, so session assembly, the harness dialect and the wire agree. +fn provider_string_native_tools(provider_string: &str, config: &crate::config::Config) -> bool { + !tinyinference_local::profile::is_local_provider_string(provider_string) + || config.local_ai.native_tool_calling +} + #[cfg(test)] #[path = "turn_models_tests.rs"] mod tests; diff --git a/vendor/tinyagents b/vendor/tinyagents index 6d1416d1bc4..232d2d6706c 160000 --- a/vendor/tinyagents +++ b/vendor/tinyagents @@ -1 +1 @@ -Subproject commit 6d1416d1bc49d6e160449227dfb51927dc4a78e2 +Subproject commit 232d2d6706c865d37b9f41afd3fa0da629f84bff From d9c0b19d93e90c5fdd7fb861ef2e13eefc51363b Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 12 Nov 2026 14:02:37 +0000 Subject: [PATCH 3/4] chore(vendor): move tinyagents to 2ccc25c (#612 and #613 merged) Co-authored-by: Medulla --- vendor/tinyagents | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/tinyagents b/vendor/tinyagents index 232d2d6706c..2ccc25c6788 160000 --- a/vendor/tinyagents +++ b/vendor/tinyagents @@ -1 +1 @@ -Subproject commit 232d2d6706c865d37b9f41afd3fa0da629f84bff +Subproject commit 2ccc25c6788e338950db53072a6e2109722ec88b From 85e21d441ca0d9803871b5cdcd6a427418518ac6 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 12 Nov 2026 14:06:55 +0000 Subject: [PATCH 4/4] docs(about_app): describe the local native tool-call opt-in; test the cloud half Co-authored-by: Medulla --- .../src/inference/turn_models_native_tests.rs | 9 +++++++++ .../about_app/catalog_localai_settings_mobile.rs | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/openhuman-core/src/inference/turn_models_native_tests.rs b/crates/openhuman-core/src/inference/turn_models_native_tests.rs index 504a36618f7..97052a5d59d 100644 --- a/crates/openhuman-core/src/inference/turn_models_native_tests.rs +++ b/crates/openhuman-core/src/inference/turn_models_native_tests.rs @@ -390,6 +390,15 @@ fn a_local_runtime_reports_native_tools_only_when_opted_in() { !source(&config).supports_native_tool_calling(), "local runtimes stay on the text protocol by default" ); + // A cloud provider calls tools natively whatever the local flag says. + let cloud = TurnModelSource::new_crate_native_from_string( + &ctx, + "chat", + "openai:gpt-4o", + Arc::new(config.clone()), + ); + assert!(cloud.supports_native_tool_calling()); + config.local_ai.native_tool_calling = true; assert!(source(&config).supports_native_tool_calling()); } diff --git a/crates/openhuman-core/src/platform/about_app/catalog_localai_settings_mobile.rs b/crates/openhuman-core/src/platform/about_app/catalog_localai_settings_mobile.rs index 5ef087b55f1..763e63f6ced 100644 --- a/crates/openhuman-core/src/platform/about_app/catalog_localai_settings_mobile.rs +++ b/crates/openhuman-core/src/platform/about_app/catalog_localai_settings_mobile.rs @@ -8,8 +8,8 @@ Capability { name: "Configure Local Provider", domain: "local_ai", category: CapabilityCategory::LocalAI, - description: "Point OpenHuman at a local runtime you run yourself: Ollama, LM Studio, MLX, oMLX, or a generic OpenAI-compatible server. OpenHuman does not install the runtime or download models; pull them in your runtime (e.g. `ollama pull `). Local chat inference does not require an OpenHuman account.", - how_to: "Connections → API keys → LLM, or use provider strings: ollama:, lmstudio:, mlx:, omlx:, local-openai:", + description: "Point OpenHuman at a local runtime you run yourself: Ollama, LM Studio, MLX, oMLX, or a generic OpenAI-compatible server. OpenHuman does not install the runtime or download models; pull them in your runtime (e.g. `ollama pull `). Local chat inference does not require an OpenHuman account. Local runtimes get tools through a text protocol in the prompt by default; an endpoint whose model calls tools natively (often a hosted gateway behind local-openai) can opt into native tool calls instead.", + how_to: "Connections → API keys → LLM, or use provider strings: ollama:, lmstudio:, mlx:, omlx:, local-openai:. Native tool calls are off by default; turn them on with `native_tool_calling: true` on the core `config_update_local_ai_settings` (or `inference_update_local_settings`) method, and off again before switching to a model that rejects native tools.", status: CapabilityStatus::Beta, privacy: None, },