Skip to content

The agent that grows with you

refactor(providers): generic endpoint seams for Responses quirks, reasoning payloads and carriers

Teknium0ae220ff4e09
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py
index a2a26784c6b..a017fc1f2c6 100644
--- a/agent/auxiliary_client.py
+++ b/agent/auxiliary_client.py
@@ -1417,11 +1417,9 @@ class _CodexCompletionsAdapter:
model = kwargs.get("model", self._model)
wire_model = _wire_model_identity(model)
host = str(getattr(self._client, "base_url", "") or "")
- is_copilot = base_url_host_matches(host, "githubcopilot.com")
# Same route classifier as the main transport, so the issuer stamp matches what it minted.
route = classify_responses_route(SimpleNamespace(provider=None, base_url=host))
is_xai = route.is_xai_responses
- is_github = route.is_github_responses
tools = kwargs.get("tools")
if tools:
# xAI Responses rejects ``pattern``/``format`` JSON Schema keywords (400); strip for
@@ -1467,8 +1465,8 @@ class _CodexCompletionsAdapter:
for tc in msg["tool_calls"]
]}
replay_messages.append(msg)
- # Copilot binds replayed codex_message_items ids to a backend connection that doesn't
- # survive credential rotation (401 on replay) — same guard as build_kwargs. Aux calls
+ # Endpoints that bind replayed codex_message_items ids to a backend connection 401 on a stale id
+ # (``replay_item_ids=False``) — same guard as build_kwargs. Aux calls
# never send ``context_management`` (main-turn feature): no compaction checkpoint.
# Auxiliary calls (context compression, flush_memories, MoA aggregation) go through this adapter
# instead of agent/transports/codex.py's build_kwargs, so they need the same guard applied
@@ -1476,7 +1474,7 @@ class _CodexCompletionsAdapter:
# Aux requests run their own model; stamp/filter reasoning provenance against it, not the main agent's.
issuer_kind = _classify_responses_issuer(base_url=host, **route._asdict())
input_items = _chat_messages_to_responses_input(
- replay_messages, is_github_responses=is_copilot,
+ replay_messages, drop_replay_item_ids=not route.endpoint.replay_item_ids,
current_issuer_kind=issuer_kind,
current_issuer_model=wire_model, native_compaction_eligible=False,
)
@@ -1490,7 +1488,7 @@ class _CodexCompletionsAdapter:
timeout = kwargs.get("timeout")
if timeout is not None:
resp_kwargs["timeout"] = timeout
- # Per-request HTTP headers (OpenCode session affinity, Copilot x-initiator) map to real
+ # Per-request HTTP headers (OpenCode session affinity, provider request headers) map to real
# headers via the SDK kwarg — forward them.
if isinstance(kwargs.get("extra_headers"), dict) and kwargs["extra_headers"]:
resp_kwargs["extra_headers"] = dict(kwargs["extra_headers"])
@@ -1526,14 +1524,14 @@ class _CodexCompletionsAdapter:
# Stable prompt-cache routing: key is content-addressed from the static prefix
# (instructions + tool schemas) so it survives across turns, scoped by the owning
# conversation (rotation-stable logical scope, else the physical session id). Skip the
- # key where the main transport does: xAI takes it in extra_body, GitHub opts out.
+ # key where the main transport does: xAI takes it in extra_body, ``prompt_cache_key=False`` endpoints opt out.
try:
# Reuse the Responses transport's single authoritative hash algorithm and session-scope
# normalization so equivalent static prefixes route to the same cache bucket across modes,
# without concentrating unrelated sessions into one shared bucket (see #78941).
from agent.transports.codex import _cache_scope_from_session_id, _content_cache_key
from agent.transports.codex import _default_prompt_cache_retention_for_request
- if not (is_xai or is_github) and "prompt_cache_key" not in resp_kwargs:
+ if not is_xai and route.endpoint.prompt_cache_key and "prompt_cache_key" not in resp_kwargs:
scope = _cache_scope_from_session_id(
_runtime_main_value("cache_scope") or _runtime_main_value("session_id")
)
diff --git a/agent/chat_completion_helpers.py b/agent/chat_completion_helpers.py
index b4ca409edb2..cd49c341bfb 100644
--- a/agent/chat_completion_helpers.py
+++ b/agent/chat_completion_helpers.py
@@ -1402,11 +1402,11 @@ def _build_bedrock_kwargs(agent, api_messages, tools_for_api, reasoning_config):
def _build_codex_kwargs(agent, api_messages, tools_for_api, reasoning_config, request_overrides, cache_scope_id):
from agent.codex_responses_adapter import classify_responses_route
from agent.native_compaction import native_compaction_context_management
- is_codex_backend, is_xai_responses, is_github_responses = classify_responses_route(agent)
+ is_codex_backend, is_xai_responses, endpoint = classify_responses_route(agent)
# Native server-side compaction (gpt-5.6 on direct OpenAI / ChatGPT Codex routes
# only) — None on every other route/model, leaving the request unchanged.
context_management = native_compaction_context_management(agent, is_codex_backend=is_codex_backend,
- is_xai_responses=is_xai_responses, is_github_responses=is_github_responses)
+ is_xai_responses=is_xai_responses, endpoint=endpoint)
# xAI's /responses endpoint 400s on ``pattern``/``format`` schema keywords and on
# ``enum`` values containing ``/`` — strip them (#27197). Deep-copy first: the
# sanitizers mutate in place and tools_for_api aliases agent.tools (#27907).
@@ -1426,9 +1426,9 @@ def _build_codex_kwargs(agent, api_messages, tools_for_api, reasoning_config, re
cache_scope_id=cache_scope_id, base_url=agent.base_url,
max_tokens=ephemeral_out if ephemeral_out is not None else agent.max_tokens,
timeout=agent._resolved_api_call_timeout(), request_overrides=request_overrides,
- provider=getattr(agent, "provider", None), is_github_responses=is_github_responses,
+ provider=getattr(agent, "provider", None),
is_codex_backend=is_codex_backend, is_xai_responses=is_xai_responses,
- github_reasoning_extra=agent._github_models_reasoning_extra_body() if is_github_responses else None,
+ profile_reasoning=agent._endpoint_reasoning_payload() if endpoint.profile_reasoning else None,
replay_encrypted_reasoning=bool(getattr(agent, "_codex_reasoning_replay_enabled", True)),
context_management=context_management, text_verbosity=getattr(agent, "text_verbosity", None))
@@ -1441,8 +1441,9 @@ def _build_chat_completions_kwargs(agent, api_messages, tools_for_api, reasoning
_is_qwen = agent._is_qwen_portal()
_is_or = agent._is_openrouter_url()
_host = agent._base_url_lower
- _is_gh = base_url_host_matches(_host, "models.github.ai") or base_url_host_matches(_host, "githubcopilot.com")
_is_lmstudio = (agent.provider or "").strip().lower() == "lmstudio"
+ from agent.endpoint_profile import endpoint_profile
+ _profile_endpoint = endpoint_profile(agent.base_url) is not None
# _fixed_temperature_for_model may return the OMIT_TEMPERATURE sentinel
# (temperature omitted entirely), a numeric override, or None.
@@ -1487,7 +1488,6 @@ def _build_chat_completions_kwargs(agent, api_messages, tools_for_api, reasoning
is_openrouter=_is_or,
is_nous=base_url_host_matches(_host, "nousresearch.com"),
is_qwen_portal=_is_qwen,
- is_github_models=_is_gh,
is_nvidia_nim=base_url_host_matches(_host, "integrate.api.nvidia.com"),
is_kimi=any(base_url_host_matches(agent.base_url, h) for h in ("api.kimi.com", "moonshot.ai", "moonshot.cn")),
is_tokenhub=base_url_host_matches(_host, "tokenhub.tencentmaas.com"),
@@ -1496,7 +1496,7 @@ def _build_chat_completions_kwargs(agent, api_messages, tools_for_api, reasoning
qwen_prepare_inplace_fn=agent._qwen_prepare_chat_messages_inplace if _is_qwen else None,
fixed_temperature=_fixed_temp,
omit_temperature=_omit_temp,
- github_reasoning_extra=agent._github_models_reasoning_extra_body() if _is_gh else None,
+ profile_endpoint=_profile_endpoint, endpoint_reasoning=agent._endpoint_reasoning_payload() if _profile_endpoint else None,
provider_name=agent.provider,
)
@@ -1628,7 +1628,7 @@ def _assistant_tool_call_dict(agent, tool_call, index: int) -> dict:
extra = getattr(tool_call, "extra_content", None)
if extra is not None:
tc_dict["extra_content"] = _dump_if_model(extra)
- # Copilot's Gemini 3 variant signs the call inside ``function`` (replayed only to Copilot).
+ # Some gateways sign Gemini 3 calls inside ``function`` (replayed only where the endpoint profile asks).
from agent.reasoning_carriers import field
fn_sig = field(tool_call, "thought_signature") or getattr(tool_call.function, "thought_signature", None)
if isinstance(fn_sig, str) and fn_sig:
@@ -1731,7 +1731,7 @@ def build_assistant_message(agent, assistant_message, finish_reason: str) -> dic
from agent.reasoning_carriers import carrier_record
if record := carrier_record(assistant_message):
- # Gemini text-turn signature / Copilot reasoning_opaque+text: top-level for the live
+ # Gemini text-turn signature / profile-declared reasoning carriers: top-level for the live
# history, a private reasoning_details record for persistence (reasoning_carriers.py).
msg.update({k: v for k, v in record.items() if k != "type"})
msg["reasoning_details"] = [*msg.get("reasoning_details", ()), record]
@@ -1864,7 +1864,7 @@ def _fallback_api_mode_resolved(agent, fb_provider: str, fb_model: str, fb_base_
return "anthropic_messages"
if agent._is_azure_openai_url(fb_base_url):
return "chat_completions" # Azure serves gpt-5.x on /chat/completions — no Responses API.
- # Provider exceptions (Copilot gpt-5-mini) stay inside the requires-responses predicate.
+ # Per-model provider exceptions stay inside the requires-responses predicate.
if agent._is_direct_openai_url(fb_base_url) or agent._provider_model_requires_responses_api(fb_model, provider=fb_provider):
return "codex_responses"
host = base_url_hostname(fb_base_url)
@@ -3121,7 +3121,7 @@ class _StreamingCall(StreamingWaitMonitor):
# whose deltas carry only this field otherwise trips the empty-stream guard (#56516).
if reasoning_text is None and isinstance(getattr(delta, "model_extra", None), dict):
reasoning_text = delta.model_extra.get("reasoning_content") or delta.model_extra.get("reasoning")
- # Copilot /chat/completions names its readable reasoning ``reasoning_text``.
+ # A profile-declared text carrier doubles as the readable reasoning.
reasoning_text = carriers.feed(delta, reasoning_text)
if reasoning_text:
# Summary-part models omit the separator between markdown blocks; re-insert it.
diff --git a/agent/chat_completion_helpers_tool_calls.py b/agent/chat_completion_helpers_tool_calls.py
index 638087db08a..d22426dac62 100644
--- a/agent/chat_completion_helpers_tool_calls.py
+++ b/agent/chat_completion_helpers_tool_calls.py
@@ -98,7 +98,7 @@ class _ToolCallAccumulator:
entry["function"]["name"] = tc_function.name
if getattr(tc_function, "arguments", None):
parts.append(tc_function.arguments)
- # Copilot's Gemini 3 variant signs the call inside ``function``.
+ # Some gateways sign Gemini 3 calls inside ``function``.
if isinstance(fn_sig := field(tc_function, "thought_signature"), str) and fn_sig:
entry["thought_signature"] = fn_sig
extra = getattr(tc_delta, "extra_content", None)
diff --git a/agent/codex_responses_adapter.py b/agent/codex_responses_adapter.py
index 8d6d9bfe8a5..c944a1e004b 100644
--- a/agent/codex_responses_adapter.py
+++ b/agent/codex_responses_adapter.py
@@ -1,5 +1,6 @@
"""Codex Responses API adapter: stateless format conversion and normalization for the
-OpenAI Responses API (OpenAI Codex, xAI, GitHub Models and other compatible endpoints)."""
+OpenAI Responses API (OpenAI Codex, xAI and other compatible endpoints; per-endpoint quirks come from the
+provider profile that claims the endpoint, see :func:`responses_endpoint_quirks`)."""
from __future__ import annotations
@@ -19,13 +20,51 @@ from hermes_cli.route_identity import normalize_route_base_url
logger = logging.getLogger(__name__)
+class ResponsesEndpointQuirks(NamedTuple):
+ """Responses wire quirks of the endpoint, from the ``responses_*`` fields of the profile claiming it
+ (``ProviderProfile.serves_endpoint``). Defaults are the generic wire."""
+ replay_item_ids: bool = True
+ prompt_cache_key: bool = True
+ issuer_kind: str = ""
+ trusts_completed_status: bool = True
+ native_compaction: bool = True
+ profile_reasoning: bool = False
+ profile: Any = None
+
+
+_GENERIC_ENDPOINT = ResponsesEndpointQuirks()
+
+
+def responses_endpoint_quirks(base_url: Any) -> ResponsesEndpointQuirks:
+ """Quirks for *base_url*; the generic wire when no registered profile claims it (or none is installed).
+ Pure function of the URL and the registry, so every turn replays the same bytes for the same history."""
+ from agent.endpoint_profile import endpoint_profile
+
+ profile = endpoint_profile(base_url)
+ if profile is None:
+ return _GENERIC_ENDPOINT
+ return 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,
+ )
+
+
+def drops_replay_item_ids(base_url: Any) -> bool:
+ """Preflight flag: True when *base_url*'s endpoint binds replayed message-item ids to a connection."""
+ return not responses_endpoint_quirks(base_url).replay_item_ids
+
+
def _classify_responses_issuer(
- *, is_xai_responses: bool = False, is_github_responses: bool = False, is_codex_backend: bool = False,
- base_url: Optional[str] = None,
+ *, is_xai_responses: bool = False, is_codex_backend: bool = False, base_url: Optional[str] = None,
+ endpoint: Optional[ResponsesEndpointQuirks] = None,
) -> str:
"""Stable identifier for the endpoint that mints ``reasoning.encrypted_content``. Blobs are sealed to their
- issuer (HTTP 400 ``invalid_encrypted_content``), so stamping lets replay drop foreign blobs after a model switch."""
- for flag, kind in ((is_xai_responses, "xai_responses"), (is_github_responses, "github_responses"), (is_codex_backend, "codex_backend")):
+ issuer (HTTP 400 ``invalid_encrypted_content``), so stamping lets replay drop foreign blobs after a model switch.
+ ``endpoint`` contributes the claiming profile's persisted ``responses_issuer_kind``."""
+ endpoint_kind = endpoint.issuer_kind if endpoint is not None else ""
+ for flag, kind in ((is_xai_responses, "xai_responses"), (bool(endpoint_kind), endpoint_kind), (is_codex_backend, "codex_backend")):
if flag:
return kind
if not base_url:
@@ -447,15 +486,16 @@ def _role_message_item(role: str, content: Any, phase: Any = None) -> dict[str,
def _assistant_message_item(
- raw: dict[str, Any], content: list[dict[str, Any]], *, is_github_responses: bool,
+ raw: dict[str, Any], content: list[dict[str, Any]], *, drop_replay_item_ids: bool,
current_issuer_kind: Optional[str] = None,
) -> dict[str, Any]:
- """Replayable assistant ``message`` item from a stored one. ``id`` is kept only when short enough and never for
- GitHub Copilot (ids bind to a backend connection; stale → 401); ``phase`` is preserved per OpenAI's cache guidance.
+ """Replayable assistant ``message`` item from a stored one. ``id`` is kept only when short enough and never on an
+ endpoint that binds ids to a backend connection (``drop_replay_item_ids``; stale → 401); ``phase`` is preserved
+ per OpenAI's cache guidance.
The ChatGPT Codex backend additionally rejects ids that do not begin with ``msg`` (foreign Responses issuers
mint short UUIDs), so those are dropped there while other issuers' policies are unchanged."""
item_id, phase = raw.get("id"), raw.get("phase")
- keep_id = not is_github_responses and _nonblank(item_id) and len(item_id.strip()) <= _MAX_RESPONSES_ITEM_ID_LENGTH
+ keep_id = not drop_replay_item_ids and _nonblank(item_id) and len(item_id.strip()) <= _MAX_RESPONSES_ITEM_ID_LENGTH
if keep_id and current_issuer_kind == "codex_backend" and not item_id.strip().startswith("msg"):
keep_id = False
return _message_item(
@@ -505,7 +545,7 @@ def _replay_reasoning_items(
def _replay_message_items(
- msg: dict[str, Any], *, is_github_responses: bool, current_issuer_kind: Optional[str] = None,
+ msg: dict[str, Any], *, drop_replay_item_ids: bool, current_issuer_kind: Optional[str] = None,
) -> list[dict[str, Any]]:
"""Replay exact assistant message items (id/phase) for prefix-cache hits.
@@ -532,7 +572,7 @@ def _replay_message_items(
if linked_to_reasoning and raw_item.get("id"):
raw_item = {k: v for k, v in raw_item.items() if k != "id"}
replayed.append(_assistant_message_item(
- raw_item, content, is_github_responses=is_github_responses, current_issuer_kind=current_issuer_kind,
+ raw_item, content, drop_replay_item_ids=drop_replay_item_ids, current_issuer_kind=current_issuer_kind,
))
return replayed
@@ -609,7 +649,7 @@ def _tool_output_items(msg: dict[str, Any], *, wire_ids: Optional[_WireCallIds]
def _chat_messages_to_responses_input(
- messages: list[dict[str, Any]], *, is_xai_responses: bool = False, is_github_responses: bool = False,
+ messages: list[dict[str, Any]], *, is_xai_responses: bool = False, drop_replay_item_ids: bool = False,
replay_encrypted_reasoning: bool = True, current_issuer_kind: Optional[str] = None,
current_issuer_model: Optional[str] = None, native_compaction_eligible: bool = False,
) -> list[dict[str, Any]]:
@@ -618,7 +658,7 @@ def _chat_messages_to_responses_input(
``is_xai_responses``: signature compatibility only (xAI DOES replay encrypted reasoning).
``replay_encrypted_reasoning``: per-session kill switch, threaded False by
``AIAgent._disable_codex_reasoning_replay`` after a repeat ``invalid_encrypted_content`` 400.
- ``is_github_responses``: drops ``id`` from replayed message items (Copilot 401s on stale ids).
+ ``drop_replay_item_ids``: drops ``id`` from replayed message items (endpoint quirk ``replay_item_ids=False``).
``current_issuer_kind`` / ``current_issuer_model``: provenance guard; items stamped by another issuer or
model drop. Legacy items carrying only an endpoint stamp replay on a matching issuer.
``native_compaction_eligible``: THIS request carries ``context_management``; gates both replaying ``compaction``
@@ -632,11 +672,10 @@ def _chat_messages_to_responses_input(
cross-turn coherence (the whole point of their partnership integration). We now replay encrypted
reasoning on every Responses transport (xAI, native Codex, custom relays) and let xAI tell us explicitly
if a specific surface ever rejects a payload.
- The Copilot backend (api.githubcopilot.com/responses) binds these ids to a specific backend "connection"
- — credential-pool rotation, a gateway restart, or routine load-balancer churn between turns all
- invalidate it — and rejects a stale id with HTTP 401 "input item ID does not belong to this connection"
- even for short ids (see #32716). ``phase``/ ``status``/``content`` are still replayed; only ``id`` is
- unsafe to reuse across a Copilot connection.
+ Some backends bind these ids to a specific backend "connection" — credential-pool rotation, a gateway
+ restart, or routine load-balancer churn between turns all invalidate it — and reject a stale id with HTTP 401
+ "input item ID does not belong to this connection" even for short ids (see #32716). ``phase``/``status``/
+ ``content`` are still replayed there; only ``id`` is unsafe to reuse across such a connection.
``native_compaction_eligible`` mirrors, for THIS request, the decision made by
``native_compaction.native_compaction_context_management`` — it is True only when that gate returned a
payload, i.e. when the request actually carries ``context_management``. It controls two things that must
@@ -694,7 +733,7 @@ def _chat_messages_to_responses_input(
)
emit(reasoning_items, msg)
message_items = _replay_message_items(
- msg, is_github_responses=is_github_responses, current_issuer_kind=current_issuer_kind,
+ msg, drop_replay_item_ids=drop_replay_item_ids, current_issuer_kind=current_issuer_kind,
)
emit(message_items, msg)
fallback = None
@@ -731,7 +770,7 @@ def _chat_messages_to_responses_input(
class ResponsesRouteFlags(NamedTuple):
"""Which special Responses-API route an agent is talking to. Single owner of the
- codex/xai/github predicates — every site must call :func:`classify_responses_route`.
+ codex/xai predicates and the endpoint quirks — every site must call :func:`classify_responses_route`.
Every site that needs these flags (request kwargs build, preflight estimation, silent- reject hints)
must call :func:`classify_responses_route` instead of re-implementing the string comparisons inline —
@@ -739,12 +778,12 @@ class ResponsesRouteFlags(NamedTuple):
"""
is_codex_backend: bool
is_xai_responses: bool
- is_github_responses: bool
+ endpoint: ResponsesEndpointQuirks
def classify_responses_route(agent: Any) -> ResponsesRouteFlags:
"""Classify the agent's Responses route from provider + base URL. Host checks are
- exact-host-or-subdomain, never substring (``evil.com/models.github.ai`` is not GitHub)."""
+ exact-host-or-subdomain, never substring (``evil.com/chatgpt.com`` is not ChatGPT)."""
from utils import base_url_hostname
provider = getattr(agent, "provider", None)
base_url = str(getattr(agent, "base_url", "") or "")
@@ -755,7 +794,7 @@ def classify_responses_route(agent: Any) -> ResponsesRouteFlags:
return ResponsesRouteFlags(
is_codex_backend=provider == "openai-codex" or (_host_is("chatgpt.com") and "/backend-api/codex" in lower),
is_xai_responses=provider in {"xai", "xai-oauth"} or hostname == "api.x.ai",
- is_github_responses=_host_is("models.github.ai") or _host_is("githubcopilot.com"),
+ endpoint=responses_endpoint_quirks(base_url),
)
@@ -774,7 +813,8 @@ def _native_responses_replay_items(
effective_model = effective_request_overrides(agent).get("model", getattr(agent, "model", None))
try:
items = _chat_messages_to_responses_input(
- messages, is_xai_responses=route["is_xai_responses"], is_github_responses=route["is_github_responses"],
+ messages, is_xai_responses=route["is_xai_responses"],
+ drop_replay_item_ids=not route["endpoint"].replay_item_ids,
replay_encrypted_reasoning=bool(getattr(agent, "_codex_reasoning_replay_enabled", True)),
current_issuer_kind=_classify_responses_issuer(base_url=getattr(agent, "base_url", None), **route),
current_issuer_model=_wire_model_identity(effective_model),
@@ -822,7 +862,7 @@ def estimate_native_responses_preflight_tokens(
class _PreflightCtx(NamedTuple):
sanitize_text: Callable[[str], str]
sanitize_harmony_tokens: bool
- is_github_responses: bool
+ drop_replay_item_ids: bool
seen_ids: set
@@ -901,7 +941,7 @@ def _preflight_message(item: dict[str, Any], idx: int, ctx: _PreflightCtx) -> di
normalized_content.append({"type": "output_text", "text": ctx.sanitize_text(_str_or_empty(part.get("text", "")))})
if not normalized_content:
raise ValueError(f"Codex Responses input[{idx}] message item must contain at least one text part.")
- return _assistant_message_item(item, normalized_content, is_github_responses=ctx.is_github_responses)
+ return _assistant_message_item(item, normalized_content, drop_replay_item_ids=ctx.drop_replay_item_ids)
def _preflight_role_message(item: dict[str, Any], idx: int, ctx: _PreflightCtx) -> dict[str, Any]:
@@ -944,12 +984,12 @@ _PREFLIGHT_ITEM_HANDLERS: dict[str, Callable[..., Optional[dict[str, Any]]]] = {
def _preflight_codex_input_items(
- raw_items: Any, *, is_github_responses: bool = False, sanitize_harmony_tokens: bool = False,
+ raw_items: Any, *, drop_replay_item_ids: bool = False, sanitize_harmony_tokens: bool = False,
) -> list[dict[str, Any]]:
if not isinstance(raw_items, list):
raise ValueError("Codex Responses input must be a list of input items.")
sanitize_text = _neutralize_harmony_tokens if sanitize_harmony_tokens else (lambda text: text)
- ctx = _PreflightCtx(sanitize_text, sanitize_harmony_tokens, is_github_responses, set())
+ ctx = _PreflightCtx(sanitize_text, sanitize_harmony_tokens, drop_replay_item_ids, set())
normalized: list[dict[str, Any]] = []
for idx, item in enumerate(raw_items):
if not isinstance(item, dict):
@@ -1014,7 +1054,7 @@ def _optional_dict(api_kwargs: dict[str, Any], key: str) -> Optional[dict[str, A
def _preflight_codex_api_kwargs(
- api_kwargs: Any, *, allow_stream: bool = False, is_github_responses: bool = False,
+ api_kwargs: Any, *, allow_stream: bool = False, drop_replay_item_ids: bool = False,
sanitize_harmony_tokens: bool = False,
) -> dict[str, Any]:
if not isinstance(api_kwargs, dict):
@@ -1028,7 +1068,7 @@ def _preflight_codex_api_kwargs(
if sanitize_harmony_tokens:
instructions = _neutralize_harmony_tokens(instructions)
input_items = _preflight_codex_input_items(
- api_kwargs.get("input"), is_github_responses=is_github_responses, sanitize_harmony_tokens=sanitize_harmony_tokens,
+ api_kwargs.get("input"), drop_replay_item_ids=drop_replay_item_ids, sanitize_harmony_tokens=sanitize_harmony_tokens,
)
normalized: dict[str, Any] = {
"model": model.strip(), "instructions": instructions, "input": input_items, "store": False,
@@ -1218,6 +1258,15 @@ class _OutputScan:
))
+def _untrusted_completed_issuers() -> frozenset:
+ """Issuer kinds whose reasoning-only ``completed`` status is not final (once per normalized response)."""
+ from providers import list_providers
+
+ declared = (p.responses_issuer_kind for p in list_providers()
+ if p.responses_issuer_kind and not p.responses_trusts_completed_status)
+ return frozenset({"codex_backend", "xai_responses", *declared})
+
+
def _normalize_codex_response(
response: Any, *, issuer_kind: Optional[str] = None, issuer_model: Optional[str] = None,
recover_leaked_tool_call: bool = True,
@@ -1290,11 +1339,12 @@ def _normalize_codex_response(
# Leaked text must not be replayed as a completed assistant message on the continuation.
codex_message_items=None if leaked_tool_call_text else (scan.message_items_raw or None),
)
- # Reasoning-only: for Codex/xAI/GitHub, status=completed means "still thinking" → incomplete so the continuation
- # retries. Other backends trust response.status — forcing incomplete there stalls for minutes on a final state.
+ # Reasoning-only: for Codex/xAI (and endpoints declaring ``responses_trusts_completed_status=False``),
+ # status=completed means "still thinking" → incomplete so the continuation retries. Other backends trust
+ # response.status — forcing incomplete there stalls for minutes on a final state.
reasoning_only = (scan.reasoning_items_raw or reasoning_parts or scan.saw_reasoning_item) and not final_text
trusted_final = (
- response_status == "completed" and issuer_kind not in ("codex_backend", "xai_responses", "github_responses")
+ response_status == "completed" and issuer_kind not in _untrusted_completed_issuers()
)
if tool_calls:
finish_reason = "tool_calls"
diff --git a/agent/codex_runtime.py b/agent/codex_runtime.py
index 27b89aeaee6..3436c38f357 100644
--- a/agent/codex_runtime.py
+++ b/agent/codex_runtime.py
@@ -959,7 +959,7 @@ class _CodexResponseAssembler:
def _pending_function_key(self, item_id: str, output_index: Any) -> str | None:
if item_id in self.pending_function_calls:
return item_id
- # Copilot rotates opaque item IDs between SSE events. The response-local
+ # Some Responses backends rotate opaque item IDs between SSE events. The response-local
# output_index still identifies the call, including index zero.
if output_index is not None:
return next((key for key, pending in self.pending_function_calls.items()
diff --git a/agent/endpoint_profile.py b/agent/endpoint_profile.py
new file mode 100644
index 00000000000..2d97c966c7d
--- /dev/null
+++ b/agent/endpoint_profile.py
@@ -0,0 +1,30 @@
+"""Resolve the provider profile that claims an endpoint URL (``ProviderProfile.serves_endpoint``).
+
+Endpoint wire quirks belong to the backend, not to the configured provider name: a ``custom`` entry
+pointed at a provider's host gets that host's quirks, and a provider entry pointed at a relay does not.
+"""
+
+from __future__ import annotations
+
+import logging
+from typing import Any
+
+logger = logging.getLogger(__name__)
+
+
+def endpoint_profile(base_url: Any) -> Any:
+ """The registered profile whose ``serves_endpoint`` claims *base_url*, else None (generic wire).
+
+ Lazy and per-home: it walks ``providers.list_providers()`` on each call, so a user plugin
+ discovered later in the process (or bound to another profile home) is honoured. Fails open.
+ """
+ url = str(base_url or "").strip()
+ if not url:
+ return None
+ try:
+ from providers import list_providers
+
+ return next((p for p in list_providers() if p.serves_endpoint(url)), None)
+ except Exception: # plugin-owned hook (possibly hosted over IPC): a broken plugin degrades to the generic wire
+ logger.debug("endpoint profile lookup failed for %s", url, exc_info=True)
+ return None
diff --git a/agent/message_sanitization.py b/agent/message_sanitization.py
index f0eb59cb49b..b5c82f1c1d5 100644
--- a/agent/message_sanitization.py
+++ b/agent/message_sanitization.py
@@ -874,7 +874,7 @@ def apply_reasoning_content_policy(
else:
api_msg.pop(R, None)
if carriers is not None and RD not in carriers:
- # Private ``*.native_assistant`` records (Gemini/Copilot carriers) survive: the transport lifts
+ # Private ``*.native_assistant`` records (Gemini / profile-declared carriers) survive: the transport lifts
# them onto the route that reads them and filters them from every other wire.
private = [d for d in api_msg.pop(RD, None) or () if isinstance(d, dict)
and str(d.get("type") or "").endswith(".native_assistant")]
diff --git a/agent/native_compaction.py b/agent/native_compaction.py
index 3a03bf500fe..8d849dc5819 100644
--- a/agent/native_compaction.py
+++ b/agent/native_compaction.py
@@ -107,9 +107,11 @@ def _warn_native_compaction_suppressed_by_checkpoint_gate() -> None:
def native_compaction_context_management(agent: Any, *, is_codex_backend: bool, is_xai_responses: bool = False,
- is_github_responses: bool = False) -> Optional[list[dict[str, Any]]]:
+ endpoint: Any = None) -> Optional[list[dict[str, Any]]]:
"""Return the ``context_management`` payload for this request, or None ("do not send").
+ ``endpoint`` is the route's ``ResponsesEndpointQuirks``; ``native_compaction=False`` never sends.
+
Every gate is re-checked per request so a mid-session model switch or the in-session
kill switch (``agent.codex_responses_native_compaction = False``) takes effect next call.
"""
@@ -125,7 +127,7 @@ def native_compaction_context_management(agent: Any, *, is_codex_backend: bool,
if getattr(agent, "compression_checkpoint_required", False) is True:
_warn_native_compaction_suppressed_by_checkpoint_gate()
return None
- if is_xai_responses or is_github_responses or not is_native_compaction_model(
+ if is_xai_responses or (endpoint is not None and not endpoint.native_compaction) or not is_native_compaction_model(
getattr(agent, "model", None), provider=getattr(agent, "provider", None),
base_url=getattr(agent, "base_url", None),
):
diff --git a/agent/reasoning_carriers.py b/agent/reasoning_carriers.py
index 632e61773b4..5f7fefe53a9 100644
--- a/agent/reasoning_carriers.py
+++ b/agent/reasoning_carriers.py
@@ -3,21 +3,40 @@
* Gemini text-turn ``thought_signature`` (message-level ``extra_content.google`` on the OpenAI-compat
and Vertex endpoints; the non-functionCall ``thoughtSignature`` part on the native API). Replaying it
makes the server rehydrate the turn's thoughts (live: 31 -> 237/250 prompt tokens).
-* GitHub Copilot ``/chat/completions`` ``reasoning_text`` / ``reasoning_opaque`` (top-level assistant
- keys, replayed by the Copilot editor clients) and the Gemini-3 ``function.thought_signature``.
+* Top-level assistant keys a provider profile declares (``ProviderProfile.message_carrier_opaque`` /
+ ``message_carrier_text``: an opaque reasoning blob and its readable text), plus the tool-call
+ ``function.thought_signature`` some gateways sign Gemini 3 calls with.
Capture stores them top-level on the live assistant dict AND as ONE private ``reasoning_details`` record,
so they persist in the existing column and survive gateway/resume replay. Its type ends in ``.native_assistant``, which no profile declares, so
the chat-completions transport never forwards the record itself; ``shape_wire_carriers`` lifts each
-field back onto the wire copy only for the route that reads it and strips it everywhere else.
+field back onto the wire copy only for the route that reads it (the endpoint profile's
+``replay_message_carriers``) and strips it everywhere else, including keys of records whose declaring
+plugin is no longer installed.
"""
from __future__ import annotations
-from typing import Any, Optional
+from typing import Any, NamedTuple, Optional
CARRIER_TYPE = "hermes.native_assistant"
-_MESSAGE_KEYS = ("extra_content", "reasoning_opaque", "reasoning_text")
+_GEMINI_KEY = "extra_content"
+
+
+def declared_carrier_keys() -> tuple[tuple[str, ...], tuple[str, ...]]:
+ """``(opaque keys, text keys)`` declared by the registered profiles, in registration order. Call once per
+ message/stream/request, never per delta."""
+ from providers import list_providers
+
+ profiles = list_providers()
+ opaque = (p.message_carrier_opaque for p in profiles if p.message_carrier_opaque)
+ text = (p.message_carrier_text for p in profiles if p.message_carrier_text)
+ return tuple(dict.fromkeys(opaque)), tuple(dict.fromkeys(text))
+
+
+def _message_keys() -> tuple[str, ...]:
+ opaque, text = declared_carrier_keys()
+ return (_GEMINI_KEY, *dict.fromkeys(opaque + text))
def field(obj: Any, name: str) -> Any:
@@ -42,9 +61,9 @@ def thought_signature(extra: Any) -> Optional[str]:
def carrier_record(assistant_message: Any) -> Optional[dict]:
"""The private ``reasoning_details`` record for one response message, or None when it has no carrier."""
record: dict[str, Any] = {}
- if sig := thought_signature(field(assistant_message, "extra_content")):
- record["extra_content"] = {"google": {"thought_signature": sig}}
- for key in ("reasoning_opaque", "reasoning_text"):
+ if sig := thought_signature(field(assistant_message, _GEMINI_KEY)):
+ record[_GEMINI_KEY] = {"google": {"thought_signature": sig}}
+ for key in _message_keys()[1:]:
value = field(assistant_message, key)
if isinstance(value, str) and value:
record[key] = value
@@ -52,25 +71,29 @@ def carrier_record(assistant_message: Any) -> Optional[dict]:
class StreamCarriers:
- """Accumulates the carriers from streamed deltas: the latest signature / opaque blob (Claude on
- Copilot sends a new opaque before each tool call; the editor clients replay only the latest) and
- the concatenated ``reasoning_text``."""
+ """Accumulates the carriers from streamed deltas: the latest signature / opaque blob per declared key (a
+ provider may send a new opaque before each tool call and expect only the latest back) and the concatenated
+ text of each declared text key. Keys are resolved once per stream."""
def __init__(self) -> None:
+ self.opaque_keys, self.text_keys = declared_carrier_keys()
self.signature: Optional[str] = None
- self.opaque: Optional[str] = None
- self.text_parts: list[str] = []
+ self.opaque: dict[str, str] = {}
+ self.text_parts: dict[str, list[str]] = {}
def feed(self, delta: Any, reasoning: Optional[str]) -> Optional[str]:
- """Absorb one delta; returns ``reasoning``, else its ``reasoning_text`` fragment (Copilot's readable reasoning)."""
- self.signature = thought_signature(field(delta, "extra_content")) or self.signature
- opaque = field(delta, "reasoning_opaque")
- self.opaque = opaque if isinstance(opaque, str) and opaque else self.opaque
- text = field(delta, "reasoning_text")
- if not (isinstance(text, str) and text):
- return reasoning
- self.text_parts.append(text)
- return text if reasoning is None else reasoning
+ """Absorb one delta; returns ``reasoning``, else its first declared text-carrier fragment (readable reasoning)."""
+ self.signature = thought_signature(field(delta, _GEMINI_KEY)) or self.signature
+ for key in self.opaque_keys:
+ opaque = field(delta, key)
+ if isinstance(opaque, str) and opaque:
+ self.opaque[key] = opaque
+ for key in self.text_keys:
+ text = field(delta, key)
+ if isinstance(text, str) and text:
+ self.text_parts.setdefault(key, []).append(text)
+ reasoning = text if reasoning is None else reasoning
+ return reasoning
def apply(self, response: Any) -> None:
choices = getattr(response, "choices", None)
@@ -79,21 +102,30 @@ class StreamCarriers:
return
if self.signature:
message.extra_content = {"google": {"thought_signature": self.signature}}
- if self.opaque:
- message.reasoning_opaque = self.opaque
- if self.text_parts:
- message.reasoning_text = "".join(self.text_parts)
+ for key, value in self.opaque.items():
+ setattr(message, key, value)
+ for key, parts in self.text_parts.items():
+ setattr(message, key, "".join(parts))
+
+class _WireRoute(NamedTuple):
+ model: Any
+ base_url: str
+ gemini: bool # the route consumes the Gemini text-turn signature
+ profile: Any # endpoint profile (``ProviderProfile.serves_endpoint``) or None
+ keep_fn_sig: bool # replayed tool calls keep ``function.thought_signature``
+ keys: tuple[str, ...] # every message-level carrier key core knows about
-def _route_reads(model: Any, base_url: Any) -> tuple[str, ...]:
- """Message-level carrier keys this route consumes."""
+
+def _wire_route(model: Any, base_url: Any) -> _WireRoute:
+ from agent.endpoint_profile import endpoint_profile
from agent.transports.chat_completions import _model_consumes_thought_signature
- from utils import base_url_host_matches
+ url = str(base_url or "")
+ profile = endpoint_profile(url)
+ keep_fn_sig = profile is not None and profile.replays_function_thought_signature(model=model, base_url=url)
# Same gate as tool-call extra_content, so the two signature carriers can never disagree.
- gemini = ("extra_content",) if _model_consumes_thought_signature(model) else ()
- copilot = ("reasoning_opaque", "reasoning_text") if base_url_host_matches(str(base_url or ""), "githubcopilot.com") else ()
- return gemini + copilot
+ return _WireRoute(model, url, _model_consumes_thought_signature(model), profile, keep_fn_sig, _message_keys())
def _strip_function_signature(tool_calls: list) -> list:
@@ -105,7 +137,7 @@ def _strip_function_signature(tool_calls: list) -> list:
]
-def _shape(msg: Any, reads: tuple[str, ...], copilot: bool) -> Any:
+def _shape(msg: Any, route: _WireRoute) -> Any:
if not isinstance(msg, dict) or msg.get("role") != "assistant":
return msg
details = msg.get("reasoning_details")
@@ -113,24 +145,26 @@ def _shape(msg: Any, reads: tuple[str, ...], copilot: bool) -> Any:
record = next((d for d in details if isinstance(d, dict) and d.get("type") == CARRIER_TYPE), None)
tool_calls = msg.get("tool_calls")
tool_calls = tool_calls if isinstance(tool_calls, list) else []
- fn_sig = not copilot and any(
+ fn_sig = not route.keep_fn_sig and any(
isinstance(tc, dict) and isinstance(tc.get("function"), dict) and "thought_signature" in tc["function"]
for tc in tool_calls)
- if record is None and not fn_sig and not any(k in msg for k in _MESSAGE_KEYS):
+ # A persisted record's own keys are stripped too, so rows from an uninstalled provider plugin never leak.
+ keys = route.keys if record is None else (*route.keys, *(k for k in record if k != "type" and k not in route.keys))
+ if record is None and not fn_sig and not any(k in msg for k in keys):
return msg
- out = {k: v for k, v in msg.items() if k not in _MESSAGE_KEYS}
+ out = {k: v for k, v in msg.items() if k not in keys}
# Live history carries the keys top-level; a resumed row only has the persisted record.
- values = {**(record or {}), **{k: msg[k] for k in _MESSAGE_KEYS if k in msg}}
+ values = {**(record or {}), **{k: msg[k] for k in keys if k in msg}}
if record is not None:
rest = [d for d in details if d is not record]
if rest:
out["reasoning_details"] = rest
else:
out.pop("reasoning_details", None)
- for key in reads:
- # Copilot clients send reasoning_text only next to the opaque blob it belongs to.
- if values.get(key) and (key != "reasoning_text" or values.get("reasoning_opaque")):
- out[key] = values[key]
+ if route.gemini and values.get(_GEMINI_KEY):
+ out[_GEMINI_KEY] = values[_GEMINI_KEY]
+ if route.profile is not None:
+ out.update(route.profile.replay_message_carriers(values, model=route.model, base_url=route.base_url))
if fn_sig:
out["tool_calls"] = _strip_function_signature(tool_calls)
return out
@@ -139,9 +173,6 @@ def _shape(msg: Any, reads: tuple[str, ...], copilot: bool) -> Any:
def shape_wire_carriers(messages: list, *, model: Any, base_url: Any) -> list:
"""Wire copy of ``messages`` with each carrier on the route that reads it and nowhere else.
Never mutates the input; unchanged messages are returned by identity."""
- from utils import base_url_host_matches
-
- reads = _route_reads(model, base_url)
- copilot = base_url_host_matches(str(base_url or ""), "githubcopilot.com")
- shaped = [_shape(m, reads, copilot) for m in messages]
+ route = _wire_route(model, base_url)
+ shaped = [_shape(m, route) for m in messages]
return messages if all(a is b for a, b in zip(shaped, messages)) else shaped
diff --git a/agent/reasoning_params.py b/agent/reasoning_params.py
index b3e9dc95d25..2c094613fbb 100644
--- a/agent/reasoning_params.py
+++ b/agent/reasoning_params.py
@@ -1,6 +1,6 @@
"""Provider reasoning-parameter policy for ``AIAgent``.
-When ``reasoning`` extra_body is safe to send, LM Studio / Ollama / GitHub Models capability probes,
+When ``reasoning`` extra_body is safe to send, LM Studio / Ollama / endpoint-profile capability probes,
``reasoning_content`` echo families, and strict-API tool-call sanitising.
Extracted from ``run_agent.py``; every method resolves through ``AIAgent``'s MRO unchanged.
"""
@@ -92,11 +92,12 @@ class ReasoningParamsMixin:
url = self._base_url_lower
if base_url_host_matches(url, "nousresearch.com") or base_url_host_matches(url, "ai-gateway.vercel.sh"):
return True
- if base_url_host_matches(url, "models.github.ai") or base_url_host_matches(url, "githubcopilot.com"):
- try:
- from hermes_cli.models import github_model_reasoning_efforts
+ from agent.endpoint_profile import endpoint_profile
- return bool(github_model_reasoning_efforts(self.model))
+ if (profile := endpoint_profile(getattr(self, "base_url", None))) is not None:
+ # A claimed endpoint gates on its own catalog: reasoning goes out iff it declares a payload.
+ try:
+ return profile.reasoning_payload(self.model, None, base_url=self.base_url) is not None
except Exception:
return False
if (self.provider or "").strip().lower() == "lmstudio":
@@ -137,21 +138,16 @@ class ReasoningParamsMixin:
return False
return bool(_cached_probe(self, "_ollama_thinking_cache", ollama_model_supports_thinking, None, lambda v: v is not None))
- def _github_models_reasoning_extra_body(self) -> dict | None:
- """Format reasoning payload for GitHub Models/OpenAI-compatible routes."""
- try:
- from hermes_cli.models import clamp_github_reasoning_effort, github_model_reasoning_efforts
- except Exception:
- return None
-
- supported = github_model_reasoning_efforts(self.model)
- if not supported:
- return None
+ def _endpoint_reasoning_payload(self) -> dict | None:
+ """``reasoning_payload`` of the profile claiming this endpoint for the agent's model and
+ ``reasoning_config`` (``ProviderProfile.serves_endpoint``), or None when no profile claims it."""
+ from agent.endpoint_profile import endpoint_profile
- cfg = self.reasoning_config if isinstance(self.reasoning_config, dict) else {}
- if cfg.get("enabled") is False:
+ base_url = getattr(self, "base_url", None)
+ profile = endpoint_profile(base_url)
+ if profile is None:
return None
- return {"effort": clamp_github_reasoning_effort(cfg.get("effort"), supported)}
+ return profile.reasoning_payload(self.model, self.reasoning_config, base_url=str(base_url))
def _build_assistant_message(self, assistant_message, finish_reason: str) -> dict:
"""``build_assistant_message``; a held turn's row with visible text comes back typed hidden
diff --git a/agent/transports/chat_completions.py b/agent/transports/chat_completions.py
index 9e4ef960801..2e288d0a9fb 100644
--- a/agent/transports/chat_completions.py
+++ b/agent/transports/chat_completions.py
@@ -96,8 +96,8 @@ def _add_prompt_cache_key(
# Responses calls stay cache-cold while the main Responses transport is warm (issue #53735). The key is
# content-addressed from the static prefix (instructions + tool schemas) so it stays warm across
# turns/fires. Guard the top-level field the same way the main transport does: xAI Responses takes the
- # key in extra_body (not top-level) and GitHub/Copilot Responses opts out of cache-key routing entirely
- # — for those hosts, skip it here.
+ # key in extra_body (not top-level) and endpoints declaring ``responses_prompt_cache_key=False`` opt out
+ # of cache-key routing entirely — for those hosts, skip it here.
from agent.transports.codex import (
_bound_prompt_cache_key_field, _cache_scope_from_session_id, _content_cache_key
)
@@ -265,7 +265,18 @@ def _is_openai_api_base_url(base_url: Any) -> bool:
_GEMINI_SIGNATURE_HOSTS = ("generativelanguage.googleapis.com", "aiplatform.googleapis.com")
-_GEMINI_SIGNATURE_PROVIDERS = frozenset({"gemini", "vertex", "copilot"})
+_GEMINI_SIGNATURE_PROVIDERS = frozenset({"gemini", "vertex"})
+
+
+def _profile_replays_tool_call_signatures(provider: Any) -> bool:
+ """``ProviderProfile.replays_tool_call_signatures`` for the provider named exactly (canonical name only)."""
+ name = (provider or "").strip().lower()
+ if not name:
+ return False
+ from providers import get_provider_profile
+
+ profile = get_provider_profile(name)
+ return profile is not None and profile.name == name and profile.replays_tool_call_signatures
def _model_consumes_thought_signature(model: Any, base_url: Any = None, provider: Any = None) -> bool:
@@ -280,6 +291,7 @@ def _model_consumes_thought_signature(model: Any, base_url: Any = None, provider
return (
"gemini" in m or "gemma" in m
or (provider or "").strip().lower() in _GEMINI_SIGNATURE_PROVIDERS
+ or _profile_replays_tool_call_signatures(provider)
or any(base_url_host_matches(base_url, host) for host in _GEMINI_SIGNATURE_HOSTS)
)
@@ -604,9 +616,10 @@ class ChatCompletionsTransport(ProviderTransport):
extra_body["thinking"] = {"type": "disabled" if thinking_off else "enabled"}
if supports_reasoning:
- if params.get("is_github_models", False):
- if params.get("github_reasoning_extra") is not None:
- extra_body["reasoning"] = params["github_reasoning_extra"]
+ # An endpoint claimed by a profile (ProviderProfile.serves_endpoint) takes its verbatim payload.
+ if params.get("profile_endpoint", False):
+ if params.get("endpoint_reasoning") is not None:
+ extra_body["reasoning"] = params["endpoint_reasoning"]
else:
_effort = (reasoning_config.get("effort", "medium") or "medium") if reasoning_config and isinstance(reasoning_config, dict) else "medium"
# Honor explicit "thinking off" like the profile path — never re-enable it.
@@ -714,8 +727,12 @@ class ChatCompletionsTransport(ProviderTransport):
provider_data["reasoning_content"] = reasoning_content
if getattr(msg, "reasoning_details", None):
provider_data["reasoning_details"] = msg.reasoning_details
- # Message-level carriers (Gemini text-turn signature, Copilot reasoning): agent/reasoning_carriers.py.
- for key in ("extra_content", "reasoning_opaque", "reasoning_text"):
+ # Message-level carriers (Gemini text-turn signature, profile-declared reasoning keys):
+ # agent/reasoning_carriers.py.
+ from agent.reasoning_carriers import declared_carrier_keys
+
+ opaque_keys, text_keys = declared_carrier_keys()
+ for key in dict.fromkeys(("extra_content", *opaque_keys, *text_keys)):
if (value := _attr_or_model_extra(msg, key)) is not None:
provider_data[key] = _dump_extra_content(value)
@@ -733,8 +750,9 @@ class ChatCompletionsTransport(ProviderTransport):
return NormalizedResponse(
content=content, tool_calls=tool_calls, finish_reason=finish_reason,
- # Copilot /chat/completions names its readable reasoning ``reasoning_text``.
- reasoning=getattr(msg, "reasoning", None) or provider_data.get("reasoning_text"), usage=usage,
+ # A profile-declared text carrier doubles as the readable reasoning (first declared wins).
+ reasoning=getattr(msg, "reasoning", None) or next(
+ (provider_data[k] for k in text_keys if provider_data.get(k)), None), usage=usage,
provider_data=provider_data or None,
)
@@ -752,7 +770,7 @@ class ChatCompletionsTransport(ProviderTransport):
name = alias_map.get(name, name)
arguments = getattr(tc_function, "arguments", None)
extra = _attr_or_model_extra(tc, "extra_content")
- fn_sig = _attr_or_model_extra(tc_function, "thought_signature") # Copilot's Gemini 3 variant
+ fn_sig = _attr_or_model_extra(tc_function, "thought_signature") # gateway-signed Gemini 3 calls
provider_data = {k: v for k, v in (("extra_content", None if extra is None else _dump_extra_content(extra)),
("thought_signature", fn_sig)) if v is not None}
call = ToolCall(
diff --git a/agent/transports/codex.py b/agent/transports/codex.py
index 5419bb39a3d..79250215d90 100644
--- a/agent/transports/codex.py
+++ b/agent/transports/codex.py
@@ -595,12 +595,13 @@ def _sends_all_turns(model: Any, params: dict[str, Any]) -> bool:
def _reasoning_fields(
model: str, params: dict[str, Any], *, effort: Any, enabled: bool, replay_encrypted_reasoning: bool,
- is_xai_responses: bool, is_github_responses: bool, all_turns: bool = False,
+ is_xai_responses: bool, profile_reasoning: bool, all_turns: bool = False,
) -> dict[str, Any]:
"""``reasoning`` / ``include`` request fields for the endpoint family.
- xAI 400s on ``reasoning.effort`` outside its allowlist; GitHub Models takes a
- verbatim ``github_reasoning_extra`` and never ``include``. A disabled ask resolved to
+ xAI 400s on ``reasoning.effort`` outside its allowlist; a ``profile_reasoning`` endpoint
+ (``ProviderProfile.responses_profile_reasoning``) takes the verbatim ``profile_reasoning``
+ payload plus ``summary: "auto"`` and never ``include``. A disabled ask resolved to
``effort="none"`` is sent as ``{"effort": "none"}`` — the wire has no other way to switch
a reasoning model's default effort off (#75227). ``all_turns`` adds ``context: "all_turns"``
so the model renders replayed reasoning from earlier user turns (``_sends_all_turns``).
@@ -614,21 +615,17 @@ def _reasoning_fields(
if grok_supports_reasoning_effort(model):
fields["reasoning"] = {"effort": effort}
elif enabled:
- if is_github_responses:
- if params.get("github_reasoning_extra") is not None:
- # Request a reasoning summary so the Responses API actually returns
- # reasoning text. Without ``summary: "auto"`` the GitHub/Copilot
- # /responses endpoint returns reasoning items with no summary, so Hermes
- # persists empty reasoning/thinking content for every Copilot model on
- # the Responses API (gpt-5.4, gpt-5, ...) — the same loss the non-GitHub
- # branch below already avoids. Verified against api.githubcopilot.com
- # /responses: the summary is only emitted when summary="auto" is sent.
- # See #46527.
- fields["reasoning"] = {**params["github_reasoning_extra"], "summary": "auto"}
+ if profile_reasoning:
+ if params.get("profile_reasoning") is not None:
+ # Request a reasoning summary so the Responses API actually returns reasoning text:
+ # without ``summary: "auto"`` such endpoints return reasoning items with no summary and
+ # Hermes persists empty reasoning/thinking content — the same loss the generic branch
+ # below avoids (#46527).
+ fields["reasoning"] = {**params["profile_reasoning"], "summary": "auto"}
else:
fields["reasoning"] = {"effort": effort, "summary": "auto", **({"context": "all_turns"} if all_turns else {})}
fields["include"] = include
- elif not is_github_responses and not is_xai_responses:
+ elif not profile_reasoning and not is_xai_responses:
fields["include"] = []
if effort == "none":
fields["reasoning"] = {"effort": "none"}
@@ -681,28 +678,32 @@ class ResponsesApiTransport(ProviderTransport):
def api_mode(self) -> str:
return "codex_responses"
- def _resolve_issuer_kind(self, params: dict[str, Any]) -> str:
+ def _resolve_issuer_kind(self, params: dict[str, Any], endpoint: Any = None) -> str:
"""Classify the current Responses endpoint from transport params (stashed for normalize_response)."""
- from agent.codex_responses_adapter import _classify_responses_issuer
+ from agent.codex_responses_adapter import _classify_responses_issuer, responses_endpoint_quirks
+ base_url = params.get("base_url")
self._last_issuer_kind = _classify_responses_issuer(
is_xai_responses=params.get("is_xai_responses") is True,
- is_github_responses=params.get("is_github_responses") is True,
is_codex_backend=params.get("is_codex_backend") is True,
- base_url=params.get("base_url"),
+ base_url=base_url,
+ endpoint=endpoint if endpoint is not None else responses_endpoint_quirks(base_url),
)
return self._last_issuer_kind
def convert_messages(self, messages: list[dict[str, Any]], **kwargs) -> Any:
"""Convert OpenAI chat messages to Responses API input items."""
- from agent.codex_responses_adapter import _chat_messages_to_responses_input, _wire_model_identity
+ from agent.codex_responses_adapter import (
+ _chat_messages_to_responses_input, _wire_model_identity, responses_endpoint_quirks,
+ )
self._last_issuer_model = _wire_model_identity(kwargs.get("model"))
+ endpoint = kwargs.get("endpoint") or responses_endpoint_quirks(kwargs.get("base_url"))
return _chat_messages_to_responses_input(
messages, is_xai_responses=kwargs.get("is_xai_responses") is True,
- is_github_responses=kwargs.get("is_github_responses") is True,
+ drop_replay_item_ids=not endpoint.replay_item_ids,
replay_encrypted_reasoning=bool(kwargs.get("replay_encrypted_reasoning", True)),
- current_issuer_kind=self._resolve_issuer_kind(kwargs),
+ current_issuer_kind=self._resolve_issuer_kind(kwargs, endpoint),
current_issuer_model=self._last_issuer_model,
native_compaction_eligible=_native_compaction_active(kwargs.get("context_management")),
)
@@ -721,8 +722,9 @@ class ResponsesApiTransport(ProviderTransport):
params: instructions, reasoning_config ({effort, enabled}), session_id (transcript id;
Codex header; cache-scope fallback), cache_scope_id (rotation-stable scope for the
cache key / xAI conv header), max_tokens, timeout, request_overrides, provider, base_url,
- is_github_responses, is_codex_backend, is_xai_responses, github_reasoning_extra,
- context_management, replay_encrypted_reasoning.
+ is_codex_backend, is_xai_responses, profile_reasoning, context_management,
+ replay_encrypted_reasoning. Endpoint quirks (item-id replay, cache key, issuer stamp, reasoning
+ shape) are resolved from ``base_url`` via ``responses_endpoint_quirks``.
params: instructions: str — system prompt (extracted from messages[0] if not given)
reasoning_config: dict | None — {effort, enabled} session_id: str | None — transcript/session id;
@@ -734,9 +736,9 @@ class ResponsesApiTransport(ProviderTransport):
max_tokens: int | None — max_output_tokens timeout: float | None — per-request timeout forwarded to
the SDK request_overrides: dict | None — extra kwargs merged in provider: str | None — provider name
for backend-specific logic base_url: str | None — endpoint URL base_url_hostname: str | None —
- hostname for backend detection is_github_responses: bool — Copilot/GitHub models backend
- is_codex_backend: bool — chatgpt.com/backend-api/codex is_xai_responses: bool — xAI/Grok backend
- github_reasoning_extra: dict | None — Copilot reasoning params
+ hostname for backend detection is_codex_backend: bool — chatgpt.com/backend-api/codex
+ is_xai_responses: bool — xAI/Grok backend profile_reasoning: dict | None — the claiming profile's
+ ``reasoning_payload`` (sent verbatim on ``responses_profile_reasoning`` endpoints)
"""
from agent.prompt_builder import DEFAULT_AGENT_IDENTITY
@@ -747,7 +749,9 @@ class ResponsesApiTransport(ProviderTransport):
payload_messages = messages[1:]
instructions = instructions or DEFAULT_AGENT_IDENTITY
- is_github_responses = params.get("is_github_responses") is True
+ from agent.codex_responses_adapter import responses_endpoint_quirks
+
+ endpoint = responses_endpoint_quirks(params.get("base_url"))
is_codex_backend = params.get("is_codex_backend") is True
is_xai_responses = params.get("is_xai_responses") is True
# Foundry 400s on encrypted-reasoning replay only in the post-tool follow-up turn.
@@ -777,7 +781,7 @@ class ResponsesApiTransport(ProviderTransport):
"model": wire_model,
"instructions": instructions,
"input": self.convert_messages(
- payload_messages, is_xai_responses=is_xai_responses, is_github_responses=is_github_responses,
+ payload_messages, is_xai_responses=is_xai_responses, endpoint=endpoint,
replay_encrypted_reasoning=replay_encrypted_reasoning, base_url=params.get("base_url"),
is_codex_backend=is_codex_backend, context_management=context_management, model=wire_model,
),
@@ -796,8 +800,9 @@ class ResponsesApiTransport(ProviderTransport):
# compression rotation; session_id itself stays untouched for transcript isolation.
_cache_scope = _cache_scope_from_session_id(params.get("cache_scope_id") or session_id)
cache_key = _content_cache_key(instructions, response_tools, _cache_scope) or _cache_scope
- # xAI takes prompt_cache_key in extra_body (below); GitHub Models opts out entirely.
- if not is_github_responses and not is_xai_responses and cache_key:
+ # xAI takes prompt_cache_key in extra_body (below); endpoints declaring
+ # ``responses_prompt_cache_key=False`` opt out entirely.
+ if endpoint.prompt_cache_key and not is_xai_responses and cache_key:
kwargs["prompt_cache_key"] = cache_key
cache_retention = _default_prompt_cache_retention_for_request(model, params.get("base_url"))
@@ -810,7 +815,7 @@ class ResponsesApiTransport(ProviderTransport):
kwargs.update(_reasoning_fields(
model, params, effort=reasoning_effort, enabled=reasoning_enabled,
replay_encrypted_reasoning=replay_encrypted_reasoning,
- is_xai_responses=is_xai_responses, is_github_responses=is_github_responses,
+ is_xai_responses=is_xai_responses, profile_reasoning=endpoint.profile_reasoning,
all_turns=self._last_sent_all_turns,
))
# agent.text_verbosity -> top-level ``text.verbosity`` (#20203). Unset sends nothing;
@@ -947,17 +952,18 @@ class ResponsesApiTransport(ProviderTransport):
return status == "incomplete" and str(raw_reason or "").strip().lower() == "content_filter"
def preflight_kwargs(
- self, api_kwargs: Any, *, allow_stream: bool = False, is_github_responses: bool = False,
+ self, api_kwargs: Any, *, allow_stream: bool = False, drop_replay_item_ids: bool = False,
sanitize_harmony_tokens: bool = False,
) -> dict:
"""Validate and sanitize Codex API kwargs before the call.
+ ``drop_replay_item_ids`` mirrors the endpoint quirk (``not responses_endpoint_quirks(url).replay_item_ids``).
``sanitize_harmony_tokens`` is for the ChatGPT Codex backend only (rejects literal Harmony tokens).
"""
from agent.codex_responses_adapter import _preflight_codex_api_kwargs
normalized = _preflight_codex_api_kwargs(
- api_kwargs, allow_stream=allow_stream, is_github_responses=is_github_responses,
+ api_kwargs, allow_stream=allow_stream, drop_replay_item_ids=drop_replay_item_ids,
sanitize_harmony_tokens=sanitize_harmony_tokens,
)
_bound_prompt_cache_key_field(normalized)
diff --git a/agent/transports/codex_app_server.py b/agent/transports/codex_app_server.py
index 36bbf78864f..5c22aae8ec1 100644
--- a/agent/transports/codex_app_server.py
+++ b/agent/transports/codex_app_server.py
@@ -101,7 +101,7 @@ class CodexAppServerClient:
# Modal/Daytona infra tokens, the dashboard session token, AUXILIARY_* side-LLM keys,
# GATEWAY_RELAY_* auth — none of which a coding subprocess has any use for. Route through the
# centralized helper so Tier-1 + dynamic-internal secrets are always stripped while provider creds
- # still flow, matching copilot_acp_client (#29157 sibling spawn-site gap).
+ # still flow, matching the ACP client (#29157 sibling spawn-site gap).
spawn_env = hermes_subprocess_env(inherit_credentials=True)
if env:
spawn_env.update(env)
diff --git a/agent/turn_api_call.py b/agent/turn_api_call.py
index 196e9dbf724..c2f5c802b0c 100644
--- a/agent/turn_api_call.py
+++ b/agent/turn_api_call.py
@@ -92,8 +92,10 @@ def perform_api_call(
def _perform_api_call(next_api_kwargs):
if agent.api_mode == "codex_responses":
+ from agent.codex_responses_adapter import drops_replay_item_ids
+
next_api_kwargs = agent._get_transport().preflight_kwargs(
- next_api_kwargs, allow_stream=False, is_github_responses=agent._is_copilot_url(),
+ next_api_kwargs, allow_stream=False, drop_replay_item_ids=drops_replay_item_ids(agent.base_url),
sanitize_harmony_tokens=agent._is_codex_backend(),
)
if _use_streaming:
diff --git a/agent/turn_api_request.py b/agent/turn_api_request.py
index e4468c52756..b436fd3b6d6 100644
--- a/agent/turn_api_request.py
+++ b/agent/turn_api_request.py
@@ -124,8 +124,10 @@ def build_request_payload(
# extra_body, kwargs strings) — see sanitize_outbound_kwargs for the #50959 rationale.
sanitize_outbound_kwargs(agent, api_kwargs)
if agent.api_mode == "codex_responses":
+ from agent.codex_responses_adapter import drops_replay_item_ids
+
api_kwargs = agent._get_transport().preflight_kwargs(
- api_kwargs, allow_stream=False, is_github_responses=agent._is_copilot_url(),
+ api_kwargs, allow_stream=False, drop_replay_item_ids=drops_replay_item_ids(agent.base_url),
sanitize_harmony_tokens=agent._is_codex_backend(),
)
# OpenRouter caching replays identical responses, even empty ones; an empty-response
diff --git a/agent/turn_context.py b/agent/turn_context.py
index 2732c34d082..dee7b26f11e 100644
--- a/agent/turn_context.py
+++ b/agent/turn_context.py
@@ -1123,8 +1123,8 @@ def build_turn_context(
agent._persist_user_message_idx = current_turn_user_idx
agent._user_turn_count += 1
- # Copilot x-initiator: the first API call of this user turn is user-initiated;
- # tool-loop follow-ups revert to "agent".
+ # Turn-initiator state for per-request provider headers: the first API call of this
+ # user turn is user-initiated; tool-loop follow-ups are agent-initiated.
agent._is_user_initiated_turn = True
# Preserve the original user message (no nudge injection).
diff --git a/agent/turn_final_response.py b/agent/turn_final_response.py
index a75d4d1f9d3..7ff2863fc63 100644
--- a/agent/turn_final_response.py
+++ b/agent/turn_final_response.py
@@ -294,7 +294,7 @@ def finish_text_response(
# real reply; ``build_api_messages`` substitutes ``api_content`` on the wire.
final_msg["api_content"] = final_response
- # Dropped tool-call recovery (copilot/Claude): finish_reason="tool_calls" with empty
+ # Dropped tool-call recovery (seen with Claude via gateways): finish_reason="tool_calls" with empty
# tool_calls would end the turn unstarted; re-prompt (max 3 CONSECUTIVE stalls).
if (
finish_reason == "tool_calls"
diff --git a/plugins/model-providers/copilot/__init__.py b/plugins/model-providers/copilot/__init__.py
index 745ee4a2814..96e9ee9dfa9 100644
--- a/plugins/model-providers/copilot/__init__.py
+++ b/plugins/model-providers/copilot/__init__.py
@@ -10,8 +10,10 @@ from typing import Any
from providers import register_provider
from providers.base import ProviderProfile
+from .responses import RESPONSES_PROFILE_FIELDS, CopilotResponsesMixin
-class CopilotProfile(ProviderProfile):
+
+class CopilotProfile(CopilotResponsesMixin, ProviderProfile):
"""GitHub Copilot / GitHub Models — editor headers + reasoning."""
def build_api_kwargs_extras(
@@ -38,7 +40,7 @@ class CopilotProfile(ProviderProfile):
copilot = CopilotProfile(
name="copilot", aliases=("github-copilot", "github-models", "github-model", "github"),
env_vars=("COPILOT_GITHUB_TOKEN", "GH_TOKEN", "GITHUB_TOKEN"), base_url="https://api.githubcopilot.com",
- auth_type="copilot",
+ auth_type="copilot", **RESPONSES_PROFILE_FIELDS,
)
register_provider(copilot)
diff --git a/plugins/model-providers/copilot/responses.py b/plugins/model-providers/copilot/responses.py
new file mode 100644
index 00000000000..d817d630572
--- /dev/null
+++ b/plugins/model-providers/copilot/responses.py
@@ -0,0 +1,66 @@
+"""Copilot / GitHub Models wire quirks on the Responses route, reasoning payloads and reasoning carriers.
+
+Fills the generic ``ProviderProfile`` endpoint seams (providers/base.py, lane L3 block). Everything here
+is called per request or per replayed message, so it is pure and answers from static data / caches.
+"""
+
+from __future__ import annotations
+
+from typing import Any
+
+from utils import base_url_host_matches
+
+_COPILOT_HOST = "githubcopilot.com" # api.githubcopilot.com plus the api.<plan>.githubcopilot.com variants
+_GITHUB_MODELS_HOST = "models.github.ai"
+
+# Constructor kwargs for the profile's L3 fields. ``github_responses`` is persisted on encrypted reasoning
+# items in session history: renaming it orphans every stored blob (one cold cache + dropped reasoning on resume).
+RESPONSES_PROFILE_FIELDS: dict[str, Any] = {
+ # The backend binds replayed item ids to a connection; a stale id 401s even when short (#32716).
+ "responses_replay_item_ids": False,
+ "responses_prompt_cache_key": False,
+ "responses_issuer_kind": "github_responses",
+ "responses_trusts_completed_status": False,
+ "responses_native_compaction": False,
+ # Reasoning text only comes back when ``summary: auto`` is sent (#46527); ``include`` is never sent.
+ "responses_profile_reasoning": True,
+ "message_carrier_opaque": "reasoning_opaque",
+ "message_carrier_text": "reasoning_text",
+ # Copilot's Gemini models take tool-call ``extra_content`` signatures back like the native Gemini API.
+ "replays_tool_call_signatures": True,
+}
+
+
+def _is_copilot_host(base_url: str) -> bool:
+ return base_url_host_matches(str(base_url or ""), _COPILOT_HOST)
+
+
+class CopilotResponsesMixin:
+ """Endpoint ownership, catalog-clamped reasoning payloads and the ``/chat/completions`` carriers."""
+
+ def serves_endpoint(self, base_url: str) -> bool:
+ return _is_copilot_host(base_url) or base_url_host_matches(str(base_url or ""), _GITHUB_MODELS_HOST)
+
+ def reasoning_payload(self, model: str | None, reasoning_config: dict | None, *, base_url: str) -> dict | None:
+ from hermes_cli.models import clamp_github_reasoning_effort, github_model_reasoning_efforts
+
+ supported = github_model_reasoning_efforts(model)
+ if not supported:
+ return None
+ cfg = reasoning_config if isinstance(reasoning_config, dict) else {}
+ if cfg.get("enabled") is False:
+ return None
+ return {"effort": clamp_github_reasoning_effort(cfg.get("effort"), supported)}
+
+ def replay_message_carriers(self, values: dict[str, Any], *, model: str | None, base_url: str) -> dict[str, Any]:
+ # The editor clients replay reasoning_text only next to the opaque blob it belongs to.
+ if not _is_copilot_host(base_url) or not values.get("reasoning_opaque"):
+ return {}
+ out = {"reasoning_opaque": values["reasoning_opaque"]}
+ if values.get("reasoning_text"):
+ out["reasoning_text"] = values["reasoning_text"]
+ return out
+
+ def replays_function_thought_signature(self, *, model: str | None, base_url: str) -> bool:
+ # Copilot's Gemini 3 variant signs tool calls inside ``function`` and expects them back.
+ return _is_copilot_host(base_url)
diff --git a/providers/base.py b/providers/base.py
index 90f9f8e15a9..dda1c619491 100644
--- a/providers/base.py
+++ b/providers/base.py
@@ -536,3 +536,32 @@ class ProviderProfile:
except Exception as exc:
logger.debug("fetch_models(%s): %s", self.name, exc)
return None
+
+ # ── Lane L3: Responses-route quirks and message-level reasoning carriers ───
+ # Every field and hook below applies only on endpoints the profile claims via ``serves_endpoint``;
+ # the defaults are the generic wire. Hot path: answers must be pure and cheap (no I/O).
+ responses_replay_item_ids: bool = True # replayed Responses ``message`` items keep their ``id``
+ responses_prompt_cache_key: bool = True # the Responses body carries ``prompt_cache_key``
+ responses_issuer_kind: str = "" # persisted stamp for encrypted reasoning minted here ("" = URL-derived)
+ responses_trusts_completed_status: bool = True # False: a reasoning-only ``completed`` response continues
+ responses_native_compaction: bool = True # False: never send ``context_management``
+ responses_profile_reasoning: bool = False # True: ``reasoning`` = ``reasoning_payload`` + summary, no ``include``
+ message_carrier_opaque: str = "" # top-level assistant key of an opaque reasoning blob (latest streamed wins)
+ message_carrier_text: str = "" # top-level assistant key of readable reasoning text (streamed parts concatenate)
+ replays_tool_call_signatures: bool = False # tool calls keep Gemini ``extra_content`` signatures (by provider name)
+
+ def serves_endpoint(self, base_url: str) -> bool:
+ """True when *base_url* is this provider's own backend, so the L3 fields and hooks apply to it."""
+ return False
+
+ def reasoning_payload(self, model: str | None, reasoning_config: dict | None, *, base_url: str) -> dict | None:
+ """Verbatim ``reasoning`` object the endpoint takes for *model* (catalog-clamped), or None for none."""
+ return None
+
+ def replay_message_carriers(self, values: dict[str, Any], *, model: str | None, base_url: str) -> dict[str, Any]:
+ """Captured message carriers (``message_carrier_*`` keys) to put back on a replayed assistant message."""
+ return {}
+
+ def replays_function_thought_signature(self, *, model: str | None, base_url: str) -> bool:
+ """True when replayed tool calls keep ``function.thought_signature`` (stripped everywhere else)."""
+ return False
diff --git a/tests/agent/test_codex_responses_adapter.py b/tests/agent/test_codex_responses_adapter.py
index 9febf15acba..72b58832258 100644
--- a/tests/agent/test_codex_responses_adapter.py
+++ b/tests/agent/test_codex_responses_adapter.py
@@ -683,7 +683,7 @@ def test_preflight_codex_input_items_drops_short_id_for_github_responses():
"phase": "final_answer",
}
],
- is_github_responses=True,
+ drop_replay_item_ids=True,
)
assert "id" not in items[0]
diff --git a/tests/agent/test_codex_xai_oauth_recovery.py b/tests/agent/test_codex_xai_oauth_recovery.py
index 34f14627e8a..8ade8ec5d7b 100644
--- a/tests/agent/test_codex_xai_oauth_recovery.py
+++ b/tests/agent/test_codex_xai_oauth_recovery.py
@@ -619,7 +619,6 @@ def test_transport_round_trip_drops_foreign_reasoning():
tools=None,
is_codex_backend=True,
is_xai_responses=False,
- is_github_responses=False,
base_url="https://chatgpt.com/backend-api/codex",
instructions="you are hermes",
)
diff --git a/tests/agent/test_endpoint_profile_seams.py b/tests/agent/test_endpoint_profile_seams.py
new file mode 100644
index 00000000000..16fd183dc9a
--- /dev/null
+++ b/tests/agent/test_endpoint_profile_seams.py
@@ -0,0 +1,114 @@
+"""Generic endpoint seams (``ProviderProfile.serves_endpoint`` + the L3 fields/hooks) through a fake relay profile.
+
+The relay is not any shipped provider: the contract is that a profile claiming an endpoint controls its
+Responses item-id replay, cache-key routing, issuer stamp, reasoning shape and message-level reasoning
+carriers, and that nothing leaks onto endpoints it does not claim.
+"""
+
+from types import SimpleNamespace
+
+import pytest
+
+from providers.base import ProviderProfile
+from utils import base_url_host_matches
+
+RELAY = "https://relay.example/v1"
+OTHER = "https://other.example/v1"
+
+
+class _RelayProfile(ProviderProfile):
+ def serves_endpoint(self, base_url: str) -> bool:
+ return base_url_host_matches(base_url, "relay.example")
+
+ def reasoning_payload(self, model, reasoning_config, *, base_url):
+ return {"effort": "low"}
+
+ def replay_message_carriers(self, values, *, model, base_url):
+ return {"blob": values["blob"]} if values.get("blob") else {}
+
+
+def relay(monkeypatch):
+ import providers
+
+ profile = _RelayProfile(
+ name="relay-fake", responses_replay_item_ids=False, responses_prompt_cache_key=False,
+ responses_issuer_kind="relay_kind", responses_trusts_completed_status=False,
+ responses_profile_reasoning=True, message_carrier_opaque="blob", message_carrier_text="blob_text",
+ )
+ real = providers.list_providers
+ monkeypatch.setattr(providers, "list_providers", lambda: [profile, *real()])
+ return profile
+
+
+_HISTORY = [
+ {"role": "user", "content": "hi"},
+ {"role": "assistant", "content": "pong", "codex_message_items": [{
+ "type": "message", "role": "assistant", "status": "completed", "id": "msg_short",
+ "content": [{"type": "output_text", "text": "pong"}],
+ }]},
+ {"role": "user", "content": "again"},
+]
+
+
+def _build(base_url):
+ from agent.transports.codex import ResponsesApiTransport
+
+ transport = ResponsesApiTransport()
+ kwargs = transport.build_kwargs(
+ "gpt-5.4", _HISTORY, None, base_url=base_url, session_id="s1",
+ reasoning_config={"enabled": True, "effort": "high"}, profile_reasoning={"effort": "low"},
+ )
+ return transport, kwargs
+
+
+def test_claimed_endpoint_controls_responses_wire(relay):
+ transport, kw = _build(RELAY)
+ message = next(i for i in kw["input"] if i.get("role") == "assistant")
+ assert "id" not in message
+ assert "prompt_cache_key" not in kw
+ assert kw["reasoning"] == {"effort": "low", "summary": "auto"}
+ assert "include" not in kw
+ assert transport._last_issuer_kind == "relay_kind"
+
+
+def test_unclaimed_endpoint_keeps_generic_wire(relay):
+ transport, kw = _build(OTHER)
+ message = next(i for i in kw["input"] if i.get("role") == "assistant")
+ assert message["id"] == "msg_short"
+ assert kw["prompt_cache_key"]
+ assert kw["include"] == ["reasoning.encrypted_content"]
+ assert str(transport._last_issuer_kind).startswith("other:")
+
+
+def test_declared_issuer_untrusted_completed_status_continues(relay):
+ from agent.codex_responses_adapter import _normalize_codex_response
+
+ response = SimpleNamespace(status="completed", incomplete_details=None, output=[SimpleNamespace(
+ type="reasoning", id="rs_1", encrypted_content="enc", summary=[SimpleNamespace(type="summary_text", text="t")],
+ )])
+ assert _normalize_codex_response(response, issuer_kind="relay_kind")[1] == "incomplete"
+ assert _normalize_codex_response(response, issuer_kind="other:https://x")[1] == "stop"
+
+
+def test_declared_carriers_are_captured_and_replayed_only_on_the_claimed_endpoint(relay):
+ from agent.reasoning_carriers import CARRIER_TYPE, carrier_record, shape_wire_carriers
+
+ record = carrier_record(SimpleNamespace(blob="B", blob_text="T"))
+ assert record == {"type": CARRIER_TYPE, "blob": "B", "blob_text": "T"}
+ assistant = {"role": "assistant", "content": "x", "blob": "B", "reasoning_details": [record]}
+ on_relay = shape_wire_carriers([assistant], model="m", base_url=RELAY)[0]
+ elsewhere = shape_wire_carriers([assistant], model="m", base_url=OTHER)[0]
+ assert on_relay["blob"] == "B" and "blob_text" not in on_relay and "reasoning_details" not in on_relay
+ assert "blob" not in elsewhere and "reasoning_details" not in elsewhere
+
+
+def test_persisted_carrier_keys_of_an_uninstalled_plugin_never_reach_the_wire():
+ """No registered profile declares ``blob`` (its plugin is gone): the record's own keys are still stripped."""
+ from agent.reasoning_carriers import CARRIER_TYPE, shape_wire_carriers
+
+ record = {"type": CARRIER_TYPE, "blob": "B"}
+ assistant = {"role": "assistant", "content": "x", "blob": "B", "reasoning_details": [record]}
+ wire = shape_wire_carriers([assistant], model="m", base_url=RELAY)[0]
+ assert wire == {"role": "assistant", "content": "x"}
+ assert assistant["reasoning_details"] == [record] # history is never mutated
diff --git a/tests/agent/test_native_compaction.py b/tests/agent/test_native_compaction.py
index d7a9b2c5ffe..476d729da07 100644
--- a/tests/agent/test_native_compaction.py
+++ b/tests/agent/test_native_compaction.py
@@ -10,6 +10,7 @@ from types import SimpleNamespace
import pytest
+from agent.codex_responses_adapter import ResponsesEndpointQuirks
from agent.native_compaction import (
DEFAULT_COMPACT_THRESHOLD,
is_direct_openai_route,
@@ -136,7 +137,7 @@ class TestRequestGate:
)
assert (
native_compaction_context_management(
- agent, is_codex_backend=False, is_github_responses=True
+ agent, is_codex_backend=False, endpoint=ResponsesEndpointQuirks(native_compaction=False)
)
is None
)
diff --git a/tests/agent/test_run_agent.py b/tests/agent/test_run_agent.py
index 131befb7080..6017e70def0 100644
--- a/tests/agent/test_run_agent.py
+++ b/tests/agent/test_run_agent.py
@@ -1354,10 +1354,10 @@ class TestBuildApiKwargs:
"hermes_cli.models.github_model_reasoning_efforts",
lambda _model: ["none", "low", "medium", "high", "xhigh"],
)
- agent.model = "gpt-5.5"
+ agent.model, agent.base_url = "gpt-5.5", "https://api.githubcopilot.com"
agent.reasoning_config = {"enabled": True, "effort": "xhigh"}
- assert agent._github_models_reasoning_extra_body() == {"effort": "xhigh"}
+ assert agent._endpoint_reasoning_payload() == {"effort": "xhigh"}
def test_qwen_portal_formats_messages_and_metadata(self, agent):
diff --git a/tests/agent/transports/test_codex_transport.py b/tests/agent/transports/test_codex_transport.py
index 95fc50046db..5fde92f155f 100644
--- a/tests/agent/transports/test_codex_transport.py
+++ b/tests/agent/transports/test_codex_transport.py
@@ -46,12 +46,12 @@ class TestCodexBuildKwargs:
from hermes_constants import resolve_reasoning_config
reasoning = resolve_reasoning_config({"agent": {"reasoning_effort": effort}}, model)
- agent = SimpleNamespace(model=model, reasoning_config=reasoning)
+ agent = SimpleNamespace(model=model, reasoning_config=reasoning, base_url="https://api.githubcopilot.com")
kw = transport.build_kwargs(
model=model, messages=[{"role": "user", "content": "Hi"}],
- provider="github-copilot", is_github_responses=True,
+ provider="github-copilot", base_url="https://api.githubcopilot.com",
reasoning_config=reasoning,
- github_reasoning_extra=ReasoningParamsMixin._github_models_reasoning_extra_body(agent),
+ profile_reasoning=ReasoningParamsMixin._endpoint_reasoning_payload(agent),
)
assert kw.get("reasoning") == ({"effort": expected, "summary": "auto"} if expected else None)
@@ -229,8 +229,8 @@ class TestCodexBuildKwargs:
# restart, or load-balancer churn — replaying a stale id gets HTTP
# 401 "input item ID does not belong to this connection", even for
# ids well under the #27038 64-char length cap. build_kwargs must
- # thread is_github_responses through to the input converter so the
- # id never reaches the request.
+ # resolve the endpoint's replay_item_ids quirk from base_url and thread
+ # it to the input converter so the id never reaches the request.
messages = [
{"role": "system", "content": "You are Hermes."},
{
@@ -250,7 +250,7 @@ class TestCodexBuildKwargs:
]
kw = transport.build_kwargs(
model="gpt-5.5", messages=messages, tools=[],
- is_github_responses=True,
+ base_url="https://api.githubcopilot.com",
)
message_item = next(item for item in kw["input"] if item.get("type") == "message")
assert "id" not in message_item
@@ -1869,7 +1869,7 @@ class TestCodexTransportXaiServiceTierStrip:
model="gpt-5.5",
messages=[{"role": "user", "content": "hi"}],
tools=[],
- is_github_responses=True,
+ base_url="https://api.githubcopilot.com",
request_overrides={"service_tier": "priority"},
)
assert kw.get("service_tier") == "priority"
diff --git a/tests/agent/transports/test_codex_transport_github_reasoning.py b/tests/agent/transports/test_codex_transport_github_reasoning.py
index d5fd24140a9..de319e2031f 100644
--- a/tests/agent/transports/test_codex_transport_github_reasoning.py
+++ b/tests/agent/transports/test_codex_transport_github_reasoning.py
@@ -19,7 +19,7 @@ def transport():
def test_github_responses_requests_reasoning_summary(transport):
kw = transport.build_kwargs(
model="gpt-5.4", messages=[{"role": "user", "content": "Hi"}], tools=[],
- is_github_responses=True,
- github_reasoning_extra={"effort": "medium"},
+ base_url="https://api.githubcopilot.com",
+ profile_reasoning={"effort": "medium"},
)
assert kw.get("reasoning") == {"effort": "medium", "summary": "auto"}
diff --git a/tests/plugins/model_providers/test_copilot_profile.py b/tests/plugins/model_providers/test_copilot_profile.py
index 5e48c87335d..24e987dce6f 100644
--- a/tests/plugins/model_providers/test_copilot_profile.py
+++ b/tests/plugins/model_providers/test_copilot_profile.py
@@ -136,5 +136,6 @@ def test_main_agent_github_clamp_never_escalates(monkeypatch, effort, expected):
from agent.reasoning_params import ReasoningParamsMixin
_patch_efforts(monkeypatch, ["minimal", "low", "medium", "high"])
- agent = SimpleNamespace(model="gpt-5.4", reasoning_config={"enabled": True, "effort": effort})
- assert ReasoningParamsMixin._github_models_reasoning_extra_body(agent) == {"effort": expected}
+ agent = SimpleNamespace(model="gpt-5.4", reasoning_config={"enabled": True, "effort": effort},
+ base_url="https://api.githubcopilot.com")
+ assert ReasoningParamsMixin._endpoint_reasoning_payload(agent) == {"effort": expected}