Skip to content

feat: allow inline model pinning for subagents#1896

Merged
senamakel merged 1 commit into
tinyhumansai:mainfrom
honor2030:feat/agent-inline-model-pinning
May 17, 2026
Merged

feat: allow inline model pinning for subagents#1896
senamakel merged 1 commit into
tinyhumansai:mainfrom
honor2030:feat/agent-inline-model-pinning

Conversation

@honor2030
Copy link
Copy Markdown
Contributor

@honor2030 honor2030 commented May 16, 2026

Summary

  • add an optional model parameter to spawn_subagent and archetype delegation tools
  • thread that inline model override through SubagentRunOptions and dispatch_subagent
  • resolve the child run with the parent provider/routing but the explicitly pinned model for that spawn
  • keep existing auto-routing/default behavior unchanged when model is omitted

Refs #1837

Tests

  • cargo fmt --all
  • RUSTC=/Users/lee/.rustup/toolchains/1.93.0-aarch64-apple-darwin/bin/rustc GGML_NATIVE=OFF cargo test -p openhuman --lib subagent_runner -- --nocapture
  • RUSTC=/Users/lee/.rustup/toolchains/1.93.0-aarch64-apple-darwin/bin/rustc GGML_NATIVE=OFF cargo test -p openhuman --lib spawn_subagent -- --nocapture
  • RUSTC=/Users/lee/.rustup/toolchains/1.93.0-aarch64-apple-darwin/bin/rustc GGML_NATIVE=OFF cargo test -p openhuman --lib archetype_delegation -- --nocapture
  • RUSTC=/Users/lee/.rustup/toolchains/1.93.0-aarch64-apple-darwin/bin/rustc GGML_NATIVE=OFF cargo check -p openhuman
  • git diff --check

Summary by CodeRabbit

Release Notes

  • New Features
    • Subagent spawning now accepts an optional model parameter, allowing you to pin delegated tasks to a specific model of your choice.
    • Child agent execution can override model selection while preserving parent provider routing and configuration.

Review Change Stack

@honor2030 honor2030 requested a review from a team May 16, 2026 07:29
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 16, 2026

📝 Walkthrough

Walkthrough

This PR adds per-spawn model pinning to subagent execution. A new model_override field in SubagentRunOptions allows callers to pin a subagent to a specific model while preserving provider/routing. The resolver early-exits when an override is present; tools like spawn_subagent and archetype_delegation now expose model as a parameter.

Changes

Subagent Model Override

Layer / File(s) Summary
Core type and model-override resolver
src/openhuman/agent/harness/subagent_runner/types.rs, src/openhuman/agent/harness/subagent_runner/ops.rs
SubagentRunOptions gains optional model_override field; resolve_subagent_provider accepts the override parameter and returns early with parent provider + override model when present and non-empty, bypassing ModelSpec resolution.
Dispatcher layer model override
src/openhuman/tools/impl/agent/dispatch.rs, src/openhuman/tools/impl/agent/archetype_delegation.rs
dispatch_subagent signature updated to accept model_override: Option<&str> and populate SubagentRunOptions; archetype delegation tool parses optional model from arguments and forwards through dispatcher.
SpawnSubagentTool model parameter
src/openhuman/tools/impl/agent/spawn_subagent.rs
Tool schema extended with optional model property; execute parses trimmed, non-empty model argument and forwards via SubagentRunOptions.model_override; test validates schema advertisement.
Wiring in supporting tools
src/openhuman/tools/impl/agent/skill_delegation.rs, src/openhuman/tools/impl/agent/spawn_parallel_agents.rs, src/openhuman/tools/impl/agent/spawn_worker_thread.rs
Skill delegation, parallel agents, and worker thread tools explicitly set model_override: None when constructing SubagentRunOptions; skill delegation call refactored to multi-line layout.
Test infrastructure and feature coverage
src/openhuman/agent/harness/subagent_runner/ops_tests.rs
Test double ScriptedProvider updated to capture model strings; new test cases for model override pinning and spawn-override precedence; existing resolver and typed-mode tests updated to match new signature.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Possibly related PRs

  • tinyhumansai/openhuman#1858: Extends the subagent provider/model resolution pipeline introduced in #1858 by adding inline model override that pins the spawned model while preserving the resolved provider.

Suggested reviewers

  • senamakel

Poem

🐰 A hop and a model to pin,
Through dispatcher chains, the override wins,
Subagents now choose their own brain,
While routing flows through the old lane,
One spawn, one model—simple and plain!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: allow inline model pinning for subagents' clearly and concisely summarizes the main change: enabling inline model override capability for subagents across multiple files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
src/openhuman/agent/harness/subagent_runner/ops.rs (2)

115-120: ⚡ Quick win

Use debug-level structured tracing for override-branch diagnostics.

This is verbose branch telemetry; keep it at debug/trace and structured fields for consistent grepability.

