Skip to content

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

fix: reconcile compaction tracing additions with 0.7 BoundModel API

xf gong3a1490e89bda
diff --git a/cubepi/middleware/compaction/__init__.py b/cubepi/middleware/compaction/__init__.py
index ac9bdb4..1c09ddf 100644
--- a/cubepi/middleware/compaction/__init__.py
+++ b/cubepi/middleware/compaction/__init__.py
@@ -12,7 +12,14 @@ from cubepi.middleware.compaction.boundary import safe_boundary
from cubepi.middleware.compaction.state import CompactionState, message_refs
from cubepi.middleware.compaction.summarizer import summarize
from cubepi.middleware.compaction.tokens import approx_tokens
-from cubepi.providers.base import BoundModel, Message, TextContent, UserMessage
+from cubepi.providers.base import (
+ BoundModel,
+ Message,
+ Model,
+ Provider,
+ TextContent,
+ UserMessage,
+)
SUMMARY_PREFIX = "[Conversation summary so far]\n"
logger = logging.getLogger(__name__)
diff --git a/cubepi/tracing/recorder.py b/cubepi/tracing/recorder.py
index 938fd99..7a1cf0b 100644
--- a/cubepi/tracing/recorder.py
+++ b/cubepi/tracing/recorder.py
@@ -218,7 +218,7 @@ class Recorder:
# ``_close_open_spans`` (the latter covers cancelled runs that
# never emit AgentEndEvent).
self._active_run_token: Any | None = None
- # ``(model.provider, model.id)`` tuples for LLM calls a middleware
+ # ``(model.provider_id, model.id)`` tuples for LLM calls a middleware
# owns (e.g. ``CompactionMiddleware``'s summarizer). When the
# provider listener fires with one of these models we keep the
# chat span but skip the root ``invoke_agent`` attribution writes
@@ -279,7 +279,7 @@ class Recorder:
agent_state = getattr(agent, "_state", None)
agent_model = getattr(agent_state, "model", None) if agent_state else None
agent_key: tuple[str, str] | None = (
- (agent_model.provider, agent_model.id)
+ (agent_model.provider_id, agent_model.id)
if agent_model is not None
else None
)
@@ -290,7 +290,7 @@ class Recorder:
except Exception:
extra = []
for p, m in extra:
- key = (m.provider, m.id)
+ key = (m.provider_id, m.id)
if key != agent_key:
self._extra_call_models.add(key)
if id(p) in seen:
@@ -978,7 +978,7 @@ class Recorder:
# if the incoming model matches, skip the root writes. Gating by
# model rather than listener identity is what handles the
# shared-provider case ("reuse the client, swap the model").
- attribute_root = (model.provider, model.id) not in self._extra_call_models
+ attribute_root = (model.provider_id, model.id) not in self._extra_call_models
if attribute_root:
# System prompt sha256 on root agent span (once per run).
self._maybe_record_system_prompt_hash(payload, run)
diff --git a/tests/tracing/test_recorder.py b/tests/tracing/test_recorder.py
index c96befc..8eeeb56 100644
--- a/tests/tracing/test_recorder.py
+++ b/tests/tracing/test_recorder.py
@@ -19,7 +19,7 @@ from cubepi.agent.types import (
AgentToolResult,
BeforeToolCallResult,
)
-from cubepi.providers.base import Model, TextContent, ToolCall
+from cubepi.providers.base import BoundModel, Model, TextContent, ToolCall
from cubepi.providers.faux import FauxProvider, faux_assistant_message
from cubepi.tracing import Tracer
@@ -510,10 +510,9 @@ class TestMiddlewareProviders:
# Distinct ``provider`` labels on the two Models so the test can also
# verify the root ``invoke_agent`` span stays attributed to the agent's
# own provider, not the summarizer that fires first.
- summary_model = Model(id="summary-1", provider="faux-summary")
+ summary_model = Model(id="summary-1", provider_id="faux-summary")
mw = CompactionMiddleware(
- summary_provider=summarizer,
- summary_model=summary_model,
+ summary_model=BoundModel(provider=summarizer, spec=summary_model),
max_tokens_before_compact=1,
keep_recent_messages=1,
max_summary_tokens=128,
@@ -534,8 +533,7 @@ class TestMiddlewareProviders:
)
agent = Agent(
- provider=main,
- model=MODEL,
+ model=BoundModel(provider=main, spec=MODEL),
system_prompt="agent system prompt — kept on root",
middleware=[mw],
checkpointer=cp,
@@ -587,11 +585,10 @@ class TestMiddlewareProviders:
from cubepi.providers.base import UserMessage
shared = FauxProvider()
- agent_model = Model(id="agent-1", provider="faux-main")
- summary_model = Model(id="summary-1", provider="faux-summary")
+ agent_model = Model(id="agent-1", provider_id="faux-main")
+ summary_model = Model(id="summary-1", provider_id="faux-summary")
mw = CompactionMiddleware(
- summary_provider=shared,
- summary_model=summary_model,
+ summary_model=BoundModel(provider=shared, spec=summary_model),
max_tokens_before_compact=1,
keep_recent_messages=1,
max_summary_tokens=128,
@@ -610,8 +607,7 @@ class TestMiddlewareProviders:
)
agent = Agent(
- provider=shared,
- model=agent_model,
+ model=BoundModel(provider=shared, spec=agent_model),
system_prompt="agent system prompt — kept on root",
middleware=[mw],
checkpointer=cp,
@@ -672,8 +668,7 @@ class TestMiddlewareProviders:
provider = FauxProvider()
agent = Agent(
- provider=provider,
- model=MODEL,
+ model=BoundModel(provider=provider, spec=MODEL),
system_prompt="test",
middleware=[_SameModelMiddleware(provider, MODEL)],
)
@@ -713,10 +708,9 @@ class TestMiddlewareProviders:
provider = FauxProvider()
agent = Agent(
- provider=provider,
- model=MODEL,
+ model=BoundModel(provider=provider, spec=MODEL),
system_prompt="test",
- middleware=[_DuckMiddleware(Model(id="dm-1", provider="duck"))],
+ middleware=[_DuckMiddleware(Model(id="dm-1", provider_id="duck"))],
)
exporter = InMemoryExporter()
tracer = Tracer(
@@ -743,8 +737,7 @@ class TestMiddlewareProviders:
provider = FauxProvider()
agent = Agent(
- provider=provider,
- model=MODEL,
+ model=BoundModel(provider=provider, spec=MODEL),
system_prompt="test",
middleware=[_BoomMiddleware()],
)