penguiflow-streaming
БесплатноБез исполняемых скриптовНе проверенStream partial output (LLM tokens, progressive synthesis, status updates) from a PenguiFlow flow — emit `StreamChunk` messages via `ctx.emit_chunk(parent=msg…
от hurtener★ 27 звёзд на GitHubОб этом скилле
PenguiFlow Streaming (Protocol-Agnostic)
When to use
- Streaming raw tokens or progressive synthesis from a flow.
- Building an SSE or WebSocket bridge from a flow's stream sink to a client.
- Needing chunk ordering and
done-flag semantics without committing to the AG-UI protocol. - Streaming status updates ("downloading…", "synthesizing…") alongside content.
When NOT to use
- AG-UI protocol events (TEXT_MESSAGE_START/CONTENT/END, tool-call lifecycle) → use penguiflow-agui-events.
- ReactPlanner final-response streaming knob (
stream_final_response) andJSONLLMClient.stream/on_stream_chunkLLM-protocol callbacks → see penguiflow-reactplanner-config step 7a. - Persisting chunks for replay → use penguiflow-statestore event persistence.
Hard boundaries
This skill is the runtime chunk layer: StreamChunk, emit_chunk, sink nodes, and the protocol-agnostic SSE/WebSocket helpers PenguiFlow ships. AG-UI events (a higher-level UI event contract) and planner-internal streaming knobs are sibling skills.
Workflow
1) Switch the flow to envelope style
Streaming requires Message envelopes — payload-only flows have no trace_id to anchor stream_id. See penguiflow-core-flows (references/messages-and-envelopes.md).
msg = Message(payload={"request": ...}, headers=Headers(tenant="acme"))
await flow.emit(msg, trace_id=msg.trace_id)
2) Design the topology: compose node + chunk sink + final node
compose_node --(StreamChunk)--> chunk_sink_node
\--(FinalAnswer)--> final_node
Both successors live in adjacency:
flow = create(
compose.to(chunk_sink, final),
chunk_sink.to(),
final.to(),
)
Why a dedicated sink: chunks need their own queue and consumer. Don't rely on side effects in the compose node.
3) Emit chunks with ctx.emit_chunk
async def compose(msg: Message, ctx) -> None:
await ctx.emit_chunk(parent=msg, text="hello ", to=chunk_sink_node)
await ctx.emit_chunk(parent=msg, text="world", done=True, to=chunk_sink_node)
final = msg.model_copy(update={"payload": FinalAnswer(text="hello world")})
await ctx.emit(final, to=final_node)
Rules:
parentis required — chunks inherittrace_id, headers, deadline, and meta.- Default
stream_idis the parent'strace_id. Override only when you have multiple concurrent streams in the same trace (rare). seqis auto-assigned and monotonically increasing perstream_id. Don't supply it manually unless you really need to.done=Truemarks the end of the stream and resets internal sequence tracking. Emit it exactly once per stream.
4) Sink shape
async def chunk_sink(msg: Message, _ctx) -> None:
chunk: StreamChunk = msg.payload
# forward to client (SSE, WebSocket, queue, etc.)
await client.send(chunk.text)
if chunk.done:
await client.send_done()
The sink usually returns None (no further routing). It's the bridge between the flow and your transport.
5) Ship chunks to a client
Three first-class helpers in penguiflow.streaming:
| Helper | Use for |
|---|---|
format_sse_event(chunk) |
Format a StreamChunk as an SSE data: ... frame. |
chunk_to_ws_json(chunk) |
Serialize a StreamChunk to a JSON dict for WebSocket send_json. |
stream_flow(flow, trace_id, ...) |
Async iterator yielding chunks for a trace — useful for tests and HTTP handlers that want to consume programmatically. |
emit_stream_events(...) |
Lower-level helper to bridge sink output to async generators. |
Full SSE / WebSocket recipes in references/sse-and-websocket.md.
6) Emit a FinalAnswer to terminate the trace
Streaming chunks are progressive. Callers still need a final, canonical result. Emit FinalAnswer(text=..., citations=...) (or another typed payload) to a separate egress node so fetch(trace_id=...) returns the canonical answer.
Don't conflate the chunk sink with the final result. Two egress paths is the safe pattern.
Troubleshooting (fast checks)
- No chunks appear — the compose node received a payload-only message; switch to
Messageenvelopes. Or the sink isn't connected increate(...). - Chunks come out of order — multiple producers emit to the same
stream_idconcurrently; one producer per stream, or use distinctstream_ids per producer. - Duplicate
seq— you're supplyingseqmanually and re-emitting; letemit_chunkassign it. - Stream never ends — no chunk emitted with
done=True; emit one terminator per stream. - Streaming stalls — chunk queue is full (backpressure working); make the sink faster, or raise
queue_maxsizefor the chunk edge. - Chunks leak across tenants — same
trace_idreused for different tenants; always generate freshtrace_idper request and setHeaders.tenant. fetch(trace_id=...)hangs — chunks reach the sink but noFinalAnswerreaches Rookery; ensure the compose node emits a final to t
Установить penguiflow-streaming в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл penguiflow-streaming?
Stream partial output (LLM tokens, progressive synthesis, status updates) from a PenguiFlow flow — emit `StreamChunk` messages via `ctx.emit_chunk(parent=msg, text=..., done=..., to=sink)` from a "compose" node, route them to a dedicated sink node, and ship them to clients via SSE (`format_sse_event`), WebSocket (`chunk_to_ws_json`), or programmatic iteration (`stream_flow`/`emit_stream_events`). Use when a user says "stream tokens", "SSE streaming", "WebSocket streaming", "progressive output", "StreamChunk", or asks how to stream partials without the higher-level AG-UI protocol.
Как установить скилл penguiflow-streaming?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл penguiflow-streaming запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
frontend-design
Guidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making…
от Anthropicwebapp-testing
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing…
от Anthropicbrand-guidelines
Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand…
от Anthropicweb-artifacts-builder
Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn/ui). Use…
от Anthropic