Skip to content

The agent that grows with you

fix(agent): preserve None cache_disabled when MoA has no agent

686f6c618e1a351e827d
diff --git a/agent/moa_loop.py b/agent/moa_loop.py
index d56121b864a..cefef3114d7 100644
--- a/agent/moa_loop.py
+++ b/agent/moa_loop.py
@@ -1691,6 +1691,16 @@ class MoAChatCompletions:
# plan_cache_sections_for_destination never mutates its inputs
# and always returns request-local copies, so the prepared
# state stays canonical.
+ # Tri-state: only pass a bool when a live agent snapshot exists.
+ # Prepared-aggregator facades built via __new__ have no _agent;
+ # getattr(self._agent, ...) raises and bool(None-agent) would
+ # force False and suppress the planner's config fallback (#76085).
+ _agent = getattr(self, "_agent", None)
+ _cache_disabled = (
+ getattr(_agent, "_cache_disabled", None)
+ if _agent is not None
+ else None
+ )
agg_messages, tools = plan_cache_sections_for_destination(
planning_messages,
tools,
@@ -1698,9 +1708,7 @@ class MoAChatCompletions:
base_url=agg_runtime.get("base_url") or "",
api_mode=agg_runtime.get("api_mode") or "",
model=agg_runtime.get("model") or "",
- cache_disabled=bool(
- getattr(self._agent, "_cache_disabled", False)
- ),
+ cache_disabled=_cache_disabled,
)
if guidance:
_attach_reference_guidance(agg_messages, str(guidance))
diff --git a/tests/agent/test_cache_disabled_on_stubs.py b/tests/agent/test_cache_disabled_on_stubs.py
index 925167a8535..cd0844071d7 100644
--- a/tests/agent/test_cache_disabled_on_stubs.py
+++ b/tests/agent/test_cache_disabled_on_stubs.py
@@ -169,3 +169,92 @@ class TestMoASlotDecorationHonorsDisable:
):
out = _maybe_apply_moa_cache_control(messages, runtime)
assert not _has_cache_control(out)
+
+
+class TestPreparedAggregatorNoAgentConfigOff:
+ """Prepared-aggregator facades from ``MoAChatCompletions.__new__`` have
+ no ``_agent``. The planner must not raise and must honor config-off.
+ """
+
+ def test_prepared_aggregator_without_agent_honors_config_off(self):
+ import copy
+
+ from agent import moa_loop
+
+ calls = []
+ with (
+ patch.object(
+ moa_loop,
+ "call_llm",
+ side_effect=lambda **kwargs: calls.append(kwargs) or SimpleNamespace(
+ choices=[SimpleNamespace(
+ message=SimpleNamespace(content="ok", tool_calls=[]),
+ finish_reason="stop",
+ )],
+ usage=None,
+ model="fake",
+ ),
+ ),
+ patch.object(
+ moa_loop,
+ "_slot_runtime",
+ return_value={
+ "provider": "anthropic",
+ "model": "claude-sonnet-4-6",
+ "base_url": "https://api.anthropic.com",
+ "api_mode": "anthropic_messages",
+ },
+ ),
+ patch(
+ "hermes_cli.config.load_config_readonly",
+ return_value={"prompt_caching": {"cache_ttl": "off"}},
+ ),
+ ):
+ completions = moa_loop.MoAChatCompletions.__new__(
+ moa_loop.MoAChatCompletions
+ )
+ # No _agent attribute — the regression surface from review.
+ completions._pending_trace = None
+ prepared = {
+ "messages": [
+ {"role": "system", "content": "system"},
+ {"role": "user", "content": "lookup"},
+ {
+ "role": "assistant",
+ "content": "",
+ "tool_calls": [{
+ "id": "lookup",
+ "function": {"name": "lookup", "arguments": "{}"},
+ }],
+ },
+ {
+ "role": "tool",
+ "tool_call_id": "lookup",
+ "content": "result",
+ },
+ ],
+ "guidance": None,
+ "aggregator": {
+ "provider": "anthropic",
+ "model": "claude-sonnet-4-6",
+ },
+ "aggregator_temperature": None,
+ }
+ tools = [{
+ "type": "function",
+ "function": {
+ "name": "lookup",
+ "parameters": {"type": "object", "properties": {}},
+ },
+ }]
+ canonical_tools = copy.deepcopy(tools)
+
+ completions._call_prepared_aggregator(prepared, {"tools": tools})
+
+ assert calls, "prepared aggregator must still call the LLM"
+ assert not _has_cache_control(calls[0].get("tools") or []), (
+ "config cache_ttl=off with no live _agent must not inject "
+ "cache_control (planner config fallback, not forced False)."
+ )
+ assert not _has_cache_control(calls[0].get("messages") or [])
+ assert tools == canonical_tools