summaryrefslogtreecommitdiff
path: root/src/agentux/providers/base.py
diff options
context:
space:
mode:
authorClaude Code <noreply@anthropic.com>2026-11-27 20:03:34 +0530
committerClaude Code <noreply@anthropic.com>2026-11-27 20:03:34 +0530
commited0a4782a21d8e564f8956c87e022e8caef851ac (patch)
treee65d6e0d0ddc23a1b1b9948a47a53245f0716e90 /src/agentux/providers/base.py
parent95ea8c8b72d2dbb20ab860ab1505b46add280773 (diff)
Commit tracked-file changes required for a working Agentux installHEADmain
The committed provider/base.py, config.py, models.py, errors.py and tools were missing symbols (e.g. TextCallback) that agent.py imports, so a clean clone produced a broken install. Commit these so the remote's committed state is complete and cloneable. Co-Authored-By: Claude Code <noreply@anthropic.com>
Diffstat (limited to 'src/agentux/providers/base.py')
-rw-r--r--src/agentux/providers/base.py29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/agentux/providers/base.py b/src/agentux/providers/base.py
index f20980b..671a79c 100644
--- a/src/agentux/providers/base.py
+++ b/src/agentux/providers/base.py
@@ -8,17 +8,24 @@ matter of implementing this interface -- the agent loop does not change.
from __future__ import annotations
from abc import ABC, abstractmethod
-from typing import AsyncIterator, List, Optional
+from typing import AsyncIterator, Awaitable, Callable, List, Optional
from ..config import Config
from ..models import Message, ToolDefinition
+#: Receives text deltas as they arrive. Async so providers can await the
+#: consumer (a terminal write) without blocking the read loop.
+TextCallback = Callable[[str], Awaitable[None]]
+
class BaseProvider(ABC):
"""A model backend Agentux can drive."""
def __init__(self, config: Config) -> None:
self.config = config
+ #: Token usage reported by the most recent response, or ``None``.
+ #: Agents read this to show real numbers instead of estimates.
+ self.last_usage: Optional[Dict[str, int]] = None
@abstractmethod
async def chat(
@@ -67,5 +74,23 @@ class BaseProvider(ABC):
if message.content:
yield message.content
+ async def chat_streaming(
+ self,
+ messages: List[Message],
+ tools: Optional[List[ToolDefinition]] = None,
+ on_text: Optional[TextCallback] = None,
+ ) -> Message:
+ """Chat, streaming text deltas to ``on_text`` as they arrive.
+
+ Returns a complete :class:`Message`, so a step that turns out to be a
+ tool call costs the same single request as a step that is not. That is
+ the whole point: streaming a step and *then* discovering it was a tool
+ call means paying for the request twice.
+ """
+ message = await self.chat(messages, tools)
+ if on_text and message.content:
+ await on_text(message.content)
+ return message
+
-__all__ = ["BaseProvider"]
+__all__ = ["BaseProvider", "TextCallback"]