The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(agent): drop dead Responses quirk fields; MoA slot headers go through route_answer
Teknium5af8fda75f2e
diff --git a/agent/codex_responses_adapter.py b/agent/codex_responses_adapter.pyindex fa3452d74bf..9c683e7ed17 100644--- a/agent/codex_responses_adapter.py+++ b/agent/codex_responses_adapter.py@@ -26,10 +26,8 @@ class ResponsesEndpointQuirks(NamedTuple):replay_item_ids: bool = Trueprompt_cache_key: bool = Trueissuer_kind: str = ""- trusts_completed_status: bool = Truenative_compaction: bool = Trueprofile_reasoning: bool = False- profile: Any = None_GENERIC_ENDPOINT = ResponsesEndpointQuirks()@@ -45,9 +43,8 @@ def responses_endpoint_quirks(base_url: Any) -> ResponsesEndpointQuirks:return _GENERIC_ENDPOINTreturn ResponsesEndpointQuirks(replay_item_ids=profile.responses_replay_item_ids, prompt_cache_key=profile.responses_prompt_cache_key,- issuer_kind=profile.responses_issuer_kind, trusts_completed_status=profile.responses_trusts_completed_status,- native_compaction=profile.responses_native_compaction, profile_reasoning=profile.responses_profile_reasoning,- profile=profile,+ issuer_kind=profile.responses_issuer_kind, native_compaction=profile.responses_native_compaction,+ profile_reasoning=profile.responses_profile_reasoning,)diff --git a/agent/moa_loop.py b/agent/moa_loop.pyindex ed24e4d527f..cdfaa30c0ea 100644--- a/agent/moa_loop.py+++ b/agent/moa_loop.py@@ -393,22 +393,20 @@ def _price_reference_response(return usage, None, None, None-def _slot_request_headers(runtime: dict[str, Any]) -> dict[str, str] | None:+def _slot_request_headers(runtime: dict[str, Any], agent: Any = None) -> dict[str, str] | None:"""User-initiated request headers of the slot's provider, attributed at that provider's own endpoint- (MoA attributes by slot provider, whatever account host the slot resolved to)."""+ (MoA attributes by slot provider, whatever account host the slot resolved to). Asked like every+ per-request hook (``route_answer``: memoized, one failure policy for the agent's session)."""from agent.auxiliary_client import _normalize_aux_provider+ from agent.provider_route_hooks import route_answerfrom providers import get_provider_profileprovider = _normalize_aux_provider(str(runtime.get("provider") or ""))profile = get_provider_profile(provider) if provider else Noneif profile is None:return None- try:- return profile.request_headers(base_url=profile.base_url, model=str(runtime.get("model") or ""),- user_initiated=True) or None- except Exception: # plugin code: a broken hook must not fail the reference call- logger.debug("MoA slot %s request_headers failed", provider, exc_info=True)- return None+ return route_answer("request_headers", provider=provider, base_url=profile.base_url or "",+ model=str(runtime.get("model") or ""), user_initiated=True, scope=agent)def _run_reference(@@ -438,7 +436,7 @@ def _run_reference(# Providers may gate premium models on request attribution; MoA fan-out serves the# user's current turn, so mirror the main agent's user-initiated request headers.- initiator_headers = _slot_request_headers(runtime)+ initiator_headers = _slot_request_headers(runtime, agent)if agent is not None:from agent.auxiliary_client import aux_progress_hookdiff --git a/tests/agent/test_moa_slot_request_headers.py b/tests/agent/test_moa_slot_request_headers.pynew file mode 100644index 00000000000..f9633968487--- /dev/null+++ b/tests/agent/test_moa_slot_request_headers.py@@ -0,0 +1,55 @@+"""MoA reference slots ask a provider's ``request_headers`` through the same route as the main loop:+memoized, and a failing hook keeps the agent's session on the generic answer."""++from types import SimpleNamespace++import pytest+++def slot_profile(request, monkeypatch):+ import providers+ from agent import provider_route_hooks+ from providers.base import ProviderProfile++ state = {"calls": 0, "fail": False}++ class SlotProfile(ProviderProfile):+ def request_headers(self, *, base_url, model="", user_initiated=False):+ state["calls"] += 1+ if state["fail"]:+ raise RuntimeError("plugin bug")+ return {"X-Slot": "user"} if user_initiated else {}++ monkeypatch.setattr(provider_route_hooks, "_WARNED", set(), raising=False)+ providers.list_providers()+ providers.register_provider(SlotProfile(name="moaslot", base_url="https://api.moaslot.test/v1"))++ def _cleanup():+ providers._REGISTRY.pop("moaslot", None)+ providers._SOURCES.pop("moaslot", None)+ providers._PROVIDER_LIST_CACHE = None++ request.addfinalizer(_cleanup)+ return state+++def test_slot_headers_are_memoized_per_request_shape(slot_profile):+ from agent.moa_loop import _slot_request_headers++ runtime = {"provider": "moaslot", "model": "m"}+ for _ in range(3):+ assert _slot_request_headers(runtime, SimpleNamespace()) == {"X-Slot": "user"}+ assert slot_profile["calls"] == 1+++def test_failing_slot_hook_stays_generic_for_the_agent_session(slot_profile):+ from agent.moa_loop import _slot_request_headers++ runtime = {"provider": "moaslot", "model": "m"}+ agent = SimpleNamespace()+ slot_profile["fail"] = True+ assert _slot_request_headers(runtime, agent) is None+ slot_profile["fail"] = False+ assert _slot_request_headers(runtime, agent) is None # no flip mid-session+ assert _slot_request_headers(runtime, SimpleNamespace()) == {"X-Slot": "user"} # a new session asks again