effect-ai-streaming

Implement Effect AI streaming responses with start/delta/end protocols and resource-safe history management.

3|Updated Apr 1, 2026
One-click install
npx skills add https://github.com/mpsuesser/opencode-effect-enforcer --skill effect-ai-streaming-mpsuesser
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: effect-ai-streaming
Source: https://github.com/mpsuesser/opencode-effect-enforcer/tree/main/skills/effect-ai-streaming
Command: npx skills add https://github.com/mpsuesser/opencode-effect-enforcer --skill effect-ai-streaming-mpsuesser

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires effect.

What problem does it solve? Building real-time chat interfaces with language models requires correctly handling incremental stream parts, accumulating partial responses, and keeping conversation history consistent without race conditions or resource leaks. ## Core Features & Use Cases - StreamPart Protocol Handling: Process text, reasoning, and tool-parameter parts using the start/delta/end lifecycle with Match.when type checks. - Accumulation & History Management: Fold streamed parts into conversation history with Prompt.fromResponseParts and SubscriptionRef for atomic updates. - Resource-Safe Consumption: Protect concurrent streams with Semaphore and Channel.acquireUseRelease so permits are always released. - Use Case: Build a chat endpoint where each user message streams model output token-by-token to the UI while conversation history updates incrementally and concurrent requests are serialized safely. ## Quick Start Ask the agent to implement a streaming chat handler using Effect's LanguageModel.streamText with semaphore-protected history accumulation via SubscriptionRef.

Frequently Asked Questions about effect-ai-streaming

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I stream language model responses in Effect?▼

Use LanguageModel.streamText from effect/unstable/ai/LanguageModel to get a Stream of response parts. Consume it with Stream.runForEach to process each part, matching on part.type values like text-delta and finish.

How to accumulate streaming AI responses into conversation history?▼

Accumulate parts in a mutable array inside Stream.suspend, then fold them with Prompt.fromResponseParts and merge into history via SubscriptionRef.set with Prompt.concat. Use Stream.mapArrayEffect so side effects run per batch.

Why does Match.tag fail on Effect AI stream parts?▼

Stream parts use a type field, not the _tag field that Match.tag expects. Use Match.when({ type: "text-delta" }, handler) or direct part.type checks instead.

How do I prevent concurrent streaming requests from corrupting chat history?▼

Wrap the stream in Channel.acquireUseRelease with a Semaphore permit. Take the permit first, checkpoint history, stream with accumulation, and release the permit in the finalizer so it is always freed.

What stream part types does the Effect AI response protocol emit?▼

The protocol emits text-start/delta/end, reasoning-start/delta/end, tool-params-start/delta/end, tool-call, tool-result, finish with usage stats, and error parts. Each streaming sequence shares a unique id linking its start, delta, and end parts.