CubeLoop — a Pythonic, async-native agent harness core designed for high performance, readability, and production-grade persistence.
Python agent-frameworkagent-harnessagent-runtimeagentic-aiai-agentsai-frameworkanthropicharnessharness-engineeringharness-frameworklanggraphlanggraph-alternativellmmcpopenaipi-agentpi-agent-corepythonpython-agent
feat(openai): apply capability temperature + max_tokens_field rename
xf gong362cef30b887
diff --git a/cubepi/providers/openai.py b/cubepi/providers/openai.pyindex 707268e..27601e6 100644--- a/cubepi/providers/openai.py+++ b/cubepi/providers/openai.py@@ -7,7 +7,10 @@ from typing import Any, Literalfrom cubepi.utils.json_parse import parse_streaming_json-from cubepi.providers.capability import CapabilityDescriptor+from cubepi.providers.capability import (+ CapabilityDescriptor,+ apply_temperature,+)from cubepi.providers.base import (AssistantMessage,BaseProvider,@@ -131,6 +134,18 @@ class OpenAIProvider(BaseProvider):if "include_usage" not in so:so["include_usage"] = True+ # Capability-driven payload mutations. Gated on _cap_active so+ # legacy callers (no capability kwarg) keep today's wire bytes+ # exactly — the OpenAI path historically does not inject+ # temperature or max_tokens. Spec §3.5.+ cap = self._resolve_capability(model.id)+ if self._cap_active:+ kwargs.setdefault("temperature", model.temperature)+ kwargs.setdefault("max_tokens", model.max_tokens)+ apply_temperature(kwargs, cap.temperature)+ if cap.max_tokens_field != "max_tokens" and "max_tokens" in kwargs:+ kwargs[cap.max_tokens_field] = kwargs.pop("max_tokens")+# Fire request listeners AFTER all kwargs mutations so observers# see the final wire payload (including extra_body merges,# max_completion_tokens_alias rewrite, and stream_optionsdiff --git a/tests/providers/test_openai_capability.py b/tests/providers/test_openai_capability.pyindex 4b88e94..572d9b9 100644--- a/tests/providers/test_openai_capability.py+++ b/tests/providers/test_openai_capability.py@@ -6,6 +6,12 @@ the provider's internal state. Stream-time assertions come in Task 6.import pytest+from cubepi.providers.base import (+ Model,+ StreamOptions,+ TextContent,+ UserMessage,+)from cubepi.providers.capability import CapabilityDescriptor, TemperatureSpecfrom cubepi.providers.openai import OpenAIProvider@@ -70,3 +76,80 @@ def test_resolve_capability_returns_default_when_inactive():result = p._resolve_capability("any-model")assert isinstance(result, CapabilityDescriptor)assert result.reasoning_off_payload == {}+++async def _capture_payload_openai(provider: OpenAIProvider, model: Model) -> dict:+ """Run a stream with a fake openai client and return the kwargs sent."""+ captured: dict = {}++ async def listener(kwargs: dict, m: Model) -> None:+ captured.update(kwargs)++ provider._request_listeners.append(listener)++ # Stub the openai client so it doesn't try to actually call the network.+ class _FakeResponse:+ response = None++ def __aiter__(self):+ async def gen():+ return+ yield # never+ return gen()++ async def fake_create(**kw):+ return _FakeResponse()++ provider._client.chat.completions.create = fake_create # type: ignore[assignment]+ stream = await provider.stream(+ model=model,+ messages=[UserMessage(content=[TextContent(text="hi")])],+ options=StreamOptions(thinking="off"),+ )+ async for _ in stream:+ pass+ return captured+++def _model(id: str = "test-model", **kw) -> Model:+ return Model(+ id=id,+ provider="test",+ context_window=kw.get("context_window", 32000),+ max_tokens=kw.get("max_tokens", 4096),+ temperature=kw.get("temperature", 0.7),+ )+++async def test_temperature_ignored_strips_field():+ cap = CapabilityDescriptor(temperature=TemperatureSpec(mode="ignored"))+ p = OpenAIProvider(api_key="x", base_url="http://e", capability=cap)+ payload = await _capture_payload_openai(p, _model())+ assert "temperature" not in payload+++async def test_temperature_fixed_overwrites():+ cap = CapabilityDescriptor(temperature=TemperatureSpec(mode="fixed", fixed_value=0.0))+ p = OpenAIProvider(api_key="x", base_url="http://e", capability=cap)+ payload = await _capture_payload_openai(p, _model(temperature=0.7))+ assert payload["temperature"] == 0.0+++async def test_max_tokens_field_renamed():+ cap = CapabilityDescriptor(max_tokens_field="max_completion_tokens")+ p = OpenAIProvider(api_key="x", base_url="http://e", capability=cap)+ payload = await _capture_payload_openai(p, _model())+ assert "max_completion_tokens" in payload+ assert "max_tokens" not in payload+++async def test_legacy_no_capability_does_not_inject_temperature_or_max_tokens():+ """Regression guard: no capability passed -> wire bytes identical to today."""+ p = OpenAIProvider(api_key="x", base_url="http://e") # no capability+ payload = await _capture_payload_openai(p, _model())+ assert "temperature" not in payload+ assert "max_tokens" not in payload