feat(moa): move mixture of agents to slash command mode

This commit is contained in:
Teknium 2026-06-14 03:04:52 -07:00
parent 972a9885ee
commit 4c367df56f
No known key found for this signature in database
45 changed files with 1093 additions and 751 deletions

View file

@ -74,7 +74,7 @@ _POLISHED_TOOLS = {
"kanban_create", "kanban_show", "kanban_comment", "kanban_complete",
"kanban_block", "kanban_link", "kanban_heartbeat",
"yb_query_group_info", "yb_query_group_members", "yb_search_sticker",
"yb_send_dm", "yb_send_sticker", "mixture_of_agents",
"yb_send_dm", "yb_send_sticker",
}

View file

@ -441,6 +441,7 @@ def run_conversation(
task_id: str = None,
stream_callback: Optional[callable] = None,
persist_user_message: Optional[str] = None,
moa_config: Optional[dict[str, Any]] = None,
) -> Dict[str, Any]:
"""
Run a complete conversation with tool calling until completion.
@ -461,6 +462,19 @@ def run_conversation(
Returns:
Dict: Complete conversation result with final response and message history
"""
if moa_config is None:
try:
from hermes_cli.moa_config import decode_moa_turn
_decoded_message, _decoded_moa_config = decode_moa_turn(user_message)
if _decoded_moa_config is not None:
user_message = _decoded_message
moa_config = _decoded_moa_config
if persist_user_message is None:
persist_user_message = _decoded_message
except Exception:
pass
# ── Per-turn setup (the prologue) ──
# All once-per-turn setup — stdio guarding, retry-counter resets, user
# message sanitization, todo/nudge hydration, system-prompt restore-or-
@ -738,6 +752,29 @@ def run_conversation(
if effective_system:
api_messages = [{"role": "system", "content": effective_system}] + api_messages
if moa_config:
try:
from agent.moa_loop import aggregate_moa_context
_moa_context = aggregate_moa_context(
user_prompt=original_user_message if isinstance(original_user_message, str) else str(original_user_message),
api_messages=api_messages,
reference_models=moa_config.get("reference_models") or [],
aggregator=moa_config.get("aggregator") or {},
temperature=float(moa_config.get("reference_temperature", 0.6) or 0.6),
aggregator_temperature=float(moa_config.get("aggregator_temperature", 0.4) or 0.4),
max_tokens=int(moa_config.get("max_tokens", 4096) or 4096),
)
if _moa_context:
for _msg in reversed(api_messages):
if _msg.get("role") == "user":
_base = _msg.get("content", "")
if isinstance(_base, str):
_msg["content"] = _base + "\n\n" + _moa_context
break
except Exception as _moa_exc:
logger.warning("MoA context aggregation failed: %s", _moa_exc)
# Inject ephemeral prefill messages right after the system prompt
# but before conversation history. Same API-call-time-only pattern.
if agent.prefill_messages:

View file

@ -184,7 +184,7 @@ def build_tool_preview(tool_name: str, args: dict, max_len: int | None = None) -
"search_files": "pattern", "browser_navigate": "url",
"browser_click": "ref", "browser_type": "text",
"image_generate": "prompt", "text_to_speech": "text",
"vision_analyze": "question", "mixture_of_agents": "user_prompt",
"vision_analyze": "question",
"skill_view": "name", "skills_list": "category",
"cronjob": "action",
"execute_code": "code", "delegate_task": "goal",
@ -1015,8 +1015,6 @@ def get_cute_tool_message(
return _wrap(f"┊ 🔊 speak {_trunc(args.get('text', ''), 30)} {dur}")
if tool_name == "vision_analyze":
return _wrap(f"┊ 👁️ vision {_trunc(args.get('question', ''), 30)} {dur}")
if tool_name == "mixture_of_agents":
return _wrap(f"┊ 🧠 reason {_trunc(args.get('user_prompt', ''), 30)} {dur}")
if tool_name == "send_message":
return _wrap(f"┊ 📨 send {args.get('target', '?')}: \"{_trunc(args.get('message', ''), 25)}\" {dur}")
if tool_name == "cronjob":

114
agent/moa_loop.py Normal file
View file

@ -0,0 +1,114 @@
"""Mixture-of-Agents runtime helpers for /moa turns.
The slash command is deliberately not a model tool. It marks one user turn as
MoA-enabled; the normal Hermes agent loop still owns tool calling and turn
termination, while this module gathers reference-model context before each model
iteration.
"""
from __future__ import annotations
import logging
from typing import Any
from agent.auxiliary_client import call_llm
from agent.transports import get_transport
logger = logging.getLogger(__name__)
def _slot_label(slot: dict[str, str]) -> str:
return f"{slot.get('provider', '').strip()}:{slot.get('model', '').strip()}"
def _extract_text(response: Any) -> str:
try:
transport = get_transport("chat_completions")
if transport is None:
raise RuntimeError("chat_completions transport unavailable")
normalized = transport.normalize_response(response)
text = (normalized.content or "").strip()
if text:
return text
except Exception:
pass
try:
content = response.choices[0].message.content
return (content or "").strip()
except Exception:
return ""
def aggregate_moa_context(
*,
user_prompt: str,
api_messages: list[dict[str, Any]],
reference_models: list[dict[str, str]],
aggregator: dict[str, str],
temperature: float = 0.6,
aggregator_temperature: float = 0.4,
max_tokens: int = 4096,
) -> str:
"""Run configured reference models and synthesize their advice.
Failures are returned as model-specific notes instead of aborting the normal
agent loop; the main model can still act with partial context.
"""
reference_outputs: list[tuple[str, str]] = []
for slot in reference_models:
label = _slot_label(slot)
try:
response = call_llm(
task="moa_reference",
provider=slot["provider"],
model=slot["model"],
messages=api_messages,
temperature=temperature,
max_tokens=max_tokens,
)
text = _extract_text(response)
reference_outputs.append((label, text or "(empty response)"))
except Exception as exc:
logger.warning("MoA reference model %s failed: %s", label, exc)
reference_outputs.append((label, f"[failed: {exc}]"))
joined = "\n\n".join(
f"Reference {idx} — {label}:\n{text}"
for idx, (label, text) in enumerate(reference_outputs, start=1)
)
synth_prompt = (
"You are the aggregator in a Mixture of Agents process. Synthesize the "
"reference responses into concise, actionable guidance for the main "
"Hermes agent. Focus on next steps, tool-use strategy, risks, and any "
"disagreements. Do not answer the user directly unless that is all that "
"is needed; produce context the main agent should use in its normal loop.\n\n"
f"Original user prompt:\n{user_prompt}\n\n"
f"Reference responses:\n{joined}"
)
agg_label = _slot_label(aggregator)
try:
response = call_llm(
task="moa_aggregator",
provider=aggregator["provider"],
model=aggregator["model"],
messages=[{"role": "user", "content": synth_prompt}],
temperature=aggregator_temperature,
max_tokens=max_tokens,
)
synthesis = _extract_text(response)
except Exception as exc:
logger.warning("MoA aggregator model %s failed: %s", agg_label, exc)
synthesis = ""
if not synthesis:
synthesis = joined
return (
"[Mixture of Agents context — use this as private guidance for the "
"normal Hermes agent loop. You may call tools, continue reasoning, or "
"finish normally.]\n"
f"Aggregator: {agg_label}\n"
f"References: {', '.join(_slot_label(slot) for slot in reference_models)}\n\n"
f"{synthesis.strip()}"
)

View file

@ -7,11 +7,13 @@ import {
getAuxiliaryModels,
getGlobalModelInfo,
getGlobalModelOptions,
getMoaModels,
getRecommendedDefaultModel,
saveMoaModels,
setEnvVar,
setModelAssignment
} from '@/hermes'
import type { AuxiliaryModelsResponse, ModelOptionProvider, StaleAuxAssignment } from '@/hermes'
import type { AuxiliaryModelsResponse, MoaConfigResponse, MoaModelSlot, ModelOptionProvider, StaleAuxAssignment } from '@/hermes'
import { useI18n } from '@/i18n'
import { AlertTriangle, Cpu, Loader2 } from '@/lib/icons'
import { cn } from '@/lib/utils'
@ -97,6 +99,7 @@ export function ModelSettings({ onMainModelChanged }: ModelSettingsProps) {
const [selectedProvider, setSelectedProvider] = useState('')
const [selectedModel, setSelectedModel] = useState('')
const [auxiliary, setAuxiliary] = useState<AuxiliaryModelsResponse | null>(null)
const [moa, setMoa] = useState<MoaConfigResponse | null>(null)
const [applying, setApplying] = useState(false)
const [editingAuxTask, setEditingAuxTask] = useState<null | string>(null)
const [auxDraft, setAuxDraft] = useState<{ model: string; provider: string }>({ model: '', provider: '' })
@ -113,10 +116,11 @@ export function ModelSettings({ onMainModelChanged }: ModelSettingsProps) {
setError('')
try {
const [modelInfo, modelOptions, auxiliaryModels] = await Promise.all([
const [modelInfo, modelOptions, auxiliaryModels, moaModels] = await Promise.all([
getGlobalModelInfo(),
getGlobalModelOptions(),
getAuxiliaryModels()
getAuxiliaryModels(),
getMoaModels().catch(() => null)
])
setMainModel({ model: modelInfo.model, provider: modelInfo.provider })
@ -124,6 +128,7 @@ export function ModelSettings({ onMainModelChanged }: ModelSettingsProps) {
setSelectedProvider(prev => prev || modelInfo.provider)
setSelectedModel(prev => prev || modelInfo.model)
setAuxiliary(auxiliaryModels)
setMoa(moaModels)
} catch (err) {
setError(err instanceof Error ? err.message : String(err))
} finally {
@ -160,6 +165,35 @@ export function ModelSettings({ onMainModelChanged }: ModelSettingsProps) {
[auxDraft.provider, providers]
)
const modelsForProvider = useCallback(
(provider: string) => providers.find(row => row.slug === provider)?.models ?? [],
[providers]
)
const updateMoaSlot = useCallback((slot: MoaModelSlot, patch: Partial<MoaModelSlot>): MoaModelSlot => {
const next = { ...slot, ...patch }
if (patch.provider) {
next.model = ''
}
return next
}, [])
const saveMoa = useCallback(async (next: MoaConfigResponse) => {
setApplying(true)
setError('')
try {
const saved = await saveMoaModels(next)
setMoa(saved)
} catch (err) {
setError(err instanceof Error ? err.message : String(err))
} finally {
setApplying(false)
}
}, [])
const auxiliaryTaskLabel = useCallback((key: string) => m.tasks[key]?.label ?? key, [m.tasks])
// Persistent mismatch: any aux slot pinned to a provider different from the
@ -567,6 +601,62 @@ export function ModelSettings({ onMainModelChanged }: ModelSettingsProps) {
})}
</div>
</section>
{moa && (
<section>
<div className="mb-2.5 flex items-center justify-between">
<SectionHeading icon={Cpu} title="Mixture of Agents" />
<Button disabled={applying} onClick={() => void saveMoa(moa)} size="sm" variant="textStrong">
{applying ? m.applying : t.common.save}
</Button>
</div>
<p className="mb-2 text-xs text-muted-foreground">
Configure the provider/model slots used by /moa.
</p>
<div className="grid gap-1">
{moa.reference_models.map((slot, index) => (
<ListRow
below={
<div className="mt-2 flex flex-wrap items-center gap-2 pt-1">
<Select onValueChange={value => setMoa(prev => prev && ({ ...prev, reference_models: prev.reference_models.map((s, i) => i === index ? updateMoaSlot(s, { provider: value }) : s) }))} value={slot.provider}>
<SelectTrigger className={cn('min-w-32', CONTROL_TEXT)}><SelectValue placeholder={m.provider} /></SelectTrigger>
<SelectContent>{providerOptions.map(provider => <SelectItem key={provider.slug || 'none'} value={provider.slug || 'none'}>{provider.name}</SelectItem>)}</SelectContent>
</Select>
<Select onValueChange={value => setMoa(prev => prev && ({ ...prev, reference_models: prev.reference_models.map((s, i) => i === index ? updateMoaSlot(s, { model: value }) : s) }))} value={slot.model}>
<SelectTrigger className={cn('min-w-48', CONTROL_TEXT)}><SelectValue placeholder={m.model} /></SelectTrigger>
<SelectContent>{modelsForProvider(slot.provider).map(model => <SelectItem key={model} value={model}>{model}</SelectItem>)}</SelectContent>
</Select>
<Button disabled={moa.reference_models.length <= 1 || applying} onClick={() => setMoa(prev => prev && ({ ...prev, reference_models: prev.reference_models.filter((_, i) => i !== index) }))} size="sm" variant="ghost">
Remove
</Button>
</div>
}
description={<span className="font-mono text-[0.68rem]">{slot.provider} · {slot.model}</span>}
key={`${slot.provider}-${slot.model}-${index}`}
title={`Reference ${index + 1}`}
/>
))}
<Button disabled={applying} onClick={() => setMoa(prev => prev && ({ ...prev, reference_models: [...prev.reference_models, prev.aggregator] }))} size="sm" variant="textStrong">
Add reference model
</Button>
<ListRow
below={
<div className="mt-2 flex flex-wrap items-center gap-2 pt-1">
<Select onValueChange={value => setMoa(prev => prev && ({ ...prev, aggregator: updateMoaSlot(prev.aggregator, { provider: value }) }))} value={moa.aggregator.provider}>
<SelectTrigger className={cn('min-w-32', CONTROL_TEXT)}><SelectValue placeholder={m.provider} /></SelectTrigger>
<SelectContent>{providerOptions.map(provider => <SelectItem key={provider.slug || 'none'} value={provider.slug || 'none'}>{provider.name}</SelectItem>)}</SelectContent>
</Select>
<Select onValueChange={value => setMoa(prev => prev && ({ ...prev, aggregator: updateMoaSlot(prev.aggregator, { model: value }) }))} value={moa.aggregator.model}>
<SelectTrigger className={cn('min-w-48', CONTROL_TEXT)}><SelectValue placeholder={m.model} /></SelectTrigger>
<SelectContent>{modelsForProvider(moa.aggregator.provider).map(model => <SelectItem key={model} value={model}>{model}</SelectItem>)}</SelectContent>
</Select>
</div>
}
description={<span className="font-mono text-[0.68rem]">{moa.aggregator.provider} · {moa.aggregator.model}</span>}
title="Aggregator"
/>
</div>
</section>
)}
</div>
)
}

View file

@ -20,6 +20,7 @@ import type {
MessagingPlatformsResponse,
MessagingPlatformTestResponse,
MessagingPlatformUpdate,
MoaConfigResponse,
ModelAssignmentRequest,
ModelAssignmentResponse,
ModelInfoResponse,
@ -77,6 +78,8 @@ export type {
MessagingPlatformsResponse,
MessagingPlatformTestResponse,
MessagingPlatformUpdate,
MoaConfigResponse,
MoaModelSlot,
ModelAssignmentRequest,
ModelAssignmentResponse,
ModelInfoResponse,
@ -688,6 +691,22 @@ export function getAuxiliaryModels(): Promise<AuxiliaryModelsResponse> {
})
}
export function getMoaModels(): Promise<MoaConfigResponse> {
return window.hermesDesktop.api<MoaConfigResponse>({
...profileScoped(),
path: '/api/model/moa'
})
}
export function saveMoaModels(body: MoaConfigResponse): Promise<MoaConfigResponse & { ok: boolean }> {
return window.hermesDesktop.api<MoaConfigResponse & { ok: boolean }>({
...profileScoped(),
path: '/api/model/moa',
method: 'PUT',
body
})
}
export function setModelAssignment(body: ModelAssignmentRequest): Promise<ModelAssignmentResponse> {
return window.hermesDesktop.api<ModelAssignmentResponse>({
...profileScoped(),

View file

@ -639,6 +639,20 @@ export interface AuxiliaryModelsResponse {
tasks: AuxiliaryTaskAssignment[]
}
export interface MoaModelSlot {
provider: string
model: string
}
export interface MoaConfigResponse {
aggregator: MoaModelSlot
aggregator_temperature: number
enabled: boolean
max_tokens: number
reference_models: MoaModelSlot[]
reference_temperature: number
}
export interface ModelAssignmentRequest {
/** Optional API key for a custom/local endpoint. Persisted to model.api_key
* (where the runtime reads it) for self-hosted endpoints that require auth.

View file

@ -755,7 +755,6 @@ platform_toolsets:
# image_gen - image_generate (requires FAL_KEY)
# skills - skills_list, skill_view
# skills_hub - skill_hub (search/install/manage from online registries — user-driven only)
# moa - mixture_of_agents (requires OPENROUTER_API_KEY)
# todo - todo (in-memory task planning, no deps)
# tts - text_to_speech (Edge TTS free, or ELEVENLABS/OPENAI/MINIMAX/MISTRAL key)
# cronjob - cronjob (create/list/update/pause/resume/run/remove scheduled tasks)
@ -770,7 +769,7 @@ platform_toolsets:
#
# COMPOSITE:
# debugging - terminal + web + file
# safe - web + vision + moa (no terminal access)
# safe - web + vision (no terminal access)
# all - Everything available
#
# web - Web search and content extraction (web_search, web_extract)
@ -781,7 +780,6 @@ platform_toolsets:
# vision - Image analysis (vision_analyze)
# image_gen - Image generation with FLUX (image_generate)
# skills - Load skill documents (skills_list, skill_view)
# moa - Mixture of Agents reasoning (mixture_of_agents)
# todo - Task planning and tracking for multi-step work
# memory - Persistent memory across sessions (personal notes + user profile)
# session_search - Search and recall past conversations (FTS5 + Gemini Flash summarization)
@ -790,7 +788,7 @@ platform_toolsets:
#
# Composite toolsets:
# debugging - terminal + web + file (for troubleshooting)
# safe - web + vision + moa (no terminal access)
# safe - web + vision (no terminal access)
# NOTE: The top-level "toolsets" key is deprecated and ignored.
# Tool configuration is managed per-platform via platform_toolsets above.

14
cli.py
View file

@ -7641,6 +7641,17 @@ class HermesCLI(CLIAgentSetupMixin, CLICommandsMixin):
_cprint(f" No agent running; queued as next turn: {payload[:80]}{'...' if len(payload) > 80 else ''}")
elif canonical == "goal":
self._handle_goal_command(cmd_original)
elif canonical == "moa":
from hermes_cli.moa_config import build_moa_turn_prompt, moa_usage
parts = cmd_original.split(None, 1)
payload = parts[1].strip() if len(parts) > 1 else ""
if not payload:
_cprint(f" {moa_usage()}")
else:
self._pending_moa_config = self.config.get("moa") if isinstance(self.config, dict) else None
self._pending_agent_seed = payload
_cprint(" MoA mode queued for this turn.")
elif canonical == "subgoal":
self._handle_subgoal_command(cmd_original)
elif canonical == "skin":
@ -10231,6 +10242,8 @@ class HermesCLI(CLIAgentSetupMixin, CLICommandsMixin):
if _srn:
agent_message = _prepend_note_to_message(agent_message, _srn)
self._pending_skills_reload_note = None
_moa_cfg = getattr(self, "_pending_moa_config", None)
self._pending_moa_config = None
try:
result = self.agent.run_conversation(
user_message=agent_message,
@ -10238,6 +10251,7 @@ class HermesCLI(CLIAgentSetupMixin, CLICommandsMixin):
stream_callback=stream_callback,
task_id=self.session_id,
persist_user_message=message if _voice_prefix else None,
moa_config=_moa_cfg,
)
except Exception as exc:
logging.error("run_conversation raised: %s", exc, exc_info=True)

View file

@ -7002,6 +7002,9 @@ class GatewayRunner(GatewayAuthorizationMixin, GatewayKanbanWatchersMixin, Gatew
return await self._handle_goal_command(event)
return "Agent is running — use /goal status / pause / clear mid-run, or /stop before setting a new goal."
if _cmd_def_inner and _cmd_def_inner.name == "moa":
return "Agent is running — wait or /stop first, then run /moa."
# /subgoal is safe mid-run — it only modifies the goal's
# subgoals list, which the judge reads at the next turn
# boundary. No race with the running turn.
@ -7475,6 +7478,23 @@ class GatewayRunner(GatewayAuthorizationMixin, GatewayKanbanWatchersMixin, Gatew
if canonical == "goal":
return await self._handle_goal_command(event)
if canonical == "moa":
from hermes_cli.moa_config import build_moa_turn_prompt, moa_usage
from hermes_cli.config import load_config
moa_payload = event.get_command_args().strip()
if not moa_payload:
return moa_usage()
try:
cfg = load_config()
moa_cfg = cfg.get("moa") if isinstance(cfg, dict) else None
except Exception:
moa_cfg = None
try:
event.text = build_moa_turn_prompt(moa_payload, moa_cfg)
except Exception:
return "Failed to prepare MoA turn."
if canonical == "subgoal":
return await self._handle_subgoal_command(event)

View file

@ -107,6 +107,8 @@ COMMAND_REGISTRY: list[CommandDef] = [
args_hint="<prompt>"),
CommandDef("goal", "Set a standing goal Hermes works on across turns until achieved", "Session",
args_hint="[text | pause | resume | clear | status]"),
CommandDef("moa", "Run one prompt through configured Mixture of Agents models", "Session",
args_hint="<prompt>"),
CommandDef("subgoal", "Add or manage extra criteria on the active goal", "Session",
args_hint="[text | remove N | clear]"),
CommandDef("status", "Show session info", "Session"),
@ -1053,7 +1055,9 @@ _SLACK_PRIORITY_ALIASES = ("btw", "bg")
# the telegram-parity test reads it so an entry here is a deliberate
# "Slack-via-/hermes" decision, not a silent clamp.
# - credits: the billing/top-up surface; reached via /hermes credits on Slack.
_SLACK_VIA_HERMES_ONLY = frozenset({"credits"})
# - moa: high-cost slash mode, available through /hermes moa to avoid
# displacing existing native Slack slash commands at the 50-command cap.
_SLACK_VIA_HERMES_ONLY = frozenset({"credits", "moa"})
def _sanitize_slack_name(raw: str) -> str:

View file

@ -1390,6 +1390,22 @@ DEFAULT_CONFIG = {
"timeout": 60,
"extra_body": {},
},
"moa_reference": {
"provider": "auto",
"model": "",
"base_url": "",
"api_key": "",
"timeout": 600,
"extra_body": {},
},
"moa_aggregator": {
"provider": "auto",
"model": "",
"base_url": "",
"api_key": "",
"timeout": 600,
"extra_body": {},
},
},
"display": {
@ -1812,6 +1828,21 @@ DEFAULT_CONFIG = {
"max_turns": 20,
},
# Mixture of Agents — /moa <prompt> runs the normal Hermes agent loop,
# but injects guidance synthesized from these provider/model slots before
# each main-model iteration.
"moa": {
"reference_models": [
{"provider": "openai-codex", "model": "gpt-5.5"},
{"provider": "openrouter", "model": "deepseek/deepseek-v4-pro"},
],
"aggregator": {"provider": "openrouter", "model": "anthropic/claude-opus-4.8"},
"reference_temperature": 0.6,
"aggregator_temperature": 0.4,
"max_tokens": 4096,
"enabled": True,
},
# Skills — external skill directories for sharing skills across tools/agents.
# Each path is expanded (~, ${VAR}) and resolved. Read-only — skill creation
# always goes to ~/.hermes/skills/.
@ -2580,7 +2611,7 @@ OPTIONAL_ENV_VARS = {
"prompt": "OpenRouter API key",
"url": "https://openrouter.ai/keys",
"password": True,
"tools": ["vision_analyze", "mixture_of_agents"],
"tools": ["vision_analyze"],
"category": "provider",
"advanced": True,
},
@ -4120,7 +4151,7 @@ _KNOWN_ROOT_KEYS = {
"_config_version", "model", "providers", "fallback_model",
"fallback_providers", "credential_pool_strategies", "toolsets",
"agent", "terminal", "display", "compression", "delegation",
"auxiliary", "custom_providers", "context", "memory", "gateway",
"auxiliary", "moa", "custom_providers", "context", "memory", "gateway",
"sessions", "streaming", "updates", "mcp_servers",
}

View file

@ -10924,7 +10924,7 @@ _BUILTIN_SUBCOMMANDS = frozenset(
"computer-use",
"config", "cron", "curator", "dashboard", "debug", "doctor",
"dump", "fallback", "gateway", "hooks", "import", "insights",
"gui", "desktop", "kanban", "login", "logout", "logs", "lsp", "mcp", "memory", "migrate",
"gui", "desktop", "kanban", "login", "logout", "logs", "lsp", "mcp", "memory", "migrate", "moa",
"model", "pairing", "plugins", "portal", "postinstall", "profile", "proxy",
"prompt-size",
"send", "sessions", "setup",
@ -11449,6 +11449,18 @@ def main():
# =========================================================================
build_model_parser(subparsers, cmd_model=cmd_model)
from hermes_cli.moa_cmd import cmd_moa
moa_parser = subparsers.add_parser(
"moa",
help="Configure Mixture of Agents provider/model slots",
description="Configure the provider/model set used by /moa <prompt>.",
)
moa_subparsers = moa_parser.add_subparsers(dest="moa_command")
moa_subparsers.add_parser("list", aliases=["ls"], help="Show current MoA model slots")
moa_subparsers.add_parser("configure", aliases=["config"], help="Interactively pick MoA models")
moa_parser.set_defaults(func=cmd_moa)
# =========================================================================
# fallback command — manage the fallback provider chain
# =========================================================================

104
hermes_cli/moa_cmd.py Normal file
View file

@ -0,0 +1,104 @@
"""CLI helpers for configuring Mixture of Agents."""
from __future__ import annotations
from typing import Any
from hermes_cli.config import load_config, save_config
from hermes_cli.inventory import build_models_payload, load_picker_context
from hermes_cli.moa_config import normalize_moa_config
def _prompt_choice(title: str, rows: list[str], default: int = 0) -> int:
try:
from hermes_cli.curses_ui import curses_radiolist
return curses_radiolist(title, rows, selected=default, cancel_returns=default)
except Exception:
for idx, row in enumerate(rows, start=1):
print(f"{idx}. {row}")
raw = input(f"{title} [{default + 1}]: ").strip()
if not raw:
return default
try:
return max(0, min(len(rows) - 1, int(raw) - 1))
except ValueError:
return default
def _model_options() -> list[dict[str, Any]]:
payload = build_models_payload(
load_picker_context(),
include_unconfigured=True,
picker_hints=True,
canonical_order=True,
pricing=True,
capabilities=True,
max_models=200,
)
providers = payload.get("providers") or []
return [p for p in providers if p.get("slug") and p.get("models")]
def _pick_slot(current: dict[str, str] | None = None) -> dict[str, str]:
providers = _model_options()
if not providers:
raise RuntimeError("No configured model providers found. Run `hermes model` first.")
current_provider = (current or {}).get("provider", "")
provider_default = next(
(idx for idx, p in enumerate(providers) if p.get("slug") == current_provider),
0,
)
provider_rows = [f"{p.get('name') or p.get('slug')} ({p.get('slug')})" for p in providers]
provider = providers[_prompt_choice("Select provider", provider_rows, provider_default)]
models = list(provider.get("models") or [])
if not models:
raise RuntimeError(f"Provider {provider.get('slug')} has no selectable models")
current_model = (current or {}).get("model", "")
model_default = models.index(current_model) if current_model in models else 0
model = models[_prompt_choice(f"Select model for {provider.get('slug')}", models, model_default)]
return {"provider": str(provider.get("slug") or ""), "model": str(model)}
def _print_config(config: dict[str, Any]) -> None:
cfg = normalize_moa_config(config.get("moa") if isinstance(config, dict) else {})
print("Mixture of Agents")
print("Reference models:")
for idx, slot in enumerate(cfg["reference_models"], start=1):
print(f" {idx}. {slot['provider']}:{slot['model']}")
agg = cfg["aggregator"]
print(f"Aggregator: {agg['provider']}:{agg['model']}")
def cmd_moa(args) -> None:
"""Manage Mixture of Agents model slots."""
cfg = load_config()
sub = getattr(args, "moa_command", None) or "list"
if sub in {"list", "ls"}:
_print_config(cfg)
return
if sub in {"config", "configure"}:
moa = normalize_moa_config(cfg.get("moa") if isinstance(cfg, dict) else {})
print("Configure reference models. Pick at least one; choose Done when finished.")
refs: list[dict[str, str]] = []
existing = list(moa.get("reference_models") or [])
idx = 0
while True:
base = existing[idx] if idx < len(existing) else None
refs.append(_pick_slot(base))
idx += 1
choice = _prompt_choice("Add another reference model?", ["Add another", "Done"], 1)
if choice == 1:
break
print("Configure aggregator model.")
moa["reference_models"] = refs
moa["aggregator"] = _pick_slot(moa.get("aggregator"))
cfg["moa"] = normalize_moa_config(moa)
save_config(cfg)
print("Saved MoA configuration.")
_print_config(cfg)
return
raise SystemExit(f"Unknown moa subcommand: {sub}")

90
hermes_cli/moa_config.py Normal file
View file

@ -0,0 +1,90 @@
"""Mixture-of-Agents configuration and slash-command helpers."""
from __future__ import annotations
import base64
import json
from copy import deepcopy
from typing import Any
MOA_MARKER_PREFIX = "__HERMES_MOA_TURN_V1__"
DEFAULT_MOA_REFERENCE_MODELS: list[dict[str, str]] = [
{"provider": "openai-codex", "model": "gpt-5.5"},
{"provider": "openrouter", "model": "deepseek/deepseek-v4-pro"},
]
DEFAULT_MOA_AGGREGATOR: dict[str, str] = {
"provider": "openrouter",
"model": "anthropic/claude-opus-4.8",
}
def _clean_slot(slot: Any) -> dict[str, str] | None:
if not isinstance(slot, dict):
return None
provider = str(slot.get("provider") or "").strip()
model = str(slot.get("model") or "").strip()
if not provider or not model:
return None
return {"provider": provider, "model": model}
def normalize_moa_config(raw: Any) -> dict[str, Any]:
"""Return a validated MoA config with provider/model slots."""
if not isinstance(raw, dict):
raw = {}
refs = [_clean_slot(item) for item in raw.get("reference_models") or []]
refs = [item for item in refs if item is not None]
if not refs:
refs = deepcopy(DEFAULT_MOA_REFERENCE_MODELS)
aggregator = _clean_slot(raw.get("aggregator")) or deepcopy(DEFAULT_MOA_AGGREGATOR)
return {
"enabled": bool(raw.get("enabled", True)),
"reference_models": refs,
"aggregator": aggregator,
"reference_temperature": float(raw.get("reference_temperature", 0.6) or 0.6),
"aggregator_temperature": float(raw.get("aggregator_temperature", 0.4) or 0.4),
"max_tokens": int(raw.get("max_tokens", 4096) or 4096),
}
def encode_moa_turn(prompt: str, config: Any = None) -> str:
"""Encode a /moa turn so all frontends can route it as a normal user turn."""
payload = {
"prompt": str(prompt or ""),
"config": normalize_moa_config(config or {}),
}
encoded = base64.urlsafe_b64encode(
json.dumps(payload, separators=(",", ":"), ensure_ascii=False).encode("utf-8")
).decode("ascii")
return f"{MOA_MARKER_PREFIX}{encoded}"
def decode_moa_turn(message: Any) -> tuple[str, dict[str, Any] | None]:
"""Decode a hidden /moa turn marker.
Returns ``(user_prompt, moa_config_or_none)``. Invalid or non-marker input is
returned unchanged with ``None`` so callers can use this unconditionally.
"""
if not isinstance(message, str) or not message.startswith(MOA_MARKER_PREFIX):
return message, None
encoded = message[len(MOA_MARKER_PREFIX):].strip()
try:
payload = json.loads(base64.urlsafe_b64decode(encoded.encode("ascii")).decode("utf-8"))
except Exception:
return message, None
prompt = str(payload.get("prompt") or "")
return prompt, normalize_moa_config(payload.get("config") or {})
def build_moa_turn_prompt(user_prompt: str, config: Any = None) -> str:
"""Build the hidden turn payload used by /moa slash commands."""
return encode_moa_turn(user_prompt, config)
def moa_usage() -> str:
return "Usage: /moa <prompt>"

View file

@ -375,11 +375,6 @@ def _print_setup_summary(config: dict, hermes_home):
else:
tool_status.append(("Vision (image analysis)", False, "run 'hermes setup' to configure"))
# Mixture of Agents — requires OpenRouter specifically (calls multiple models)
if get_env_value("OPENROUTER_API_KEY"):
tool_status.append(("Mixture of Agents", True, None))
else:
tool_status.append(("Mixture of Agents", False, "OPENROUTER_API_KEY"))
# Web tools (Exa, Parallel, Firecrawl, or Tavily)
if subscription_features.web.managed_by_nous:

View file

@ -144,7 +144,7 @@ TIPS = [
"The todo tool helps the agent track complex multi-step tasks during a session.",
"session_search performs full-text search across ALL past conversations.",
"The agent automatically saves preferences, corrections, and environment facts to memory.",
"mixture_of_agents routes hard problems through 4 frontier LLMs collaboratively.",
"/moa routes one hard prompt through your configured Mixture of Agents model set.",
"Terminal commands support background mode with notify_on_complete for long-running tasks.",
"Terminal background processes support watch_patterns to alert on specific output lines.",
"The terminal tool supports 6 backends: local, Docker, SSH, Modal, Daytona, and Singularity.",

View file

@ -63,7 +63,6 @@ CONFIGURABLE_TOOLSETS = [
("image_gen", "🎨 Image Generation", "image_generate"),
("video_gen", "🎬 Video Generation", "video_generate (text-to-video + image-to-video)"),
("x_search", "🐦 X (Twitter) Search", "x_search (requires xAI OAuth or XAI_API_KEY)"),
("moa", "🧠 Mixture of Agents", "mixture_of_agents"),
("tts", "🔊 Text-to-Speech", "text_to_speech"),
("skills", "📚 Skills", "list, view, manage"),
("todo", "📋 Task Planning", "todo"),
@ -112,7 +111,7 @@ def gui_toolset_label(label: str) -> str:
# `hermes tools` → X (Twitter) Search setup walks users through credential
# setup. The tool's check_fn means the schema still won't appear to the
# model if the credential later goes missing or expires.
_DEFAULT_OFF_TOOLSETS = {"moa", "homeassistant", "spotify", "discord", "discord_admin", "video", "video_gen", "x_search"}
_DEFAULT_OFF_TOOLSETS = {"homeassistant", "spotify", "discord", "discord_admin", "video", "video_gen", "x_search"}
def _xai_credentials_present() -> bool:
@ -565,10 +564,9 @@ TOOL_CATEGORIES = {
}
# Simple env-var requirements for toolsets NOT in TOOL_CATEGORIES.
# Used as a fallback for tools like vision/moa that just need an API key.
# Used as a fallback for toolsets like vision that just need an API key.
TOOLSET_ENV_REQUIREMENTS = {
"vision": [("OPENROUTER_API_KEY", "https://openrouter.ai/keys")],
"moa": [("OPENROUTER_API_KEY", "https://openrouter.ai/keys")],
}

View file

@ -738,6 +738,21 @@ class ModelAssignment(BaseModel):
profile: Optional[str] = None
class MoaModelSlot(BaseModel):
provider: str
model: str
class MoaConfigPayload(BaseModel):
reference_models: list[MoaModelSlot]
aggregator: MoaModelSlot
reference_temperature: float = 0.6
aggregator_temperature: float = 0.4
max_tokens: int = 4096
enabled: bool = True
profile: Optional[str] = None
def _normalize_main_model_assignment(provider: str, model: str) -> tuple[str, str]:
"""Normalize a main-slot (provider, model) pair before persisting.
@ -3240,6 +3255,49 @@ def get_auxiliary_models(profile: Optional[str] = None):
raise HTTPException(status_code=500, detail="Failed to read auxiliary config")
@app.get("/api/model/moa")
def get_moa_models(profile: Optional[str] = None):
"""Return the configured Mixture-of-Agents provider/model slots."""
try:
from hermes_cli.moa_config import normalize_moa_config
with _profile_scope(profile):
cfg = load_config()
return normalize_moa_config(cfg.get("moa") if isinstance(cfg, dict) else {})
except HTTPException:
raise
except Exception:
_log.exception("GET /api/model/moa failed")
raise HTTPException(status_code=500, detail="Failed to read MoA config")
@app.put("/api/model/moa")
def set_moa_models(body: MoaConfigPayload, profile: Optional[str] = None):
"""Persist the Mixture-of-Agents provider/model slots."""
try:
from hermes_cli.moa_config import normalize_moa_config
with _profile_scope(body.profile or profile):
cfg = load_config()
raw = {
"reference_models": [slot.dict() for slot in body.reference_models],
"aggregator": body.aggregator.dict(),
"reference_temperature": body.reference_temperature,
"aggregator_temperature": body.aggregator_temperature,
"max_tokens": body.max_tokens,
"enabled": body.enabled,
}
normalized = normalize_moa_config(raw)
cfg["moa"] = normalized
save_config(cfg)
return {"ok": True, **normalized}
except HTTPException:
raise
except Exception:
_log.exception("PUT /api/model/moa failed")
raise HTTPException(status_code=500, detail="Failed to save MoA config")
@app.post("/api/model/set")
async def set_model_assignment(body: ModelAssignment, profile: Optional[str] = None):
"""Assign a model to the main slot or an auxiliary task slot.

View file

@ -221,7 +221,6 @@ _LEGACY_TOOLSET_MAP = {
"web_tools": ["web_search", "web_extract"],
"terminal_tools": ["terminal"],
"vision_tools": ["vision_analyze"],
"moa_tools": ["mixture_of_agents"],
"image_tools": ["image_generate"],
"skills_tools": ["skills_list", "skill_view", "skill_manage"],
"browser_tools": [

View file

@ -5210,10 +5210,11 @@ class AIAgent:
task_id: str = None,
stream_callback: Optional[callable] = None,
persist_user_message: Optional[str] = None,
moa_config: Optional[dict[str, Any]] = None,
) -> Dict[str, Any]:
"""Forwarder — see ``agent.conversation_loop.run_conversation``."""
from agent.conversation_loop import run_conversation
return run_conversation(self, user_message, system_message, conversation_history, task_id, stream_callback, persist_user_message)
return run_conversation(self, user_message, system_message, conversation_history, task_id, stream_callback, persist_user_message, moa_config)
def chat(self, message: str, stream_callback: Optional[callable] = None) -> str:
"""

View file

@ -439,7 +439,6 @@ Enable/disable via `hermes tools` (interactive) or `hermes tools enable/disable
| `feishu_drive` | Feishu (Lark) drive tools |
| `yuanbao` | Yuanbao integration tools |
| `rl` | Reinforcement learning tools (off by default) |
| `moa` | Mixture of Agents (off by default) |
Full enumeration lives in `toolsets.py` as the `TOOLSETS` dict; `_HERMES_CORE_TOOLS` is the default bundle most platforms inherit from.

View file

@ -0,0 +1,41 @@
from hermes_cli.moa_config import (
DEFAULT_MOA_AGGREGATOR,
DEFAULT_MOA_REFERENCE_MODELS,
build_moa_turn_prompt,
decode_moa_turn,
normalize_moa_config,
)
def test_normalize_moa_config_uses_provider_model_slots():
cfg = normalize_moa_config({})
assert cfg["reference_models"] == DEFAULT_MOA_REFERENCE_MODELS
assert cfg["aggregator"] == DEFAULT_MOA_AGGREGATOR
assert all(set(slot) == {"provider", "model"} for slot in cfg["reference_models"])
assert set(cfg["aggregator"]) == {"provider", "model"}
def test_normalize_moa_config_drops_incomplete_slots_and_keeps_valid_ones():
cfg = normalize_moa_config(
{
"reference_models": [
{"provider": "openai-codex", "model": "gpt-5.5"},
{"provider": "openrouter", "model": ""},
{"provider": "", "model": "anthropic/claude-opus-4.8"},
],
"aggregator": {"provider": "openrouter", "model": "anthropic/claude-opus-4.8"},
}
)
assert cfg["reference_models"] == [{"provider": "openai-codex", "model": "gpt-5.5"}]
assert cfg["aggregator"] == {"provider": "openrouter", "model": "anthropic/claude-opus-4.8"}
def test_build_moa_turn_prompt_keeps_user_prompt_and_marks_mode():
prompt = build_moa_turn_prompt("write a file then inspect it")
decoded_prompt, cfg = decode_moa_turn(prompt)
assert decoded_prompt == "write a file then inspect it"
assert cfg is not None
assert cfg["reference_models"] == DEFAULT_MOA_REFERENCE_MODELS

View file

@ -244,6 +244,36 @@ class TestWebServerEndpoints:
assert "hermes_home" in data
assert "active_sessions" in data
def test_get_moa_models_returns_provider_model_slots(self):
resp = self.client.get("/api/model/moa")
assert resp.status_code == 200
data = resp.json()
assert data["reference_models"]
assert all(set(slot) == {"provider", "model"} for slot in data["reference_models"])
assert set(data["aggregator"]) == {"provider", "model"}
def test_put_moa_models_persists_provider_model_slots(self):
from hermes_cli.config import load_config
payload = {
"reference_models": [
{"provider": "openai-codex", "model": "gpt-5.5"},
{"provider": "openrouter", "model": "deepseek/deepseek-v4-pro"},
],
"aggregator": {"provider": "openrouter", "model": "anthropic/claude-opus-4.8"},
"reference_temperature": 0.6,
"aggregator_temperature": 0.4,
"max_tokens": 4096,
"enabled": True,
}
resp = self.client.put("/api/model/moa", json=payload)
assert resp.status_code == 200
assert resp.json()["ok"] is True
cfg = load_config()
assert cfg["moa"]["reference_models"] == payload["reference_models"]
assert cfg["moa"]["aggregator"] == payload["aggregator"]
# ── GET /api/media (remote image display) ───────────────────────────
def test_get_media_serves_image_in_root(self):

View file

@ -0,0 +1,153 @@
import json
from types import SimpleNamespace
from unittest.mock import MagicMock
from agent.moa_loop import aggregate_moa_context
from run_agent import AIAgent
def _response(content="done", *, tool_calls=None):
message = SimpleNamespace(content=content, tool_calls=tool_calls or [])
choice = SimpleNamespace(message=message, finish_reason="stop")
return SimpleNamespace(choices=[choice], usage=None, model="fake-model")
def test_moa_mode_aggregates_reference_models_before_each_agent_iteration(monkeypatch):
agent = AIAgent(
api_key="test-key",
base_url="https://openrouter.ai/api/v1",
model="anthropic/claude-opus-4.8",
provider="openrouter",
quiet_mode=True,
skip_context_files=True,
skip_memory=True,
enabled_toolsets=[],
max_iterations=1,
)
agent.client = MagicMock()
agent.client.chat.completions.create.return_value = _response("final")
aggregate = MagicMock(return_value="reference synthesis")
monkeypatch.setattr("agent.moa_loop.aggregate_moa_context", aggregate)
result = agent.run_conversation(
"solve this",
moa_config={
"reference_models": [
{"provider": "openai-codex", "model": "gpt-5.5"},
{"provider": "openrouter", "model": "deepseek/deepseek-v4-pro"},
],
"aggregator": {"provider": "openrouter", "model": "anthropic/claude-opus-4.8"},
},
)
assert result["final_response"] == "final"
aggregate.assert_called_once()
kwargs = aggregate.call_args.kwargs
assert kwargs["user_prompt"] == "solve this"
assert [m["model"] for m in kwargs["reference_models"]] == [
"gpt-5.5",
"deepseek/deepseek-v4-pro",
]
sent_messages = agent.client.chat.completions.create.call_args.kwargs["messages"]
sent_text = "\n".join(str(m.get("content", "")) for m in sent_messages)
assert "reference synthesis" in sent_text
def test_moa_mode_runs_on_second_iteration_after_tool_result(monkeypatch):
agent = AIAgent(
api_key="test-key",
base_url="https://openrouter.ai/api/v1",
model="anthropic/claude-opus-4.8",
provider="openrouter",
quiet_mode=True,
skip_context_files=True,
skip_memory=True,
enabled_toolsets=["file"],
max_iterations=2,
)
agent.client = MagicMock()
agent.client.chat.completions.create.side_effect = [
_response(
"",
tool_calls=[
SimpleNamespace(
id="call_1",
type="function",
function=SimpleNamespace(
name="search_files",
arguments=json.dumps({"pattern": "*.py", "target": "files", "path": "/tmp"}),
),
)
],
),
_response("final"),
]
aggregate_calls = []
def aggregate(**kwargs):
aggregate_calls.append(
{
"reference_models": kwargs["reference_models"],
"aggregator": kwargs["aggregator"],
"has_tool_result": any(m.get("role") == "tool" for m in kwargs["api_messages"]),
}
)
return f"guidance {len(aggregate_calls)}"
monkeypatch.setattr("agent.moa_loop.aggregate_moa_context", aggregate)
result = agent.run_conversation(
"find python files",
moa_config={
"reference_models": [
{"provider": "openai-codex", "model": "gpt-5.5"},
{"provider": "openrouter", "model": "deepseek/deepseek-v4-pro"},
],
"aggregator": {"provider": "openrouter", "model": "anthropic/claude-opus-4.8"},
},
)
assert result["final_response"] == "final"
assert len(aggregate_calls) == 2
assert aggregate_calls[0]["has_tool_result"] is False
assert aggregate_calls[1]["has_tool_result"] is True
assert [slot["provider"] for slot in aggregate_calls[1]["reference_models"]] == [
"openai-codex",
"openrouter",
]
assert aggregate_calls[1]["aggregator"] == {
"provider": "openrouter",
"model": "anthropic/claude-opus-4.8",
}
def test_aggregate_moa_context_calls_mixed_providers(monkeypatch):
calls = []
def fake_call_llm(**kwargs):
calls.append(kwargs)
message = SimpleNamespace(content=f"reply from {kwargs['provider']}:{kwargs['model']}", tool_calls=[])
return SimpleNamespace(choices=[SimpleNamespace(message=message, finish_reason="stop")], usage=None)
monkeypatch.setattr("agent.moa_loop.call_llm", fake_call_llm)
context = aggregate_moa_context(
user_prompt="question",
api_messages=[{"role": "user", "content": "question"}],
reference_models=[
{"provider": "openai-codex", "model": "gpt-5.5"},
{"provider": "openrouter", "model": "deepseek/deepseek-v4-pro"},
],
aggregator={"provider": "openrouter", "model": "anthropic/claude-opus-4.8"},
max_tokens=200,
)
assert [(c["task"], c["provider"], c["model"]) for c in calls] == [
("moa_reference", "openai-codex", "gpt-5.5"),
("moa_reference", "openrouter", "deepseek/deepseek-v4-pro"),
("moa_aggregator", "openrouter", "anthropic/claude-opus-4.8"),
]
assert "openai-codex:gpt-5.5" in context
assert "openrouter:deepseek/deepseek-v4-pro" in context

View file

@ -375,7 +375,7 @@ class TestPreToolCallBlocking:
class TestLegacyToolsetMap:
def test_expected_legacy_names(self):
expected = [
"web_tools", "terminal_tools", "vision_tools", "moa_tools",
"web_tools", "terminal_tools", "vision_tools",
"image_tools", "skills_tools", "browser_tools", "cronjob_tools",
"file_tools", "tts_tools",
]

View file

@ -36,52 +36,6 @@ def _run(coro):
return asyncio.get_event_loop().run_until_complete(coro)
# ── mixture_of_agents_tool — reference model (line 146) ───────────────────
class TestMoAReferenceModelContentNone:
"""tools/mixture_of_agents_tool.py — _query_model()"""
def test_none_content_raises_before_fix(self):
"""Demonstrate that None content from a reasoning model crashes."""
response = _make_response(None)
# Simulate the exact line: response.choices[0].message.content.strip()
with pytest.raises(AttributeError):
response.choices[0].message.content.strip()
def test_none_content_safe_with_or_guard(self):
"""The ``or ""`` guard should convert None to empty string."""
response = _make_response(None)
content = (response.choices[0].message.content or "").strip()
assert content == ""
def test_normal_content_unaffected(self):
"""Regular string content should pass through unchanged."""
response = _make_response(" Hello world ")
content = (response.choices[0].message.content or "").strip()
assert content == "Hello world"
# ── mixture_of_agents_tool — aggregator (line 214) ────────────────────────
class TestMoAAggregatorContentNone:
"""tools/mixture_of_agents_tool.py — _run_aggregator()"""
def test_none_content_raises_before_fix(self):
response = _make_response(None)
with pytest.raises(AttributeError):
response.choices[0].message.content.strip()
def test_none_content_safe_with_or_guard(self):
response = _make_response(None)
content = (response.choices[0].message.content or "").strip()
assert content == ""
# ── web_tools — LLM content processor (line 419) ─────────────────────────
class TestWebToolsProcessorContentNone:
@ -170,14 +124,6 @@ class TestSourceLinesAreGuarded:
with open(os.path.join(base, rel_path)) as f:
return f.read()
def test_mixture_of_agents_reference_model_guarded(self):
src = self._read_file("tools/mixture_of_agents_tool.py")
# The unguarded pattern should NOT exist
assert ".message.content.strip()" not in src, (
"tools/mixture_of_agents_tool.py still has unguarded "
".content.strip() — apply `(... or \"\").strip()` guard"
)
def test_web_tools_guarded(self):
src = self._read_file("tools/web_tools.py")
assert ".message.content.strip()" not in src, (

View file

@ -1,85 +0,0 @@
import importlib
import json
from types import SimpleNamespace
from unittest.mock import AsyncMock, MagicMock
import pytest
moa = importlib.import_module("tools.mixture_of_agents_tool")
def test_moa_defaults_are_well_formed():
# Invariants, not a catalog snapshot: the exact model list churns with
# OpenRouter availability (see PR #6636 where gemini-3-pro-preview was
# removed upstream). What we care about is that the defaults are present
# and valid vendor/model slugs.
assert isinstance(moa.REFERENCE_MODELS, list)
assert len(moa.REFERENCE_MODELS) >= 1
for m in moa.REFERENCE_MODELS:
assert isinstance(m, str) and "/" in m and not m.startswith("/")
assert isinstance(moa.AGGREGATOR_MODEL, str)
assert "/" in moa.AGGREGATOR_MODEL
@pytest.mark.asyncio
async def test_reference_model_retry_warnings_avoid_exc_info_until_terminal_failure(monkeypatch):
fake_client = SimpleNamespace(
chat=SimpleNamespace(
completions=SimpleNamespace(
create=AsyncMock(side_effect=RuntimeError("rate limited"))
)
)
)
warn = MagicMock()
err = MagicMock()
monkeypatch.setattr(moa, "_get_openrouter_client", lambda: fake_client)
monkeypatch.setattr(moa.logger, "warning", warn)
monkeypatch.setattr(moa.logger, "error", err)
model, message, success = await moa._run_reference_model_safe(
"openai/gpt-5.4-pro", "hello", max_retries=2
)
assert model == "openai/gpt-5.4-pro"
assert success is False
assert "failed after 2 attempts" in message
assert warn.call_count == 2
assert all(call.kwargs.get("exc_info") is None for call in warn.call_args_list)
err.assert_called_once()
assert err.call_args.kwargs.get("exc_info") is True
@pytest.mark.asyncio
async def test_moa_top_level_error_logs_single_traceback_on_aggregator_failure(monkeypatch):
monkeypatch.setenv("OPENROUTER_API_KEY", "test-key")
monkeypatch.setattr(
moa,
"_run_reference_model_safe",
AsyncMock(return_value=("anthropic/claude-opus-4.6", "ok", True)),
)
monkeypatch.setattr(
moa,
"_run_aggregator_model",
AsyncMock(side_effect=RuntimeError("aggregator boom")),
)
monkeypatch.setattr(
moa,
"_debug",
SimpleNamespace(log_call=MagicMock(), save=MagicMock(), active=False),
)
err = MagicMock()
monkeypatch.setattr(moa.logger, "error", err)
result = json.loads(
await moa.mixture_of_agents_tool(
"solve this",
reference_models=["anthropic/claude-opus-4.6"],
)
)
assert result["success"] is False
assert "Error in MoA processing" in result["error"]
err.assert_called_once()
assert err.call_args.kwargs.get("exc_info") is True

View file

@ -2,7 +2,7 @@
Replaces the identical DEBUG_MODE / _log_debug_call / _save_debug_log /
get_debug_session_info boilerplate previously duplicated across web_tools,
vision_tools, mixture_of_agents_tool, and image_generation_tool.
vision_tools, and image_generation_tool.
Usage in a tool module:

View file

@ -119,7 +119,7 @@ def _get_subagent_approval_callback():
# toolset to request explicitly — the correct mechanism for nested
# delegation is role='orchestrator', which re-adds "delegation" in
# _build_child_agent regardless of this exclusion.
_EXCLUDED_TOOLSET_NAMES = frozenset({"debugging", "safe", "delegation", "moa", "rl"})
_EXCLUDED_TOOLSET_NAMES = frozenset({"debugging", "safe", "delegation", "rl"})
_SUBAGENT_TOOLSETS = sorted(
name
for name, defn in TOOLSETS.items()

View file

@ -1,542 +0,0 @@
#!/usr/bin/env python3
"""
Mixture-of-Agents Tool Module
This module implements the Mixture-of-Agents (MoA) methodology that leverages
the collective strengths of multiple LLMs through a layered architecture to
achieve state-of-the-art performance on complex reasoning tasks.
Based on the research paper: "Mixture-of-Agents Enhances Large Language Model Capabilities"
by Junlin Wang et al. (arXiv:2406.04692v1)
Key Features:
- Multi-layer LLM collaboration for enhanced reasoning
- Parallel processing of reference models for efficiency
- Intelligent aggregation and synthesis of diverse responses
- Specialized for extremely difficult problems requiring intense reasoning
- Optimized for coding, mathematics, and complex analytical tasks
Available Tool:
- mixture_of_agents_tool: Process complex queries using multiple frontier models
Architecture:
1. Reference models generate diverse initial responses in parallel
2. Aggregator model synthesizes responses into a high-quality output
3. Multiple layers can be used for iterative refinement (future enhancement)
Models Used (via OpenRouter):
- Reference Models: claude-opus-4.6, gemini-3-pro-preview, gpt-5.4-pro, deepseek-v3.2
- Aggregator Model: claude-opus-4.6 (highest capability for synthesis)
Configuration:
To customize the MoA setup, modify the configuration constants at the top of this file:
- REFERENCE_MODELS: List of models for generating diverse initial responses
- AGGREGATOR_MODEL: Model used to synthesize the final response
- REFERENCE_TEMPERATURE/AGGREGATOR_TEMPERATURE: Sampling temperatures
- MIN_SUCCESSFUL_REFERENCES: Minimum successful models needed to proceed
Usage:
from mixture_of_agents_tool import mixture_of_agents_tool
import asyncio
# Process a complex query
result = await mixture_of_agents_tool(
user_prompt="Solve this complex mathematical proof..."
)
"""
import json
import logging
import os
import asyncio
import datetime
from typing import Dict, Any, List, Optional
from tools.openrouter_client import get_async_client as _get_openrouter_client, check_api_key as check_openrouter_api_key
from agent.auxiliary_client import extract_content_or_reasoning
from tools.debug_helpers import DebugSession
import sys
logger = logging.getLogger(__name__)
# Configuration for MoA processing
# Reference models - these generate diverse initial responses in parallel.
# Keep this list aligned with current top-tier OpenRouter frontier options.
REFERENCE_MODELS = [
"anthropic/claude-opus-4.6",
"google/gemini-2.5-pro",
"openai/gpt-5.4-pro",
"deepseek/deepseek-v3.2",
]
# Aggregator model - synthesizes reference responses into final output.
# Prefer the strongest synthesis model in the current OpenRouter lineup.
AGGREGATOR_MODEL = "anthropic/claude-opus-4.6"
# Temperature settings optimized for MoA performance
REFERENCE_TEMPERATURE = 0.6 # Balanced creativity for diverse perspectives
AGGREGATOR_TEMPERATURE = 0.4 # Focused synthesis for consistency
# Failure handling configuration
MIN_SUCCESSFUL_REFERENCES = 1 # Minimum successful reference models needed to proceed
# System prompt for the aggregator model (from the research paper)
AGGREGATOR_SYSTEM_PROMPT = """You have been provided with a set of responses from various open-source models to the latest user query. Your task is to synthesize these responses into a single, high-quality response. It is crucial to critically evaluate the information provided in these responses, recognizing that some of it may be biased or incorrect. Your response should not simply replicate the given answers but should offer a refined, accurate, and comprehensive reply to the instruction. Ensure your response is well-structured, coherent, and adheres to the highest standards of accuracy and reliability.
Responses from models:"""
_debug = DebugSession("moa_tools", env_var="MOA_TOOLS_DEBUG")
def _construct_aggregator_prompt(system_prompt: str, responses: List[str]) -> str:
"""
Construct the final system prompt for the aggregator including all model responses.
Args:
system_prompt (str): Base system prompt for aggregation
responses (List[str]): List of responses from reference models
Returns:
str: Complete system prompt with enumerated responses
"""
response_text = "\n".join([f"{i+1}. {response}" for i, response in enumerate(responses)])
return f"{system_prompt}\n\n{response_text}"
async def _run_reference_model_safe(
model: str,
user_prompt: str,
temperature: float = REFERENCE_TEMPERATURE,
max_tokens: int = 32000,
max_retries: int = 6
) -> tuple[str, str, bool]:
"""
Run a single reference model with retry logic and graceful failure handling.
Args:
model (str): Model identifier to use
user_prompt (str): The user's query
temperature (float): Sampling temperature for response generation
max_tokens (int): Maximum tokens in response
max_retries (int): Maximum number of retry attempts
Returns:
tuple[str, str, bool]: (model_name, response_content_or_error, success_flag)
"""
for attempt in range(max_retries):
try:
logger.info("Querying %s (attempt %s/%s)", model, attempt + 1, max_retries)
# Build parameters for the API call
api_params = {
"model": model,
"messages": [{"role": "user", "content": user_prompt}],
"max_tokens": max_tokens,
"extra_body": {
"reasoning": {
"enabled": True,
"effort": "xhigh"
}
}
}
# GPT models (especially gpt-4o-mini) don't support custom temperature values
# Only include temperature for non-GPT models
if not model.lower().startswith('gpt-'):
api_params["temperature"] = temperature
response = await _get_openrouter_client().chat.completions.create(**api_params)
content = extract_content_or_reasoning(response)
if not content:
# Reasoning-only response — let the retry loop handle it
logger.warning("%s returned empty content (attempt %s/%s), retrying", model, attempt + 1, max_retries)
if attempt < max_retries - 1:
await asyncio.sleep(min(2 ** (attempt + 1), 60))
continue
logger.info("%s responded (%s characters)", model, len(content))
return model, content, True
except Exception as e:
error_str = str(e)
# Keep retry-path logging concise; full tracebacks are reserved for
# terminal failure paths so long-running MoA retries don't flood logs.
if "invalid" in error_str.lower():
logger.warning("%s invalid request error (attempt %s): %s", model, attempt + 1, error_str)
elif "rate" in error_str.lower() or "limit" in error_str.lower():
logger.warning("%s rate limit error (attempt %s): %s", model, attempt + 1, error_str)
else:
logger.warning("%s unknown error (attempt %s): %s", model, attempt + 1, error_str)
if attempt < max_retries - 1:
# Exponential backoff for rate limiting: 2s, 4s, 8s, 16s, 32s, 60s
sleep_time = min(2 ** (attempt + 1), 60)
logger.info("Retrying in %ss...", sleep_time)
await asyncio.sleep(sleep_time)
else:
error_msg = f"{model} failed after {max_retries} attempts: {error_str}"
logger.error("%s", error_msg, exc_info=True)
return model, error_msg, False
async def _run_aggregator_model(
system_prompt: str,
user_prompt: str,
temperature: float = AGGREGATOR_TEMPERATURE,
max_tokens: int = None
) -> str:
"""
Run the aggregator model to synthesize the final response.
Args:
system_prompt (str): System prompt with all reference responses
user_prompt (str): Original user query
temperature (float): Focused temperature for consistent aggregation
max_tokens (int): Maximum tokens in final response
Returns:
str: Synthesized final response
"""
logger.info("Running aggregator model: %s", AGGREGATOR_MODEL)
# Build parameters for the API call
api_params = {
"model": AGGREGATOR_MODEL,
"messages": [
{"role": "system", "content": system_prompt},
{"role": "user", "content": user_prompt}
],
"max_tokens": max_tokens,
"extra_body": {
"reasoning": {
"enabled": True,
"effort": "xhigh"
}
}
}
# GPT models (especially gpt-4o-mini) don't support custom temperature values
# Only include temperature for non-GPT models
if not AGGREGATOR_MODEL.lower().startswith('gpt-'):
api_params["temperature"] = temperature
response = await _get_openrouter_client().chat.completions.create(**api_params)
content = extract_content_or_reasoning(response)
# Retry once on empty content (reasoning-only response)
if not content:
logger.warning("Aggregator returned empty content, retrying once")
response = await _get_openrouter_client().chat.completions.create(**api_params)
content = extract_content_or_reasoning(response)
logger.info("Aggregation complete (%s characters)", len(content))
return content
async def mixture_of_agents_tool(
user_prompt: str,
reference_models: Optional[List[str]] = None,
aggregator_model: Optional[str] = None
) -> str:
"""
Process a complex query using the Mixture-of-Agents methodology.
This tool leverages multiple frontier language models to collaboratively solve
extremely difficult problems requiring intense reasoning. It's particularly
effective for:
- Complex mathematical proofs and calculations
- Advanced coding problems and algorithm design
- Multi-step analytical reasoning tasks
- Problems requiring diverse domain expertise
- Tasks where single models show limitations
The MoA approach uses a fixed 2-layer architecture:
1. Layer 1: Multiple reference models generate diverse responses in parallel (temp=0.6)
2. Layer 2: Aggregator model synthesizes the best elements into final response (temp=0.4)
Args:
user_prompt (str): The complex query or problem to solve
reference_models (Optional[List[str]]): Custom reference models to use
aggregator_model (Optional[str]): Custom aggregator model to use
Returns:
str: JSON string containing the MoA results with the following structure:
{
"success": bool,
"response": str,
"models_used": {
"reference_models": List[str],
"aggregator_model": str
},
"processing_time": float
}
Raises:
Exception: If MoA processing fails or API key is not set
"""
start_time = datetime.datetime.now()
debug_call_data = {
"parameters": {
"user_prompt": user_prompt[:200] + "..." if len(user_prompt) > 200 else user_prompt,
"reference_models": reference_models or REFERENCE_MODELS,
"aggregator_model": aggregator_model or AGGREGATOR_MODEL,
"reference_temperature": REFERENCE_TEMPERATURE,
"aggregator_temperature": AGGREGATOR_TEMPERATURE,
"min_successful_references": MIN_SUCCESSFUL_REFERENCES
},
"error": None,
"success": False,
"reference_responses_count": 0,
"failed_models_count": 0,
"failed_models": [],
"final_response_length": 0,
"processing_time_seconds": 0,
"models_used": {}
}
try:
logger.info("Starting Mixture-of-Agents processing...")
logger.info("Query: %s", user_prompt[:100])
# Validate API key availability
if not os.getenv("OPENROUTER_API_KEY"):
raise ValueError("OPENROUTER_API_KEY environment variable not set")
# Use provided models or defaults
ref_models = reference_models or REFERENCE_MODELS
agg_model = aggregator_model or AGGREGATOR_MODEL
logger.info("Using %s reference models in 2-layer MoA architecture", len(ref_models))
# Layer 1: Generate diverse responses from reference models (with failure handling)
logger.info("Layer 1: Generating reference responses...")
model_results = await asyncio.gather(*[
_run_reference_model_safe(model, user_prompt, REFERENCE_TEMPERATURE)
for model in ref_models
])
# Separate successful and failed responses
successful_responses = []
failed_models = []
for model_name, content, success in model_results:
if success:
successful_responses.append(content)
else:
failed_models.append(model_name)
successful_count = len(successful_responses)
failed_count = len(failed_models)
logger.info("Reference model results: %s successful, %s failed", successful_count, failed_count)
if failed_models:
logger.warning("Failed models: %s", ', '.join(failed_models))
# Check if we have enough successful responses to proceed
if successful_count < MIN_SUCCESSFUL_REFERENCES:
raise ValueError(f"Insufficient successful reference models ({successful_count}/{len(ref_models)}). Need at least {MIN_SUCCESSFUL_REFERENCES} successful responses.")
debug_call_data["reference_responses_count"] = successful_count
debug_call_data["failed_models_count"] = failed_count
debug_call_data["failed_models"] = failed_models
# Layer 2: Aggregate responses using the aggregator model
logger.info("Layer 2: Synthesizing final response...")
aggregator_system_prompt = _construct_aggregator_prompt(
AGGREGATOR_SYSTEM_PROMPT,
successful_responses
)
final_response = await _run_aggregator_model(
aggregator_system_prompt,
user_prompt,
AGGREGATOR_TEMPERATURE
)
# Calculate processing time
end_time = datetime.datetime.now()
processing_time = (end_time - start_time).total_seconds()
logger.info("MoA processing completed in %.2f seconds", processing_time)
# Prepare successful response (only final aggregated result, minimal fields)
result = {
"success": True,
"response": final_response,
"models_used": {
"reference_models": ref_models,
"aggregator_model": agg_model
}
}
debug_call_data["success"] = True
debug_call_data["final_response_length"] = len(final_response)
debug_call_data["processing_time_seconds"] = processing_time
debug_call_data["models_used"] = result["models_used"]
# Log debug information
_debug.log_call("mixture_of_agents_tool", debug_call_data)
_debug.save()
return json.dumps(result, indent=2, ensure_ascii=False)
except Exception as e:
error_msg = f"Error in MoA processing: {str(e)}"
logger.error("%s", error_msg, exc_info=True)
# Calculate processing time even for errors
end_time = datetime.datetime.now()
processing_time = (end_time - start_time).total_seconds()
# Prepare error response (minimal fields)
result = {
"success": False,
"response": "MoA processing failed. Please try again or use a single model for this query.",
"models_used": {
"reference_models": reference_models or REFERENCE_MODELS,
"aggregator_model": aggregator_model or AGGREGATOR_MODEL
},
"error": error_msg
}
debug_call_data["error"] = error_msg
debug_call_data["processing_time_seconds"] = processing_time
_debug.log_call("mixture_of_agents_tool", debug_call_data)
_debug.save()
return json.dumps(result, indent=2, ensure_ascii=False)
def check_moa_requirements() -> bool:
"""
Check if all requirements for MoA tools are met.
Returns:
bool: True if requirements are met, False otherwise
"""
return check_openrouter_api_key()
def get_moa_configuration() -> Dict[str, Any]:
"""
Get the current MoA configuration settings.
Returns:
Dict[str, Any]: Dictionary containing all configuration parameters
"""
return {
"reference_models": REFERENCE_MODELS,
"aggregator_model": AGGREGATOR_MODEL,
"reference_temperature": REFERENCE_TEMPERATURE,
"aggregator_temperature": AGGREGATOR_TEMPERATURE,
"min_successful_references": MIN_SUCCESSFUL_REFERENCES,
"total_reference_models": len(REFERENCE_MODELS),
"failure_tolerance": f"{len(REFERENCE_MODELS) - MIN_SUCCESSFUL_REFERENCES}/{len(REFERENCE_MODELS)} models can fail"
}
if __name__ == "__main__":
"""
Simple test/demo when run directly
"""
print("🤖 Mixture-of-Agents Tool Module")
print("=" * 50)
# Check if API key is available
api_available = check_openrouter_api_key()
if not api_available:
print("❌ OPENROUTER_API_KEY environment variable not set")
print("Please set your API key: export OPENROUTER_API_KEY='your-key-here'")
print("Get API key at: https://openrouter.ai/")
sys.exit(1)
else:
print("✅ OpenRouter API key found")
print("🛠️ MoA tools ready for use!")
# Show current configuration
config = get_moa_configuration()
print("\n⚙️ Current Configuration:")
print(f" 🤖 Reference models ({len(config['reference_models'])}): {', '.join(config['reference_models'])}")
print(f" 🧠 Aggregator model: {config['aggregator_model']}")
print(f" 🌡️ Reference temperature: {config['reference_temperature']}")
print(f" 🌡️ Aggregator temperature: {config['aggregator_temperature']}")
print(f" 🛡️ Failure tolerance: {config['failure_tolerance']}")
print(f" 📊 Minimum successful models: {config['min_successful_references']}")
# Show debug mode status
if _debug.active:
print(f"\n🐛 Debug mode ENABLED - Session ID: {_debug.session_id}")
print(f" Debug logs will be saved to: ./logs/moa_tools_debug_{_debug.session_id}.json")
else:
print("\n🐛 Debug mode disabled (set MOA_TOOLS_DEBUG=true to enable)")
print("\nBasic usage:")
print(" from mixture_of_agents_tool import mixture_of_agents_tool")
print(" import asyncio")
print("")
print(" async def main():")
print(" result = await mixture_of_agents_tool(")
print(" user_prompt='Solve this complex mathematical proof...'")
print(" )")
print(" print(result)")
print(" asyncio.run(main())")
print("\nBest use cases:")
print(" - Complex mathematical proofs and calculations")
print(" - Advanced coding problems and algorithm design")
print(" - Multi-step analytical reasoning tasks")
print(" - Problems requiring diverse domain expertise")
print(" - Tasks where single models show limitations")
print("\nPerformance characteristics:")
print(" - Higher latency due to multiple model calls")
print(" - Significantly improved quality for complex tasks")
print(" - Parallel processing for efficiency")
print(f" - Optimized temperatures: {REFERENCE_TEMPERATURE} for reference models, {AGGREGATOR_TEMPERATURE} for aggregation")
print(" - Token-efficient: only returns final aggregated response")
print(" - Resilient: continues with partial model failures")
print(" - Configurable: easy to modify models and settings at top of file")
print(" - State-of-the-art results on challenging benchmarks")
print("\nDebug mode:")
print(" # Enable debug logging")
print(" export MOA_TOOLS_DEBUG=true")
print(" # Debug logs capture all MoA processing steps and metrics")
print(" # Logs saved to: ./logs/moa_tools_debug_UUID.json")
# ---------------------------------------------------------------------------
# Registry
# ---------------------------------------------------------------------------
from tools.registry import registry
MOA_SCHEMA = {
"name": "mixture_of_agents",
"description": "Route a hard problem through multiple frontier LLMs collaboratively. Makes 5 API calls (4 reference models + 1 aggregator) with maximum reasoning effort — use sparingly for genuinely difficult problems. Best for: complex math, advanced algorithms, multi-step analytical reasoning, problems benefiting from diverse perspectives.",
"parameters": {
"type": "object",
"properties": {
"user_prompt": {
"type": "string",
"description": "The complex query or problem to solve using multiple AI models. Should be a challenging problem that benefits from diverse perspectives and collaborative reasoning."
}
},
"required": ["user_prompt"]
}
}
registry.register(
name="mixture_of_agents",
toolset="moa",
schema=MOA_SCHEMA,
handler=lambda args, **kw: mixture_of_agents_tool(user_prompt=args.get("user_prompt", "")),
check_fn=check_moa_requirements,
requires_env=["OPENROUTER_API_KEY"],
is_async=True,
emoji="🧠",
)

View file

@ -36,7 +36,6 @@ DISTRIBUTIONS = {
"image_gen": 100,
"terminal": 100,
"file": 100,
"moa": 100,
"browser": 100
}
},
@ -48,8 +47,7 @@ DISTRIBUTIONS = {
"image_gen": 90, # 80% chance of image generation tools
"vision": 90, # 60% chance of vision tools
"web": 55, # 40% chance of web tools
"terminal": 45,
"moa": 10 # 20% chance of reasoning tools
"terminal": 45
}
},
@ -60,7 +58,6 @@ DISTRIBUTIONS = {
"web": 90, # 90% chance of web tools
"browser": 70, # 70% chance of browser tools for deep research
"vision": 50, # 50% chance of vision tools
"moa": 40, # 40% chance of reasoning tools
"terminal": 10 # 10% chance of terminal tools
}
},
@ -74,8 +71,7 @@ DISTRIBUTIONS = {
"file": 94, # 94% chance of file tools
"vision": 65, # 65% chance of vision tools
"browser": 50, # 50% chance of browser for accessing papers/databases
"image_gen": 15, # 15% chance of image generation tools
"moa": 10 # 10% chance of reasoning tools
"image_gen": 15 # 15% chance of image generation tools
}
},
@ -85,7 +81,6 @@ DISTRIBUTIONS = {
"toolsets": {
"terminal": 80, # 80% chance of terminal tools
"file": 80, # 80% chance of file tools (read, write, patch, search)
"moa": 60, # 60% chance of reasoning tools
"web": 30, # 30% chance of web tools
"vision": 10 # 10% chance of vision tools
}
@ -98,8 +93,7 @@ DISTRIBUTIONS = {
"web": 80,
"browser": 70, # Browser is safe (no local filesystem access)
"vision": 60,
"image_gen": 60,
"moa": 50
"image_gen": 60
}
},
@ -112,7 +106,6 @@ DISTRIBUTIONS = {
"image_gen": 50,
"terminal": 50,
"file": 50,
"moa": 50,
"browser": 50
}
},
@ -156,14 +149,15 @@ DISTRIBUTIONS = {
# Reasoning heavy
"reasoning": {
"description": "Heavy mixture of agents usage with minimal other tools",
"description": "Heavy research/reasoning distribution with minimal other tools",
"toolsets": {
"moa": 90,
"web": 30,
"web": 90,
"file": 60,
"terminal": 20
}
},
# Browser-based web interaction
"browser_use": {
"description": "Full browser-based web interaction with search, vision, and page control",

View file

@ -158,12 +158,6 @@ TOOLSETS = {
"includes": []
},
"moa": {
"description": "Advanced reasoning and problem-solving tools",
"tools": ["mixture_of_agents"],
"includes": []
},
"skills": {
"description": "Access, create, edit, and manage skill documents with specialized instructions and knowledge",
"tools": ["skills_list", "skill_view", "skill_manage"],

View file

@ -7869,6 +7869,7 @@ _PENDING_INPUT_COMMANDS: frozenset[str] = frozenset(
"steer",
"plan",
"goal",
"moa",
"undo",
}
)
@ -8132,6 +8133,24 @@ def _(rid, params: dict) -> dict:
return _err(rid, 4004, "usage: /queue <prompt>")
return _ok(rid, {"type": "send", "message": arg})
if name == "moa":
if not arg:
return _err(rid, 4004, "usage: /moa <prompt>")
try:
from hermes_cli.moa_config import build_moa_turn_prompt
moa_cfg = _load_cfg().get("moa") or {}
return _ok(
rid,
{
"type": "send",
"notice": "MoA mode queued for this turn.",
"message": build_moa_turn_prompt(arg, moa_cfg),
},
)
except Exception as exc:
return _err(rid, 5030, f"moa unavailable: {exc}")
if name == "retry":
if not session:
return _err(rid, 4001, "no active session to retry")

View file

@ -74,6 +74,7 @@ const PROFILE_SCOPED_PREFIXES = [
"/api/model/info",
"/api/model/set",
"/api/model/auxiliary",
"/api/model/moa",
"/api/model/options",
];
@ -449,6 +450,13 @@ export const api = {
getModelInfo: () => fetchJSON<ModelInfoResponse>("/api/model/info"),
getModelOptions: () => fetchJSON<ModelOptionsResponse>("/api/model/options"),
getAuxiliaryModels: () => fetchJSON<AuxiliaryModelsResponse>("/api/model/auxiliary"),
getMoaModels: () => fetchJSON<MoaConfigResponse>("/api/model/moa"),
saveMoaModels: (body: MoaConfigResponse) =>
fetchJSON<MoaConfigResponse & { ok: boolean }>("/api/model/moa", {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
}),
setModelAssignment: (body: ModelAssignmentRequest) =>
fetchJSON<ModelAssignmentResponse>("/api/model/set", {
method: "POST",
@ -2017,6 +2025,20 @@ export interface AuxiliaryModelsResponse {
main: { provider: string; model: string };
}
export interface MoaModelSlot {
provider: string;
model: string;
}
export interface MoaConfigResponse {
reference_models: MoaModelSlot[];
aggregator: MoaModelSlot;
reference_temperature: number;
aggregator_temperature: number;
max_tokens: number;
enabled: boolean;
}
export interface ModelAssignmentRequest {
confirm_expensive_model?: boolean;
scope: "main" | "auxiliary";

View file

@ -16,6 +16,8 @@ import { api } from "@/lib/api";
import type {
AuxiliaryModelsResponse,
AuxiliaryTaskAssignment,
MoaConfigResponse,
MoaModelSlot,
ModelsAnalyticsModelEntry,
ModelsAnalyticsResponse,
} from "@/lib/api";
@ -533,6 +535,10 @@ type PickerTarget =
| { kind: "main" }
| { kind: "aux"; task: string };
type MoaPickerTarget =
| { kind: "reference"; index: number }
| { kind: "aggregator" };
function AuxiliaryTasksModal({
aux,
refreshKey,
@ -686,6 +692,92 @@ function AuxiliaryTasksModal({
);
}
function MoaModelsModal({
config,
refreshKey,
onClose,
onSaved,
}: {
config: MoaConfigResponse;
refreshKey: number;
onClose(): void;
onSaved(next: MoaConfigResponse): void;
}) {
const [draft, setDraft] = useState<MoaConfigResponse>(config);
const [picker, setPicker] = useState<MoaPickerTarget | null>(null);
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const slotLabel = (slot: MoaModelSlot) => `${slot.provider || "(provider)"} · ${slot.model || "(model)"}`;
const save = async () => {
setBusy(true);
setError(null);
try {
const saved = await api.saveMoaModels(draft);
onSaved(saved);
onClose();
} catch (e) {
setError(e instanceof Error ? e.message : String(e));
} finally {
setBusy(false);
}
};
return (
<div className="fixed inset-0 z-50 flex items-center justify-center bg-background/80 p-4 backdrop-blur-sm">
<Card className="max-h-[85vh] w-full max-w-2xl overflow-auto">
<CardHeader>
<CardTitle className="text-sm">Configure Mixture of Agents</CardTitle>
</CardHeader>
<CardContent className="space-y-4">
<p className="text-xs text-text-secondary">
These provider/model slots feed /moa. Reference models produce perspectives; the aggregator synthesizes private guidance for the normal Hermes agent loop.
</p>
<div className="space-y-2">
<div className="text-display text-xs font-medium tracking-wider">Reference models</div>
{draft.reference_models.map((slot, index) => (
<div key={`${slot.provider}-${slot.model}-${index}`} className="flex items-center gap-2 border border-border/50 bg-muted/20 px-3 py-2">
<div className="min-w-0 flex-1 truncate font-mono text-xs text-text-secondary">{slotLabel(slot)}</div>
<Button size="sm" outlined onClick={() => setPicker({ kind: "reference", index })}>Change</Button>
<Button size="sm" ghost disabled={draft.reference_models.length <= 1} onClick={() => setDraft((prev) => ({ ...prev, reference_models: prev.reference_models.filter((_, i) => i !== index) }))}>Remove</Button>
</div>
))}
<Button size="sm" outlined onClick={() => setDraft((prev) => ({ ...prev, reference_models: [...prev.reference_models, prev.aggregator] }))}>Add reference model</Button>
</div>
<div className="space-y-2">
<div className="text-display text-xs font-medium tracking-wider">Aggregator</div>
<div className="flex items-center gap-2 border border-border/50 bg-muted/20 px-3 py-2">
<div className="min-w-0 flex-1 truncate font-mono text-xs text-text-secondary">{slotLabel(draft.aggregator)}</div>
<Button size="sm" outlined onClick={() => setPicker({ kind: "aggregator" })}>Change</Button>
</div>
</div>
{error && <div className="text-xs text-destructive">{error}</div>}
<div className="flex justify-end gap-2 pt-2">
<Button ghost onClick={onClose} disabled={busy}>Cancel</Button>
<Button onClick={save} disabled={busy}>{busy ? "Saving…" : "Save"}</Button>
</div>
</CardContent>
</Card>
{picker && (
<ModelPickerDialog
key={`moa-picker-${refreshKey}-${picker.kind}-${picker.kind === "reference" ? picker.index : "agg"}`}
loader={api.getModelOptions}
alwaysGlobal
title="Select MoA Model"
onApply={async ({ provider, model }) => {
setDraft((prev) => {
if (picker.kind === "aggregator") return { ...prev, aggregator: { provider, model } };
return { ...prev, reference_models: prev.reference_models.map((slot, i) => i === picker.index ? { provider, model } : slot) };
});
}}
onClose={() => setPicker(null)}
/>
)}
</div>
);
}
function ModelSettingsPanel({
aux,
refreshKey,
@ -696,11 +788,17 @@ function ModelSettingsPanel({
onSaved(): void;
}) {
const [auxModalOpen, setAuxModalOpen] = useState(false);
const [moaModalOpen, setMoaModalOpen] = useState(false);
const [moa, setMoa] = useState<MoaConfigResponse | null>(null);
const [picker, setPicker] = useState<PickerTarget | null>(null);
const mainProv = aux?.main.provider ?? "";
const mainModel = aux?.main.model ?? "";
useEffect(() => {
api.getMoaModels().then(setMoa).catch(() => setMoa(null));
}, [refreshKey]);
const applyAssignment = async ({
scope,
task,
@ -792,6 +890,31 @@ function ModelSettingsPanel({
</Button>
</div>
<div className="flex min-w-0 flex-col gap-2 bg-muted/20 border border-border/50 px-3 py-2 sm:flex-row sm:items-center sm:justify-between sm:gap-3">
<div className="min-w-0 flex-1">
<div className="flex items-center gap-2 mb-0.5">
<Brain className="h-3 w-3 text-text-tertiary" />
<span className="text-display text-xs font-medium tracking-wider">
Mixture of Agents
</span>
</div>
<div className="text-xs font-mono text-text-secondary truncate">
{moa
? `${moa.reference_models.length} reference${moa.reference_models.length === 1 ? "" : "s"} · ${moa.aggregator.provider}/${shortModelName(moa.aggregator.model)}`
: "not loaded"}
</div>
</div>
<Button
size="sm"
outlined
onClick={() => setMoaModalOpen(true)}
disabled={!moa}
className="shrink-0 self-start text-xs uppercase sm:self-center"
>
Configure
</Button>
</div>
{picker && (
<ModelPickerDialog
key={`picker-${refreshKey}`}
@ -819,6 +942,18 @@ function ModelSettingsPanel({
onClose={() => setAuxModalOpen(false)}
/>
)}
{moaModalOpen && moa && (
<MoaModelsModal
config={moa}
refreshKey={refreshKey}
onSaved={(next) => {
setMoa(next);
onSaved();
}}
onClose={() => setMoaModalOpen(false)}
/>
)}
</CardContent>
</Card>
);

View file

@ -8,7 +8,7 @@ description: "Authoritative reference for Hermes built-in tools, grouped by tool
This page documents Hermes' built-in tools, grouped by toolset. Availability varies by platform, credentials, and enabled toolsets.
**Quick counts (current registry):** ~71 tools — 10 browser tools (core) + 2 CDP-gated browser tools, 4 file tools, 4 Home Assistant tools, 2 terminal tools, 2 web tools, 5 Feishu tools, 7 Spotify tools (registered by the bundled `spotify` plugin), 5 Yuanbao tools, 9 kanban tools (registered when the kanban dispatcher spawns the agent), 2 Discord tools, and a handful of standalone tools (`memory`, `clarify`, `delegate_task`, `execute_code`, `cronjob`, `session_search`, `skill_view`/`skill_manage`/`skills_list`, `text_to_speech`, `image_generate`, `video_generate`, `vision_analyze`, `video_analyze`, `mixture_of_agents`, `send_message`, `todo`, `computer_use`, `process`).
**Quick counts (current registry):** ~71 tools — 10 browser tools (core) + 2 CDP-gated browser tools, 4 file tools, 4 Home Assistant tools, 2 terminal tools, 2 web tools, 5 Feishu tools, 7 Spotify tools (registered by the bundled `spotify` plugin), 5 Yuanbao tools, 9 kanban tools (registered when the kanban dispatcher spawns the agent), 2 Discord tools, and a handful of standalone tools (`memory`, `clarify`, `delegate_task`, `execute_code`, `cronjob`, `session_search`, `skill_view`/`skill_manage`/`skills_list`, `text_to_speech`, `image_generate`, `video_generate`, `vision_analyze`, `video_analyze`, `send_message`, `todo`, `computer_use`, `process`).
:::tip MCP Tools
In addition to built-in tools, Hermes can load tools dynamically from MCP servers. MCP tools appear with the prefix `mcp_<server>_` (e.g., `mcp_github_create_issue` for the `github` MCP server). See [MCP Integration](/user-guide/features/mcp) for configuration.
@ -144,12 +144,6 @@ Registered when the agent is either (a) spawned by the kanban dispatcher (`HERME
|------|-------------|----------------------|
| `send_message` | Send a message to a connected messaging platform, or list available targets. IMPORTANT: When the user asks to send to a specific channel or person (not just a bare platform name), call send_message(action='list') FIRST to see available tar… | — |
## `moa` toolset
| Tool | Description | Requires environment |
|------|-------------|----------------------|
| `mixture_of_agents` | Route a hard problem through multiple frontier LLMs collaboratively. Makes 5 API calls (4 reference models + 1 aggregator) with maximum reasoning effort — use sparingly for genuinely difficult problems. Best for: complex math, advanced alg… | OPENROUTER_API_KEY |
## `session_search` toolset
| Tool | Description | Requires environment |

View file

@ -71,7 +71,6 @@ Or in-session:
| `kanban` | `kanban_block`, `kanban_comment`, `kanban_complete`, `kanban_create`, `kanban_heartbeat`, `kanban_link`, `kanban_list`, `kanban_show`, `kanban_unblock` | Multi-agent coordination tools. Registered for dispatcher-spawned task workers (`HERMES_KANBAN_TASK`) and for profiles that explicitly list the `kanban` toolset by name (the `all`/`*` wildcard does **not** enable it). Workers mark tasks done, block, heartbeat, comment, and create/link follow-up tasks; orchestrator profiles additionally get board-routing tools like list/unblock. |
| `memory` | `memory` | Persistent cross-session memory management. |
| `messaging` | `send_message` | Send messages to other platforms (Telegram, Discord, etc.) from within a session. |
| `moa` | `mixture_of_agents` | Multi-model consensus via Mixture of Agents. |
| `safe` | `image_generate`, `vision_analyze`, `web_extract`, `web_search` (via `includes`) | Read-only research + media generation. No file writes, no terminal, no code execution. |
| `search` | `web_search` | Web search only (without extract). |
| `session_search` | `session_search` | Search past conversation sessions. |

View file

@ -519,7 +519,7 @@ cronjob(action="create", name="weekly-news-summary",
prompt="Summarize this week's AI news: ...")
```
When `enabled_toolsets` is set on a job it wins; otherwise the `hermes tools` cron-platform config wins; otherwise Hermes falls back to the built-in defaults. This matters for cost control: carrying `moa`, `browser`, `delegation` into every tiny "fetch news" job bloats the tool-schema prompt on every LLM call.
When `enabled_toolsets` is set on a job it wins; otherwise the `hermes tools` cron-platform config wins; otherwise Hermes falls back to the built-in defaults. This matters for cost control: carrying `browser`, `delegation` into every tiny "fetch news" job bloats the tool-schema prompt on every LLM call.
### Skipping the agent entirely: `wakeAgent`

View file

@ -0,0 +1,54 @@
---
sidebar_position: 7
title: "Mixture of Agents"
description: "Use /moa to run one prompt through multiple configured models inside the normal Hermes agent loop"
---
# Mixture of Agents
Mixture of Agents is now a slash-command mode, not a model tool.
Use it when a hard prompt benefits from multiple model perspectives but still needs Hermes' normal agent loop: tool calls, follow-up iterations, interrupts, transcript persistence, and the same session context as any other message.
```bash
/moa design and implement a migration plan for this flaky test cluster
```
Hermes runs the configured reference models first, asks the configured aggregator to synthesize their guidance, then injects that private guidance into the next normal agent iteration. If the main model calls a tool, Hermes continues the usual tool loop and refreshes MoA guidance on the next model iteration.
## Configure the model set
You can configure MoA from:
- Dashboard → Models → Model Settings → Mixture of Agents
- Desktop app → Settings → Model → Mixture of Agents
- `config.yaml`
The config stores explicit provider/model pairs, so you can mix providers and use multiple models from the same provider:
```yaml
moa:
reference_models:
- provider: openai-codex
model: gpt-5.5
- provider: openrouter
model: deepseek/deepseek-v4-pro
aggregator:
provider: openrouter
model: anthropic/claude-opus-4.8
reference_temperature: 0.6
aggregator_temperature: 0.4
max_tokens: 4096
```
Defaults use one Codex OAuth model and two OpenRouter-hosted models for high-signal testing:
- `openai-codex:gpt-5.5`
- `openrouter:deepseek/deepseek-v4-pro`
- aggregator: `openrouter:anthropic/claude-opus-4.8`
## Notes
- `/moa` is per-turn. A regular message after it is not automatically MoA-routed.
- MoA is no longer listed under `hermes tools`; there is no `moa` toolset to enable.
- Credential failures on one reference model do not abort the turn. Hermes includes the failure in the synthesis context and continues with whatever models returned.

View file

@ -49,7 +49,7 @@ hermes tools
hermes tools
```
Common toolsets include `web`, `search`, `terminal`, `file`, `browser`, `vision`, `image_gen`, `moa`, `skills`, `tts`, `todo`, `memory`, `session_search`, `cronjob`, `code_execution`, `delegation`, `clarify`, `homeassistant`, `messaging`, `spotify`, `discord`, `discord_admin`, `debugging`, and `safe`.
Common toolsets include `web`, `search`, `terminal`, `file`, `browser`, `vision`, `image_gen`, `skills`, `tts`, `todo`, `memory`, `session_search`, `cronjob`, `code_execution`, `delegation`, `clarify`, `homeassistant`, `messaging`, `spotify`, `discord`, `discord_admin`, `debugging`, and `safe`.
See [Toolsets Reference](/reference/toolsets-reference) for the full set, including platform presets such as `hermes-cli`, `hermes-telegram`, and dynamic MCP toolsets like `mcp-<server>`.

View file

@ -456,7 +456,6 @@ Enable/disable via `hermes tools` (interactive) or `hermes tools enable/disable
| `feishu_drive` | Feishu (Lark) drive tools |
| `yuanbao` | Yuanbao integration tools |
| `rl` | Reinforcement learning tools (off by default) |
| `moa` | Mixture of Agents (off by default) |
Full enumeration lives in `toolsets.py` as the `TOOLSETS` dict; `_HERMES_CORE_TOOLS` is the default bundle most platforms inherit from.

View file

@ -8,7 +8,7 @@ description: "Hermes 内置工具权威参考,按工具集分组"
本页记录 Hermes 的内置工具,按工具集分组。可用性因平台、凭据和已启用的工具集而异。
**当前注册表快速统计:** 约 71 个工具 —— 10 个浏览器工具(核心)+ 2 个 CDP 门控浏览器工具、4 个文件工具、4 个 Home Assistant 工具、2 个终端工具、2 个 Web 工具、5 个 Feishu 工具、7 个 Spotify 工具(由内置 `spotify` 插件注册)、5 个 Yuanbao 工具、9 个 kanban 工具(在 kanban 调度器生成 agent 时注册)、2 个 Discord 工具,以及若干独立工具(`memory`、`clarify`、`delegate_task`、`execute_code`、`cronjob`、`session_search`、`skill_view`/`skill_manage`/`skills_list`、`text_to_speech`、`image_generate`、`video_generate`、`vision_analyze`、`video_analyze`、`mixture_of_agents`、`send_message`、`todo`、`computer_use`、`process`)。
**当前注册表快速统计:** 约 71 个工具 —— 10 个浏览器工具(核心)+ 2 个 CDP 门控浏览器工具、4 个文件工具、4 个 Home Assistant 工具、2 个终端工具、2 个 Web 工具、5 个 Feishu 工具、7 个 Spotify 工具(由内置 `spotify` 插件注册)、5 个 Yuanbao 工具、9 个 kanban 工具(在 kanban 调度器生成 agent 时注册)、2 个 Discord 工具,以及若干独立工具(`memory`、`clarify`、`delegate_task`、`execute_code`、`cronjob`、`session_search`、`skill_view`/`skill_manage`/`skills_list`、`text_to_speech`、`image_generate`、`video_generate`、`vision_analyze`、`video_analyze`、`send_message`、`todo`、`computer_use`、`process`)。
:::tip MCP 工具
除内置工具外,Hermes 还可从 MCP 服务器动态加载工具。MCP 工具以 `mcp_<server>_` 为前缀(例如,`github` MCP 服务器的 `mcp_github_create_issue`)。配置方法见 [MCP 集成](/user-guide/features/mcp)。
@ -143,12 +143,6 @@ description: "Hermes 内置工具权威参考,按工具集分组"
|------|------|----------|
| `send_message` | 向已连接的消息平台发送消息,或列出可用目标。重要:当用户要求发送到特定频道或人员(而非仅平台名称)时,请先调用 `send_message(action='list')` 查看可用目标… | — |
## `moa` 工具集
| 工具 | 描述 | 所需环境 |
|------|------|----------|
| `mixture_of_agents` | 将难题路由给多个前沿 LLM 协作处理。进行 5 次 API 调用(4 个参考模型 + 1 个聚合器),以最大推理力度运行——请谨慎用于真正困难的问题。最适合:复杂数学、高级算法… | OPENROUTER_API_KEY |
## `session_search` 工具集
| 工具 | 描述 | 所需环境 |

View file

@ -70,7 +70,6 @@ hermes tools # curses UI to enable/disable per platfo
| `kanban` | `kanban_block`, `kanban_comment`, `kanban_complete`, `kanban_create`, `kanban_heartbeat`, `kanban_link`, `kanban_list`, `kanban_show`, `kanban_unblock` | 多 agent 协调工具。为调度器生成的任务工作者(`HERMES_KANBAN_TASK`)以及显式启用 `kanban` 工具集的 profile 注册。工作者可标记任务完成、阻塞、心跳、评论以及创建/关联后续任务;编排器 profile 还额外获得看板路由工具,如 list/unblock。 |
| `memory` | `memory` | 持久化跨会话记忆管理。 |
| `messaging` | `send_message` | 在会话中向其他平台(Telegram、Discord 等)发送消息。 |
| `moa` | `mixture_of_agents` | 通过 Mixture of Agents 实现多模型共识。 |
| `safe` | `image_generate`, `vision_analyze`, `web_extract`, `web_search`(通过 `includes`) | 只读研究 + 媒体生成。无文件写入、无终端、无代码执行。 |
| `search` | `web_search` | 仅网页搜索(不含提取)。 |
| `session_search` | `session_search` | 搜索历史会话记录。 |

View file

@ -67,6 +67,7 @@ const sidebars: SidebarsConfig = {
'user-guide/features/honcho',
'user-guide/features/context-files',
'user-guide/features/context-references',
'user-guide/features/mixture-of-agents',
'user-guide/features/personality',
'user-guide/features/skins',
'user-guide/features/plugins',