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
fix(capability): document clobber semantics; reject empty reasoning path
xf gong03d7f0e902eb
diff --git a/cubepi/providers/capability.py b/cubepi/providers/capability.pyindex b5e0d0d..2b1e50c 100644--- a/cubepi/providers/capability.py+++ b/cubepi/providers/capability.py@@ -33,7 +33,7 @@ class TemperatureSpec(BaseModel):class ReasoningLevelSpec(BaseModel):"""How to express a fine-grain reasoning level on this endpoint."""- path: str+ path: str = Field(..., min_length=1)kind: Literal["int_budget", "effort", "enum"]level_budgets: dict[str, int] | None = Nonelevel_to_effort: dict[str, str] | None = None@@ -144,7 +144,13 @@ def _resolve_level_value(spec: ReasoningLevelSpec, level: ThinkingLevel) -> Anydef _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."""+ """Walk a dotted path into ``target``, creating dicts as needed; set the leaf.++ When an intermediate segment holds a non-dict scalar in ``target``, the+ scalar is replaced with a fresh dict before recursion continues. The+ capability layer is the authority on what lives at a provider-controlled+ path, so this "capability wins" rule mirrors :func:`merge_capability_payload`.+ """parts = path.split(".")cursor: Any = targetfor part in parts[:-1]:diff --git a/tests/test_capability.py b/tests/test_capability.pyindex 725a80d..2fd226e 100644--- a/tests/test_capability.py+++ b/tests/test_capability.py@@ -230,3 +230,39 @@ def test_writes_into_existing_nested_dict():)write_reasoning_level(kwargs, spec, "off")assert kwargs == {"extra_body": {"other": True, "thinking": {"type": "disabled"}}}+++def test_write_reasoning_level_overwrites_existing_leaf():+ """Pre-existing leaf value at the spec's path is replaced (last writer wins)."""+ kwargs: dict = {"reasoning_effort": "low"}+ spec = ReasoningLevelSpec(+ path="reasoning_effort",+ kind="effort",+ level_to_effort={"high": "high"},+ )+ write_reasoning_level(kwargs, spec, "high")+ assert kwargs == {"reasoning_effort": "high"}+++def test_write_reasoning_level_replaces_non_dict_intermediate():+ """A non-dict scalar at an intermediate segment is clobbered with a dict."""+ kwargs: dict = {"thinking": "stale-string"}+ spec = ReasoningLevelSpec(+ path="thinking.budget_tokens",+ kind="int_budget",+ level_budgets={"medium": 8192},+ )+ write_reasoning_level(kwargs, spec, "medium")+ assert kwargs == {"thinking": {"budget_tokens": 8192}}+++def test_reasoning_level_path_must_be_non_empty():+ import pytest+ from pydantic import ValidationError++ with pytest.raises(ValidationError):+ ReasoningLevelSpec(+ path="",+ kind="int_budget",+ level_budgets={"low": 4000},+ )