Skip to content

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

feat(agent): widen model type to accept FallbackBoundModel

xf gongba4ee8711d91
diff --git a/cubepi/agent/agent.py b/cubepi/agent/agent.py
index 21918e9..68d3547 100644
--- a/cubepi/agent/agent.py
+++ b/cubepi/agent/agent.py
@@ -5,7 +5,7 @@ import time
import uuid
from collections.abc import Sequence
from dataclasses import dataclass, field
-from typing import Callable, Generic, TypeVar
+from typing import TYPE_CHECKING, Callable, Generic, TypeVar
from cubepi.agent._outcome import RunOutcome
from cubepi.agent._tool_cycle import ToolCycleViolation, check_tool_cycle
@@ -49,6 +49,9 @@ from cubepi.types import JsonObject, StructuredValue
TMessage = TypeVar("TMessage")
+if TYPE_CHECKING:
+ from cubepi.providers.fallback import FallbackBoundModel
+
def _default_convert_to_llm(
messages: list[Message], *, ctx: AgentContext
@@ -138,7 +141,7 @@ class Agent(Generic[TMessage]):
def __init__(
self,
*,
- model: BoundModel,
+ model: BoundModel | FallbackBoundModel,
system_prompt: str = "",
tools: list[AgentTool] | None = None,
thinking: ThinkingLevel = "off",
diff --git a/cubepi/agent/loop.py b/cubepi/agent/loop.py
index 22f4ad8..56f4942 100644
--- a/cubepi/agent/loop.py
+++ b/cubepi/agent/loop.py
@@ -1,7 +1,7 @@
from __future__ import annotations
import asyncio
-from typing import Callable
+from typing import TYPE_CHECKING, Callable
from cubepi.agent.tools import execute_tool_calls
from cubepi.agent.types import (
@@ -27,12 +27,15 @@ from cubepi.providers.base import (
ToolResultMessage,
)
+if TYPE_CHECKING:
+ from cubepi.providers.fallback import FallbackBoundModel
+
async def run_agent_loop(
*,
prompts: list[Message],
context: AgentContext,
- model: BoundModel,
+ model: BoundModel | FallbackBoundModel,
convert_to_llm: Callable,
emit: Callable,
transform_context: Callable | None = None,
@@ -90,7 +93,7 @@ async def run_agent_loop(
async def run_agent_loop_continue(
*,
context: AgentContext,
- model: BoundModel,
+ model: BoundModel | FallbackBoundModel,
convert_to_llm: Callable,
emit: Callable,
transform_context: Callable | None = None,
@@ -148,7 +151,7 @@ async def run_agent_loop_continue(
async def run_agent_loop_resume(
*,
context: AgentContext,
- model: BoundModel,
+ model: BoundModel | FallbackBoundModel,
convert_to_llm: Callable,
emit: Callable,
transform_context: Callable | None = None,
@@ -387,7 +390,7 @@ async def _run_loop(
*,
current_context: AgentContext,
new_messages: list[Message],
- model: BoundModel,
+ model: BoundModel | FallbackBoundModel,
convert_to_llm: Callable,
transform_context: Callable | None,
transform_system_prompt: Callable | None,
@@ -443,7 +446,7 @@ async def _run_loop_inner(
*,
current_context: AgentContext,
new_messages: list[Message],
- model: BoundModel,
+ model: BoundModel | FallbackBoundModel,
convert_to_llm: Callable,
transform_context: Callable | None,
transform_system_prompt: Callable | None,
@@ -683,7 +686,7 @@ async def _run_loop_inner(
async def _stream_assistant_response(
context: AgentContext,
- model: BoundModel,
+ model: BoundModel | FallbackBoundModel,
convert_to_llm: Callable,
transform_context: Callable | None,
transform_system_prompt: Callable | None,