heartbeat_seconds (utils/sse.py)

mirobody · mirobody/utils/sse.py · python · Apache-2.0
ai

Server-Sent Events keepalive: the interval, the response headers and the relay every streaming endpoint shares. An agent turn goes quiet in three places: before the first token (auth, session, agent construction, tool loading, model queueing), inside a tool call, and between recu

# Source: https://github.com/thetahealth/mirobody | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
# Provided via justclaw.it.com; keep this notice with the code.
"""Server-Sent Events keepalive: the interval, the response headers and the
relay every streaming endpoint shares.

An agent turn goes quiet in three places: before the first token (auth,
session, agent construction, tool loading, model queueing), inside a tool
call, and between recursion hops. Every middlebox on the path (a mobile
client, an API gateway, a reverse proxy) reads "no bytes for a while" as
"connection dead" and cuts it. The fix is to make liveness *observable
bytes*: write one small frame, and only while the source is silent (the chat
stream writes a `heartbeat` block, `a

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key