agentscope-ai / agentscope-ai/QwenPaw

[Feature]: spawn_subagent support for per-task model selection (multi-model collaboration)

Offen
#4,901 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
enhancement
Vorherrschende Sprache
Python
Sterne
34.9k
Forks
3.1k
Ø Merge
1 T. 15 Std.
Gemergte PRs (30 T.)
225

Beschreibung

## Summary

Allow `spawn_subagent` to run sub-tasks with a different model than the parent agent — cheap models for simple tasks (grep, file reads), main model for complex reasoning — to save token costs. Inspired by Claude Code's Haiku/Opus task dispatch pattern.

## Component(s) Affected

- [x] Core / Backend (app, agents, config, providers, utils, local_models)
- [ ] Console (frontend web UI)
- [ ] Channels
- [ ] Skills
- [ ] CLI
- [ ] Documentation (website)
- [ ] Tests
- [ ] CI/CD
- [ ] Scripts / Deploy

## Problem / Motivation

Currently `spawn_subagent` always uses the same model as the parent agent. But many sub-tasks are lightweight — grep searches, reading config files, listing directories — which a cheap model handles perfectly well. Running them on the main model (DeepSeek V4 Pro, Claude Opus, etc.) is wasteful.

Claude Code handles this by routing simple tool calls (grep, read) to Haiku and complex reasoning to Opus. For cost-conscious users, this is essential.

## Proposed Solution

Two approaches, could be phased:

**Phase 1 (MVP): Add an explicit `model` parameter to spawn_subagent**

```python
spawn_subagent(
task="grep for XXX",
model="haiku", # new: model name or local/cloud slot
...
)
```

Pass through `request_context` (same pattern as the existing `fork_project_dir`), and in the runner, override the agent's ChatModel per session. Minimal diff (~30 lines, 3 files), explicit user control.

**Phase 2 (ideal): Task-complexity-aware automatic routing**

Automatically assign models based on task complexity — simple tasks (short prompt, no reasoning required) get a cheaper model, complex tasks get the main model. The existing `RoutingPolicy.decide()` already accepts `text` as input for content-aware decisions, providing a natural hook for this logic. Could add an `auto_route_subagent: bool` toggle in `AgentsLLMRoutingConfig`.

## Alternatives Considered

- **Use `chat_with_agent` to a different agent**: works for model selection, but different workspace — can't share project files. `spawn_subagent`'s core value is same-workspace execution.
- **Manually create multiple agent instances**: too heavy, requires config changes each time.
- **Wait for QwenPaw to adopt AgentScope 2.0's Agent**: AgentScope 2.0's Agent is stateless and supports model switching natively, but the migration timeline is uncertain and the upper-layer integration still needs to be written anyway.

## Additional Context

- PR #4806 (spawn_subagent introduction) explicitly states "Inspired by Claude Code's subagent design"
- PR #849 (LLM routing framework) — `RoutingPolicy` comment says "Smarter switching can be added later without changing the dual-slot config shape" — the extension point is already in place
- AgentScope 2.0 recently released with a stateless Agent architecture that naturally supports multi-model switching

## Willing to Contribute

- [ ] I am willing to open a PR for this feature (after discussion).

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.