feat: carry the per-call tier down to the transport that must send it

The Transport port took the request apart into five arguments, so a tier
placed on ChatRequest could never reach _build_payload: the field was set,
read by nobody, and silently ignored - the exact shape of failure that sent
downstream to extra_body in the first place.

complete() now takes reasoning_effort with no default, matching the
TelemetryRecorder convention: a default would turn a missing hand-off into
a silent 'no opinion'. All four fakes move with it, since @runtime_checkable
checks method names and not signatures.

EmbeddingTransport and OcrTransport are deliberately left alone - they have
no reasoning semantics - and a test now holds that line.

_build_payload drops its inline sugar conversion for effective_effort(), so
the guard and the hot path share one judgement, and passes the source's
effort_fallback for the same reason.
This commit is contained in:
2026-09-05 02:28:24 -04:00
parent 1f13eb18ab
commit 80a8013642
11 changed files with 142 additions and 15 deletions
+22 -8
View File
@@ -28,6 +28,7 @@ from polygateway.streaming import StreamLivenessTimeout, stream_with_liveness_ti
from polygateway.thinking import (
ThinkingCapability,
ThinkingUnsupportedError,
effective_effort,
get_capability,
observe_thinking,
reconcile_thinking,
@@ -351,6 +352,7 @@ class OpenAICompatTransport:
profile: ProviderProfile,
stream: bool,
overlay: dict[str, Any],
reasoning_effort: Effort | None,
) -> dict[str, Any]:
payload: dict[str, Any] = {"model": source.model, "messages": messages, "stream": stream}
if stream:
@@ -360,17 +362,19 @@ class OpenAICompatTransport:
capability = get_capability(source.model, table=self._capabilities)
first_time = source.model not in self._warned_models
self._warned_models.add(source.model)
# `enable_thinking` 的档位语法糖(True → auto,False → none,None 不表态);
# 就地转换是过渡形态,T5 起由 thinking.effective_effort() 统一收口并接上
# 源级/请求级档位(设计 §4.2)
enabled = source.enable_thinking
effort = None if enabled is None else (Effort.AUTO if enabled else Effort.NONE)
# 三层优先级在此汇合: 请求级 > 源级 > enable_thinking 语法糖(设计 §4.2)。
# 判定与装配守卫共用同一个纯函数,两处分叉就会变成"装配期放行、运行期报错"
payload.update(
resolve_thinking(
profile,
capability,
effort,
effective_effort(
request_effort=reasoning_effort,
source_effort=source.reasoning_effort,
enable_thinking=source.enable_thinking,
),
model=source.model,
fallback=source.effort_fallback,
warn_unregistered=first_time,
).payload
)
@@ -388,12 +392,22 @@ class OpenAICompatTransport:
stream: bool,
overlay: dict[str, Any],
call_id: str,
reasoning_effort: Effort | None,
) -> TransportResult:
"""一次原始调用;HTTP/线路/流式异常按 ARCH §6.2 翻译为领域错误。"""
"""一次原始调用;HTTP/线路/流式异常按 ARCH §6.2 翻译为领域错误。
`reasoning_effort` 是**请求级**档位(`None` = 不表态);它与源级配置的优先级
在 `_build_payload` 里由 `effective_effort` 裁定,本层只负责把它送到。
"""
profile = get_provider(source.provider, registry=self._registry)
try:
payload = self._build_payload(
messages=messages, source=source, profile=profile, stream=stream, overlay=overlay
messages=messages,
source=source,
profile=profile,
stream=stream,
overlay=overlay,
reasoning_effort=reasoning_effort,
)
except ThinkingUnsupportedError as exc:
# 推理开关不可满足是**请求本身**的问题: 换源重试都救不了它。只捕这个