From ed0a4782a21d8e564f8956c87e022e8caef851ac Mon Sep 17 00:00:00 2001 From: Claude Code Date: Fri, 27 Nov 2026 20:03:34 +0530 Subject: Commit tracked-file changes required for a working Agentux install 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 --- src/agentux/providers/base.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'src/agentux/providers/base.py') 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"] -- cgit v1.2.3