Suggested patch
-        log::info!(
-            "[subagent_runner] agent_id={} using inline model override model={}",
-            agent_id,
-            model
-        );
+        tracing::debug!(
+            agent_id = %agent_id,
+            model = %model,
+            "[subagent_runner] using inline model override"
+        );

As per coding guidelines "src/**/*.rs: Rust core code must use log / tracing at debug / trace levels for verbose diagnostics on new/changed flows...".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/openhuman/agent/harness/subagent_runner/ops.rs` around lines 115 - 120,
Current info-level log in the override branch is too verbose; change the log to
a debug/trace structured call and keep the rest of the logic unchanged: replace
the log::info! in the override branch (the site that logs agent_id and model
before returning (parent_provider, model.to_string())) with a debug or
trace-level structured log (e.g., tracing::debug! or log::debug!) emitting
agent_id and model as named fields (agent_id=? or agent_id=%agent_id,
model=%model) so diagnostics are lower-volume and grepable.

294-302: ⚡ Quick win

Skip config load when a non-empty model_override is already present.

The override branch bypasses ModelSpec resolution, but Config::load_or_init() still runs unconditionally first. That adds avoidable I/O/latency for pinned spawns.

Suggested patch
-    let config_loaded = crate::openhuman::config::Config::load_or_init().await;
+    let model_override = options.model_override.as_deref();
+    let config_loaded = if model_override
+        .map(str::trim)
+        .filter(|model| !model.is_empty())
+        .is_some()
+    {
+        None
+    } else {
+        crate::openhuman::config::Config::load_or_init().await.ok()
+    };
     let (subagent_provider, model) = resolve_subagent_provider(
         &definition.model,
         &definition.id,
-        config_loaded.as_ref().ok(),
+        config_loaded.as_ref(),
         parent.provider.clone(),
         parent.model_name.clone(),
-        options.model_override.as_deref(),
+        model_override,
     );
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/openhuman/agent/harness/subagent_runner/ops.rs` around lines 294 - 302,
If options.model_override is present and non-empty, avoid the unnecessary
Config::load_or_init() call by short-circuiting and passing None for the config
parameter to resolve_subagent_provider; i.e., check
options.model_override.as_deref().map(|s| !s.is_empty()).unwrap_or(false) and
only call crate::openhuman::config::Config::load_or_init().await when that check
is false, then pass the resulting config as before (config_loaded.as_ref().ok())
or None when skipped so resolve_subagent_provider(&definition.model,
&definition.id, /*config*/ , parent.provider.clone(), parent.model_name.clone(),
options.model_override.as_deref()) receives no config when a model_override is
provided.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/openhuman/agent/harness/subagent_runner/ops.rs`:
- Around line 115-120: Current info-level log in the override branch is too
verbose; change the log to a debug/trace structured call and keep the rest of
the logic unchanged: replace the log::info! in the override branch (the site
that logs agent_id and model before returning (parent_provider,
model.to_string())) with a debug or trace-level structured log (e.g.,
tracing::debug! or log::debug!) emitting agent_id and model as named fields
(agent_id=? or agent_id=%agent_id, model=%model) so diagnostics are lower-volume
and grepable.
- Around line 294-302: If options.model_override is present and non-empty, avoid
the unnecessary Config::load_or_init() call by short-circuiting and passing None
for the config parameter to resolve_subagent_provider; i.e., check
options.model_override.as_deref().map(|s| !s.is_empty()).unwrap_or(false) and
only call crate::openhuman::config::Config::load_or_init().await when that check
is false, then pass the resulting config as before (config_loaded.as_ref().ok())
or None when skipped so resolve_subagent_provider(&definition.model,
&definition.id, /*config*/ , parent.provider.clone(), parent.model_name.clone(),
options.model_override.as_deref()) receives no config when a model_override is
provided.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 282fb8cb-13bc-49ee-9c78-d05fa4f6662a

📥 Commits

Reviewing files that changed from the base of the PR and between bd5c2ed and 5d28cc8.

📒 Files selected for processing (9)
  • src/openhuman/agent/harness/subagent_runner/ops.rs
  • src/openhuman/agent/harness/subagent_runner/ops_tests.rs
  • src/openhuman/agent/harness/subagent_runner/types.rs
  • src/openhuman/tools/impl/agent/archetype_delegation.rs
  • src/openhuman/tools/impl/agent/dispatch.rs
  • src/openhuman/tools/impl/agent/skill_delegation.rs
  • src/openhuman/tools/impl/agent/spawn_parallel_agents.rs
  • src/openhuman/tools/impl/agent/spawn_subagent.rs
  • src/openhuman/tools/impl/agent/spawn_worker_thread.rs

@senamakel senamakel merged commit 7a7c899 into tinyhumansai:main May 17, 2026
24 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants