Skip to content

API Reference parrot.integrations.matrix.streaming

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.integrations.matrix.streaming

View source

Matrix streaming handler — edit-based token streaming.

Uses Matrix's m.replace (message edit) relation to simulate streaming output by progressively updating a single message as the LLM generates tokens. The result is visible in any Matrix client (Element, etc.) and persists in room history.

Alias MatrixClientWrapper

Re-exported from parrot.integrations.matrix.client.MatrixClientWrapper.

Class MatrixStreamHandler

Handles streaming LLM output to a Matrix room via message edits.

Usage::

handler = MatrixStreamHandler(wrapper, room_id)
event_id = await handler.begin_stream("Thinking...")

async for token in llm_stream:
    await handler.send_token(event_id, token)

await handler.end_stream(event_id, final_text)
Parameter Type Default Description
wrapper MatrixClientWrapper Connected MatrixClientWrapper.
room_id str Target room for streaming.
min_edit_interval_ms int 500 Minimum milliseconds between edits.
min_chars_delta int 50 Minimum character change before sending edit.

Method MatrixStreamHandler.begin_stream

Send the initial message and return its event_id.

begin_stream(initial_text: str = '▌') -> str

Parameter Type Default Description
initial_text str '▌' Initial placeholder text (e.g., cursor).

Returns: str — The event_id to use for subsequent edits.

Method MatrixStreamHandler.send_token

Accumulate a token and edit the message if thresholds are met.

send_token(event_id: str, token: str) -> None

Parameter Type Default Description
event_id str The original message event_id.
token str New token to append.

Method MatrixStreamHandler.end_stream

Finalize the stream with the complete response.

end_stream(event_id: str, final_text: Optional[str] = None) -> None

Parameter Type Default Description
event_id str The original message event_id.
final_text Optional[str] None Final complete text (uses accumulated if None).

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally