Skip to content

CubeLoop — a Pythonic, async-native agent harness core designed for high performance, readability, and production-grade persistence.

feat(capability): apply_temperature with free/fixed/ignored modes

xf gonga367f14a7552
diff --git a/cubepi/providers/capability.py b/cubepi/providers/capability.py
index bc3f5be..6b2fb16 100644
--- a/cubepi/providers/capability.py
+++ b/cubepi/providers/capability.py
@@ -87,3 +87,25 @@ def merge_capability_payload(kwargs: dict[str, Any], patch: dict[str, Any]) -> N
merge_capability_payload(kwargs[key], patch_value)
else:
kwargs[key] = patch_value
+
+
+def apply_temperature(kwargs: dict[str, Any], spec: TemperatureSpec) -> None:
+ """Mutate ``kwargs['temperature']`` in place per ``spec``.
+
+ - mode="ignored": strip the key entirely.
+ - mode="fixed": overwrite with ``fixed_value`` (set the key if absent).
+ - mode="free": clamp caller's value to ``[min, max]``; no-op if absent.
+ """
+
+ if spec.mode == "ignored":
+ kwargs.pop("temperature", None)
+ return
+
+ if spec.mode == "fixed":
+ assert spec.fixed_value is not None # enforced by validator
+ kwargs["temperature"] = spec.fixed_value
+ return
+
+ if "temperature" in kwargs:
+ value = kwargs["temperature"]
+ kwargs["temperature"] = max(spec.min, min(spec.max, value))
diff --git a/tests/test_capability.py b/tests/test_capability.py
index 8bac2f5..25b6bf6 100644
--- a/tests/test_capability.py
+++ b/tests/test_capability.py
@@ -2,6 +2,7 @@ from cubepi.providers.capability import (
CapabilityDescriptor,
ReasoningLevelSpec,
TemperatureSpec,
+ apply_temperature,
merge_capability_payload,
)
@@ -117,3 +118,45 @@ def test_merge_none_patch_value_overwrites():
kwargs: dict = {"x": {"nested": True}}
merge_capability_payload(kwargs, {"x": None})
assert kwargs["x"] is None
+
+
+def test_apply_temperature_free_passes_through():
+ kwargs = {"temperature": 0.7}
+ apply_temperature(kwargs, TemperatureSpec(mode="free"))
+ assert kwargs == {"temperature": 0.7}
+
+
+def test_apply_temperature_free_clamps_above_max():
+ kwargs = {"temperature": 5.0}
+ apply_temperature(kwargs, TemperatureSpec(mode="free", min=0, max=2))
+ assert kwargs == {"temperature": 2.0}
+
+
+def test_apply_temperature_free_clamps_below_min():
+ kwargs = {"temperature": -1.0}
+ apply_temperature(kwargs, TemperatureSpec(mode="free", min=0, max=2))
+ assert kwargs == {"temperature": 0.0}
+
+
+def test_apply_temperature_ignored_strips():
+ kwargs = {"temperature": 0.7}
+ apply_temperature(kwargs, TemperatureSpec(mode="ignored"))
+ assert "temperature" not in kwargs
+
+
+def test_apply_temperature_fixed_overwrites():
+ kwargs = {"temperature": 0.7}
+ apply_temperature(kwargs, TemperatureSpec(mode="fixed", fixed_value=0.0))
+ assert kwargs == {"temperature": 0.0}
+
+
+def test_apply_temperature_fixed_sets_when_absent():
+ kwargs: dict = {}
+ apply_temperature(kwargs, TemperatureSpec(mode="fixed", fixed_value=0.0))
+ assert kwargs == {"temperature": 0.0}
+
+
+def test_apply_temperature_free_no_op_when_absent():
+ kwargs: dict = {}
+ apply_temperature(kwargs, TemperatureSpec(mode="free"))
+ assert kwargs == {}