featherweight.streaming¶
streaming ¶
Streaming agents: an agent that talks to a person while it works.
A StreamingAgent is run with runner.stream(), which returns a StreamingRun: an async iterable of AG-UI events
(the events of the ag-ui-protocol package, which featherweight does not redefine). There is no output model, no output
check and no retry. See docs/streaming.md.
ChatInput ¶
Bases: AgentInput
The conversation so far, sent by the client. featherweight keeps no conversation: this is all the agent sees.
The last message is from the user. system and developer messages are refused, so that a client cannot replace
the agent's prompt. thread_id names the conversation in the run log; it does not load anything.
StreamingAgent ¶
Bases: AgentBase
An agent for chat and other user-facing work. It has no output_model and no check_output, and is not retried.
Declare it as any agent (name, description, version, prompt, model, tools, skills, MCP servers, sub-agents). Its
input is a ChatInput. A sub-agent it launches is a tool call that returns when the sub-agent is done; its own text
is not streamed. allow_user_questions and raise_conflicts do nothing here: a person is already in the chat.
StreamingRun ¶
StreamingRun(
run_id: str,
start: Callable[
[StreamingRun, Callable[[BaseEvent], None]],
Awaitable[None],
],
)
One streamed turn. Loop over it to get the events; it can be looped over once.
The run starts when the loop starts, and ends when the loop ends. Leaving the loop early stops the run.
status is INIT until the loop starts, then RUNNING, then SUCCESS, FAILED or CANCELLED; error says why it failed.
usage is the tokens of the turn, known when the run ends. new_messages is what the turn produced.
new_messages
property
¶
new_messages: list[BaseMessage]
The LangChain messages this turn produced: the assistant messages (with their tool calls and thoughts) and the
tool results, in order. They fill up as the turn goes and are complete when the loop ends. Store them next to the
history you sent: history.add_messages(run.new_messages).
cancel ¶
cancel() -> None
Stop the run, from anywhere in the same process. The model call is cancelled, the stream ends cleanly (the open
things are closed and RUN_FINISHED has the cancelled outcome), the row is CANCELLED, and new_messages has what
the turn had said and done. A tool that was running is cancelled where it can be (an async tool); a synchronous tool
or an MCP call may finish anyway. Safe to call before the loop starts, after the run ended, or twice.