Skip to content

th-9a5794: stream_preamble — fast-model preamble to cover reasoning TTFT#234

Merged
brentrager merged 1 commit into
mainfrom
th-9a5794-preamble
Jul 15, 2026
Merged

th-9a5794: stream_preamble — fast-model preamble to cover reasoning TTFT#234
brentrager merged 1 commit into
mainfrom
th-9a5794-preamble

Conversation

@brentrager

Copy link
Copy Markdown
Contributor

What

Adds an optional fast-model preamble to streaming turns. When the server is configured with SMOOTH_AGENT_PREAMBLE_MODEL (e.g. groq-gpt-oss-20b), a small fast model runs in parallel with each turn and streams ONE short present-tense "what I'm about to do" sentence over a new stream_preamble wire event — an ephemeral status line the real answer replaces. It covers the reasoning model's (gpt-oss-120b) time-to-first-token dead air.

Why

Perceived operator slowness is latency-to-first-token, not throughput — a reasoning model behind the gateway sits on dead air while it reasons + resolves its first tool call. The gateway exposes no clean harmony preamble channel, so we translate intent via a fast model.

Validated live against llm.smoo.ai: the 20b returns a clean sentence ("Let me retrieve your recent conversation statistics.") in ~466 ms — ahead of the 120b's first answer token, and on tool-using turns (2–4 s) it fills the whole gap.

Changes

  • runner.rs: parallel preamble task, best-effort/fail-silent, guarded by an answer-started flag so a slow preamble never pops in after the reply began.
  • protocol.rs: stream_preamble builder (mirrors stream_reasoning).
  • config.rs: documents SMOOTH_AGENT_PREAMBLE_MODEL (unset = off).
  • spec/events/stream-preamble.schema.json; TS SDK StreamPreamble in the union + validate map (regenerated).

Safety

Off unless configured — every existing consumer is byte-for-byte unchanged. 101 server tests + a new protocol test pass; SDK typechecks. Uses the same gateway/key as the main model. Skipped when a test LLM provider is injected.

Rollout

Merge → the 🦋 version PR publishes server crate + SDK at 1.22.15 → chat-ws bumps the pin + sets SMOOTH_AGENT_PREAMBLE_MODEL=groq-gpt-oss-20b@smooai/chat-widget renders the stream_preamble frame (separate PR).

🤖 Generated with Claude Code

https://claude.ai/code/session_01WEUZgsyfGVab8uqSFPbr23

When SMOOTH_AGENT_PREAMBLE_MODEL is set (e.g. groq-gpt-oss-20b), the streaming
runner fires a small fast model IN PARALLEL with each turn and streams ONE short
present-tense "what I'm about to do" sentence over a new stream_preamble wire
event — an ephemeral status line the real answer replaces. Covers the reasoning
model's (gpt-oss-120b) time-to-first-token dead air. Validated live against the
llm.smoo.ai gateway: 20b returns a clean sentence in ~466ms, ahead of the 120b's
first answer token; on tool-using turns (2-4s) it fills the whole gap.

- runner.rs: parallel preamble task, best-effort/fail-silent, guarded by an
  answer-started flag so a slow preamble never pops in after the reply.
- protocol.rs: stream_preamble builder (mirrors stream_reasoning shape).
- config.rs: document SMOOTH_AGENT_PREAMBLE_MODEL (unset = off).
- spec: stream-preamble.schema.json; TS SDK: StreamPreamble in the union + validate map.
- Off unless configured — every existing consumer unchanged. 101 server tests + protocol test pass; SDK typechecks.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WEUZgsyfGVab8uqSFPbr23
@changeset-bot

changeset-bot Bot commented Jul 15, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b4af670

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@smooai/smooth-operator Patch
@smooai/smooth-operator-web-chat-example Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@brentrager brentrager merged commit 57c7a02 into main Jul 15, 2026
7 checks passed
@brentrager brentrager deleted the th-9a5794-preamble branch July 15, 2026 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant