Conversation
There was a problem hiding this comment.
Pull request overview
Fixes MoA’s reference_max_tokens cap being ignored by ensuring the auxiliary request-kwargs builder can conditionally include an output-token limit for MoA reference/aggregator calls.
Changes:
- Add
taskplumbing intoagent/auxiliary_client.py::_build_call_kwargs()and thread it through all internal call sites so MoA calls can be treated specially. - Add MoA-focused regression tests asserting that MoA tasks include a token cap while non-MoA auxiliary tasks keep the “omit max_tokens by default” behavior.
- Adjust retry paths to preserve the
taskcontext during same-provider retries and fallback calls.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| agent/auxiliary_client.py | Threads task into _build_call_kwargs() and uses it to decide when to include an output token cap (MoA tasks). |
| tests/agent/test_auxiliary_client.py | Adds regression tests covering MoA vs non-MoA max_tokens behavior in _build_call_kwargs(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| _is_moa = bool(task) and str(task).startswith("moa_") | ||
| if ( | ||
| _is_anthropic_compat_endpoint(provider, _effective_base) | ||
| or _is_nvidia_nim | ||
| or _is_moa | ||
| ): | ||
| kwargs["max_tokens"] = max_tokens |
| base_url=base_url, | ||
| task="moa_reference", | ||
| ) | ||
| assert kwargs["max_tokens"] == 800 |
Related: competing/superset of #58261 (which forwards |
6fc4103 to
e9e2507
Compare
PR NousResearch#56756 added reference_max_tokens to cap MoA advisor output and cut turn latency. The value is correctly threaded through five layers of MoA code (moa_config → conversation_loop → aggregate_moa_context → _run_references_parallel → _run_reference → call_llm(task='moa_reference', max_tokens=800, ...)). However, _build_call_kwargs() in auxiliary_client.py silently drops max_tokens for all OpenAI-compatible providers (PR NousResearch#34845, which fixed endpoints and NVIDIA NIM keep it. This means reference_max_tokens never reached the API for the vast majority of providers. The bug affects every OpenAI-compatible MoA reference/aggregator slot: Z.AI (coding plan), OpenRouter, OpenAI, GitHub Copilot, and local providers. Only Anthropic-compat endpoints (MiniMax, /anthropic URLs) worked — by coincidence, not MoA-aware design. Fix: thread the 'task' parameter through all six _build_call_kwargs() call sites. When task starts with 'moa_', max_tokens is always included in the request kwargs regardless of provider. Non-MoA auxiliary tasks (compression, titles, vision, etc.) keep PR NousResearch#34845 behavior unchanged. Verified end-to-end: - Z.AI GLM-5.2 with max_tokens=50 → returned exactly 50 tokens - Z.AI GLM-5.2 with max_tokens=20 → returned exactly 20 tokens - Z.AI GLM-5.2 uncapped → returned 315 tokens - 7 new regression tests covering 4 providers, Anthropic wire, non-MoA tasks, and prefix-matching boundary - 288 auxiliary_client tests pass (was 281, +7 new), 84 MoA tests pass - Zero regressions
Copilot review pointed out that hardcoding kwargs['max_tokens'] would 400 on models requiring max_completion_tokens (GPT-5 family, Copilot). The existing auxiliary_max_tokens_param() helper already selects the correct parameter name per model — use it instead of hardcoding. Test updated to parametrize expected_key so the Copilot gpt-5.5 case correctly asserts max_completion_tokens instead of max_tokens. Addresses Copilot review comments on both files.
e9e2507 to
1ae2d5a
Compare
teknium1
left a comment
There was a problem hiding this comment.
Thanks for tracing the cap through the auxiliary request builder; the underlying reference-path omission is real on current main (agent/moa_loop.py:317-324, agent/auxiliary_client.py:6382-6414).
Problems
- The new broad
moa_gate also coversmoa_aggregator. In the one-shot path,agent/conversation_loop.py:892passesreference_max_tokensintoaggregate_moa_context, andagent/moa_loop.py:722-727forwards that same value to the aggregator. Sending it after this change contradicts the advisors-only contract inwebsite/docs/user-guide/features/mixture-of-agents.md:112-116.
Suggested changes
- Limit the builder exception to
task == "moa_reference", rather than themoa_prefix. - Add a one-shot regression asserting the configured reference cap reaches advisor calls but not the
moa_aggregatorcall.
Automated hermes-sweeper review.
| ) | ||
| _is_moa = bool(task) and str(task).startswith("moa_") | ||
| if ( | ||
| _is_anthropic_compat_endpoint(provider, _effective_base) |
There was a problem hiding this comment.
This also matches moa_aggregator. Current one-shot MoA passes reference_max_tokens through to that aggregator (agent/conversation_loop.py:892; agent/moa_loop.py:722-727), while the documented contract says this cap applies to advisors only. Restrict this exception to task == "moa_reference".
Per review feedback from teknium1: reference_max_tokens is an advisors-only
contract. The aggregator is the acting model and must not be capped by the
reference budget. Changed _is_moa from startswith('moa_') to exact match on
'moa_reference'. Added regression test proving aggregator does NOT receive
max_tokens.
|
Pushed `818ab4a` — scoped to exact match `task == "moa_reference"`. Added `test_moa_aggregator_does_not_get_max_tokens_on_openai_compat` proving the aggregator keeps getting max_tokens dropped. Renamed the prefix test to `test_moa_task_exact_match` covering both `moa_aggregator` and `moa_custom_future` as exclusions. PR description updated to reflect advisors-only scope. |
Summary
The
reference_max_tokensconfig option (added in PR #56756 on Jul 2, 2026) is silentlyignored for all OpenAI-compatible providers. The value travels correctly through five layers
of MoA code (
moa_config.py→conversation_loop.py→aggregate_moa_context()→_run_references_parallel()→_run_reference()→call_llm(task="moa_reference", max_tokens=800, ...)), but the final delivery layer —_build_call_kwargs()inauxiliary_client.py— dropsmax_tokensfor any provider that isn't Anthropic-compatibleor NVIDIA NIM.
This means the cap never worked for any user on OpenRouter, Z.AI (coding plan endpoint),
OpenAI, local providers, or GitHub Copilot. Every reference call ran uncapped regardless of
the config setting.
Root Cause — Two PRs That Collided
_build_call_kwargs()stop sendingmax_tokensfor all OpenAI-compatible providers (fix for #34530 — Copilot GPT-5 models 400 onmax_tokens). Only Anthropic-compat endpoints keep it.reference_max_tokensconfig option. Wired it throughmoa_loop.pyandconversation_loop.py(5 files, 117 insertions). Did NOT touchauxiliary_client.py— the file wheremax_tokensgets dropped.Same author wrote both PRs one month apart. The second PR added the config key, 5 unit tests,
official docs, and correct wiring — but didn't realize the final delivery layer would silently
discard the value. No existing test caught this because the tests only exercise
_build_call_kwargs()with providers where
max_tokensis already dropped (OpenAI-compat), so they assert its absenceand pass.
The code that drops it
agent/auxiliary_client.py,_build_call_kwargs():Affected Providers
api.z.ai/api/coding/paas/v4openrouter.ai/api/v1api.openai.com/v1api.githubcopilot.comlocalhost:xxxx/anthropicendpointsThe Fix
Thread the
taskparameter through all six_build_call_kwargs()call sites. Whentaskstarts with
moa_,max_tokensis always included in the request kwargs regardless of provider.3 changes:
task: Optional[str] = Noneparameter to_build_call_kwargs()signature_is_moa = bool(task) and str(task).startswith("moa_")check in themax_tokensblocktask=taskfrom all six callers (call_llmmain + fallback,async_call_llmmain + fallback,_retry_same_provider_sync,_retry_same_provider_async)Non-MoA auxiliary tasks (compression, titles, vision, etc.) keep PR #34845 behavior unchanged —
max_tokensis still dropped for OpenAI-compatible endpoints. No regressions.Verification
End-to-end API calls (real Z.AI endpoint, GLM-5.2)
max_tokensTests
TestBuildCallKwargsMaxTokens:task="moa_reference"→ all sendmax_tokenstask="moa_aggregator"→ unchanged Anthropic-compat behaviormax_tokensmoa_reference✓,moa_custom_future✓,mopha_reference✗