hermes-agent/tests/cli/test_moa_command.py
Teknium c6575df927
feat(moa): expose MoA presets as selectable virtual models (#46081)
* feat(moa): expose MoA presets as selectable virtual models

Reconstructed onto current main (PR #46081's base had diverged with no common
ancestor, marking the PR dirty so CI never dispatched). MoA is now a virtual
provider: each named preset is a selectable model under provider 'moa', and the
preset's aggregator is the acting model that answers and calls tools.

Reference models fan out in parallel via a bounded ThreadPoolExecutor (the same
batch pattern delegate_task uses) — all references dispatched at once, collected
when every one finishes, then handed to the aggregator. Output order is
preserved, failures and the MoA-recursion guard stay isolated per reference.

- Removed the old mixture_of_agents model tool and moa toolset.
- Added moa as a virtual provider in the provider/model inventory.
- /moa is shortcut behavior over model selection (default preset / named preset
  / one-shot prompt).
- Dashboard + Desktop manage named presets; presets appear in model pickers.
- Parallel reference fan-out in agent/moa_loop.py with regression test.

* fix(moa): thread moa_config through _run_agent to _run_agent_inner

The reconstructed gateway MoA wiring declared moa_config on _run_agent (the
profile-scoping wrapper) and used it inside _run_agent_inner, but the wrapper
never forwarded it — _run_agent_inner had no such parameter, so the runtime hit
NameError: name 'moa_config' is not defined on the compression-failure session
sync path. Add moa_config to _run_agent_inner's signature and forward it from
both wrapper call sites (multiplex and non-multiplex). Caught by
tests/gateway/test_compression_failure_session_sync.py on CI shard test(4).

* fix(moa): classify moa as a virtual provider in the catalog

The moa virtual provider has no PROVIDER_REGISTRY/ProviderProfile entry, so
provider_catalog() fell through to the default auth_type="api_key" with no
env vars — tripping two catalog invariants:
  - test_provider_catalog: api_key providers must expose a credential env var
  - test_provider_parity: every hermes-model provider must be desktop-configurable

moa already declares auth_type="virtual" in HERMES_OVERLAYS; consult that
overlay as an auth_type fallback so the catalog reports moa as virtual (no real
credential, no network endpoint). Exempt virtual providers from the desktop
parity union check the same way 'custom' is exempt — derived from the catalog,
not a hardcoded slug, so future virtual providers are covered too.
2026-06-25 13:52:06 -07:00

69 lines
2.3 KiB
Python

import queue
from unittest.mock import patch
from cli import HermesCLI
from hermes_cli.moa_config import decode_moa_turn
def _make_cli():
cli = HermesCLI.__new__(HermesCLI)
cli.config = {
"moa": {
"default_preset": "default",
"presets": {
"default": {
"reference_models": [{"provider": "openai-codex", "model": "gpt-5.5"}],
"aggregator": {"provider": "openrouter", "model": "anthropic/claude-opus-4.8"},
},
"review": {
"reference_models": [{"provider": "openrouter", "model": "deepseek/deepseek-v4-pro"}],
"aggregator": {"provider": "openrouter", "model": "anthropic/claude-opus-4.8"},
},
},
}
}
cli._pending_input = queue.Queue()
cli._pending_agent_seed = None
cli._pending_moa_config = None
cli._agent_running = False
cli.agent = None
return cli
def test_moa_bare_switches_to_default_preset_model():
cli = _make_cli()
with patch("cli._cprint"):
assert cli.process_command("/moa") is True
assert cli.provider == "moa"
assert cli.requested_provider == "moa"
assert cli.model == "default"
assert cli.agent is None
def test_moa_exact_preset_switches_to_named_preset_model():
cli = _make_cli()
with patch("cli._cprint"):
cli.process_command("/moa review")
assert cli.provider == "moa"
assert cli.model == "review"
assert cli.agent is None
def test_moa_non_preset_is_one_shot_prompt():
cli = _make_cli()
with patch("cli._cprint"):
cli.process_command("/moa inspect the flaky test")
assert cli._pending_agent_seed == "inspect the flaky test"
assert cli._pending_moa_disable_after_turn is True
assert cli.provider == "moa"
assert cli.model == "default"
assert cli._pending_moa_restore_model["provider"] != "moa"
def test_decode_legacy_encoded_moa_turn_still_works():
from hermes_cli.moa_config import build_moa_turn_prompt
encoded = build_moa_turn_prompt("hello", _make_cli().config["moa"], preset="review")
prompt, cfg = decode_moa_turn(encoded)
assert prompt == "hello"
assert cfg["reference_models"] == [{"provider": "openrouter", "model": "deepseek/deepseek-v4-pro"}]