Part 2 of 12 · 1 min read
Why a progress bar beats a spinner
Live commentary instead of a post-match report, and why it changes how slow an agent feels.
Think of watching a football match live versus reading a one-line final score an hour later. The outcome can be identical, but the live version feels completely different because you see things happen as they happen.
In plain words: showing a user what an agent is doing while it works makes a slow run feel fast, even when the total time does not change.
A worked example. An agent run takes 60 seconds end to end. If the client waits silently for one response, the user sees nothing for the full 60 seconds. If the server streams progress events as they happen, the user sees the first signal in about 0.4 seconds — roughly 150 times sooner — even though the run still finishes at 60 seconds.
The key lines. Server-Sent Events (SSE) format each update as plain text, from code/mini-stream/sse.py:
# from code/mini-stream/sse.py
def format_event(data, event=None, id=None, retry=None):
...
for line in re.split(r"\r\n|\r|\n", data if isinstance(data, str) else json.dumps(data)):
out.append(f"data: {line}")
return "\n".join(out) + "\n\n"
Read it as: build one small text block per update, with an id and a type, ending in a blank line so the client knows where it ends. The browser's built-in EventSource reads this format directly. It reconnects automatically if the connection drops.
SSE, EventSource
Server-Sent Events (SSE) is a one-way stream of text events from server to client over plain HTTP; EventSource is the browser API that reads an SSE stream and reconnects on its own.
Example: format_event({"text": "..."}, event="delta", id=21) produces one such text block.