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(capability): write_reasoning_level for int_budget/effort/enum
xf gong6a6925a058f5
diff --git a/cubepi/providers/capability.py b/cubepi/providers/capability.pyindex 6f9b629..b8c8918 100644--- a/cubepi/providers/capability.py+++ b/cubepi/providers/capability.py@@ -113,3 +113,58 @@ def apply_temperature(kwargs: dict[str, Any], spec: TemperatureSpec) -> None:if "temperature" in kwargs:value = kwargs["temperature"]kwargs["temperature"] = max(spec.min, min(spec.max, value))+++from cubepi.providers.base import ThinkingLevel+++def _resolve_level_value(spec: ReasoningLevelSpec, level: ThinkingLevel) -> Any | None:+ """Return the wire value for ``level`` per ``spec``, or None to skip writing."""+ if spec.kind == "int_budget":+ if spec.level_budgets is None:+ raise RuntimeError(+ "ReasoningLevelSpec(kind='int_budget') reached _resolve_level_value "+ "with no level_budgets — validator was bypassed"+ )+ return spec.level_budgets.get(level)+ if spec.kind == "effort":+ if spec.level_to_effort is None:+ raise RuntimeError(+ "ReasoningLevelSpec(kind='effort') reached _resolve_level_value "+ "with no level_to_effort — validator was bypassed"+ )+ return spec.level_to_effort.get(level)+ if spec.kind == "enum":+ if spec.level_to_enum is None:+ raise RuntimeError(+ "ReasoningLevelSpec(kind='enum') reached _resolve_level_value "+ "with no level_to_enum — validator was bypassed"+ )+ return spec.level_to_enum.get(level)+ return None+++def _write_dotted_path(target: dict[str, Any], path: str, value: Any) -> None:+ """Walk a dotted path into ``target``, creating dicts as needed; set the leaf."""+ parts = path.split(".")+ cursor: Any = target+ for part in parts[:-1]:+ if part not in cursor or not isinstance(cursor[part], dict):+ cursor[part] = {}+ cursor = cursor[part]+ cursor[parts[-1]] = value+++def write_reasoning_level(+ kwargs: dict[str, Any],+ spec: ReasoningLevelSpec,+ level: ThinkingLevel,+) -> None:+ """Write the resolved wire value for ``level`` at ``spec.path`` inside ``kwargs``.++ If the level is not in the spec's level map (i.e. unsupported), no write happens.+ """+ value = _resolve_level_value(spec, level)+ if value is None:+ return+ _write_dotted_path(kwargs, spec.path, value)diff --git a/tests/test_capability.py b/tests/test_capability.pyindex af4ba69..725a80d 100644--- a/tests/test_capability.py+++ b/tests/test_capability.py@@ -4,6 +4,7 @@ from cubepi.providers.capability import (TemperatureSpec,apply_temperature,merge_capability_payload,+ write_reasoning_level,)@@ -174,3 +175,58 @@ def test_apply_temperature_free_clamp_inclusive_at_max():kwargs = {"temperature": 2.0}apply_temperature(kwargs, TemperatureSpec(mode="free", min=0.0, max=2.0))assert kwargs == {"temperature": 2.0}+++def test_int_budget_writes_top_level_path():+ kwargs: dict = {}+ spec = ReasoningLevelSpec(+ path="thinking.budget_tokens",+ kind="int_budget",+ level_budgets={"off": 0, "low": 4000, "medium": 10000, "high": 32000},+ )+ write_reasoning_level(kwargs, spec, "medium")+ assert kwargs == {"thinking": {"budget_tokens": 10000}}+++def test_int_budget_skips_when_level_absent_in_map():+ kwargs: dict = {}+ spec = ReasoningLevelSpec(+ path="thinking.budget_tokens",+ kind="int_budget",+ level_budgets={"low": 4000},+ )+ write_reasoning_level(kwargs, spec, "xhigh")+ assert kwargs == {}+++def test_effort_writes_string():+ kwargs: dict = {}+ spec = ReasoningLevelSpec(+ path="reasoning_effort",+ kind="effort",+ level_to_effort={"low": "low", "medium": "medium", "high": "high"},+ )+ write_reasoning_level(kwargs, spec, "high")+ assert kwargs == {"reasoning_effort": "high"}+++def test_enum_writes_nested_extra_body():+ kwargs: dict = {}+ spec = ReasoningLevelSpec(+ path="extra_body.thinking.type",+ kind="enum",+ level_to_enum={"off": "disabled", "low": "enabled", "medium": "enabled", "high": "enabled"},+ )+ write_reasoning_level(kwargs, spec, "medium")+ assert kwargs == {"extra_body": {"thinking": {"type": "enabled"}}}+++def test_writes_into_existing_nested_dict():+ kwargs: dict = {"extra_body": {"other": True}}+ spec = ReasoningLevelSpec(+ path="extra_body.thinking.type",+ kind="enum",+ level_to_enum={"off": "disabled", "medium": "enabled"},+ )+ write_reasoning_level(kwargs, spec, "off")+ assert kwargs == {"extra_body": {"other": True, "thinking": {"type": "disabled"}}}