Skip to content

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

feat(capability): introduce CapabilityDescriptor with validated defaults

xf gongbf2a3d3bc958
diff --git a/cubepi/providers/capability.py b/cubepi/providers/capability.py
new file mode 100644
index 0000000..737aaa9
--- /dev/null
+++ b/cubepi/providers/capability.py
@@ -0,0 +1,60 @@
+"""Capability descriptor — vendor quirks expressed as data, bound to a Provider.
+
+See docs/dev/specs/2026-05-19-llm-provider-platform-design.md §3.1.
+"""
+
+from __future__ import annotations
+
+from typing import Any, Literal
+
+from pydantic import BaseModel, Field, model_validator
+
+
+class TemperatureSpec(BaseModel):
+ mode: Literal["free", "fixed", "ignored"] = "free"
+ min: float = 0.0
+ max: float = 2.0
+ default: float = 1.0
+ fixed_value: float | None = None
+
+ @model_validator(mode="after")
+ def _validate_fixed(self) -> "TemperatureSpec":
+ if self.mode == "fixed" and self.fixed_value is None:
+ raise ValueError("TemperatureSpec(mode='fixed') requires fixed_value")
+ return self
+
+
+class ReasoningLevelSpec(BaseModel):
+ """How to express a fine-grain reasoning level on this endpoint."""
+
+ path: str
+ kind: Literal["int_budget", "effort", "enum"]
+ level_budgets: dict[str, int] | None = None
+ level_to_effort: dict[str, str] | None = None
+ level_to_enum: dict[str, str] | None = None
+
+ @model_validator(mode="after")
+ def _validate_kind_map(self) -> "ReasoningLevelSpec":
+ if self.kind == "int_budget" and not self.level_budgets:
+ raise ValueError("kind='int_budget' requires level_budgets")
+ if self.kind == "effort" and not self.level_to_effort:
+ raise ValueError("kind='effort' requires level_to_effort")
+ if self.kind == "enum" and not self.level_to_enum:
+ raise ValueError("kind='enum' requires level_to_enum")
+ return self
+
+
+class CapabilityDescriptor(BaseModel):
+ """Vendor quirks for one endpoint. Empty default = legacy no-op."""
+
+ reasoning_off_payload: dict[str, Any] = Field(default_factory=dict)
+ reasoning_on_payload: dict[str, Any] = Field(default_factory=dict)
+ reasoning_level: ReasoningLevelSpec | None = None
+
+ temperature: TemperatureSpec = Field(default_factory=TemperatureSpec)
+
+ max_tokens_field: Literal["max_tokens", "max_completion_tokens"] = "max_tokens"
+
+ supports_tools: bool = True
+ supports_images: bool = False
+ supports_streaming: bool = True
diff --git a/tests/test_capability.py b/tests/test_capability.py
new file mode 100644
index 0000000..9020533
--- /dev/null
+++ b/tests/test_capability.py
@@ -0,0 +1,54 @@
+from cubepi.providers.capability import (
+ CapabilityDescriptor,
+ ReasoningLevelSpec,
+ TemperatureSpec,
+)
+
+
+def test_descriptor_defaults_are_legacy_safe():
+ """Empty descriptor must encode 'no-op' so existing callers behave the same."""
+ cap = CapabilityDescriptor()
+ assert cap.reasoning_off_payload == {}
+ assert cap.reasoning_on_payload == {}
+ assert cap.reasoning_level is None
+ assert cap.temperature.mode == "free"
+ assert cap.temperature.min == 0.0
+ assert cap.temperature.max == 2.0
+ assert cap.max_tokens_field == "max_tokens"
+ assert cap.supports_tools is True
+ assert cap.supports_images is False
+ assert cap.supports_streaming is True
+
+
+def test_temperature_fixed_requires_value():
+ """mode=fixed without fixed_value must fail validation."""
+ import pytest
+ from pydantic import ValidationError
+
+ with pytest.raises(ValidationError):
+ TemperatureSpec(mode="fixed")
+
+
+def test_reasoning_level_int_budget_requires_map():
+ """kind=int_budget without level_budgets must fail."""
+ import pytest
+ from pydantic import ValidationError
+
+ with pytest.raises(ValidationError):
+ ReasoningLevelSpec(path="thinking.budget_tokens", kind="int_budget")
+
+
+def test_reasoning_level_effort_requires_map():
+ import pytest
+ from pydantic import ValidationError
+
+ with pytest.raises(ValidationError):
+ ReasoningLevelSpec(path="reasoning_effort", kind="effort")
+
+
+def test_reasoning_level_enum_requires_map():
+ import pytest
+ from pydantic import ValidationError
+
+ with pytest.raises(ValidationError):
+ ReasoningLevelSpec(path="extra_body.thinking.type", kind="enum")