effect-ai-language-model

Generate text, structured output, and streaming responses with the Effect AI LanguageModel service.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires effect.

What problem does it solve? Working with LLM APIs in TypeScript often means untyped responses, ad-hoc error handling, and manual JSON parsing of model output. This Skill teaches the Effect AI LanguageModel service so agents produce type-safe text generation, schema-validated structured output, streaming, and tool calling using Effect's functional patterns. ## Core Features & Use Cases - Text Generation & Streaming: Use generateText for completions and streamText for real-time token, reasoning, and tool-call stream parts. - Structured Output: Use generateObject with Effect Schema to force schema-validated responses, including tagged ADT extraction. - Tool Calling: Attach toolkits, control toolChoice, run parallel tool execution, and handle approval-gated tools. - Provider Patterns: Build custom providers with LanguageModel.make, configure multi-provider fallback with ExecutionPlan, and avoid the common pitfall of leaking LanguageModel into service signatures. - Use Case: Building a chat feature that extracts structured contact data from user messages, streams the reply token-by-token, and falls back from Anthropic to OpenAI on failure. ## Quick Start Ask the agent to write an Effect program that uses LanguageModel.generateObject with a Schema to extract structured data from a prompt, following this skill's import and error-handling patterns.

Frequently Asked Questions about effect-ai-language-model

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

FAQPage Schema
How do I get structured JSON output from an LLM in Effect?▼

Use LanguageModel.generateObject with an Effect Schema defining the expected shape. The response's value field contains the schema-validated object, so invalid model output fails as a typed error instead of requiring manual JSON parsing.

How do I stream LLM responses with Effect?▼

Use LanguageModel.streamText, which returns an Effect Stream of parts such as text-delta, reasoning-delta, and tool-call. Consume it with Stream.runForEach or collect text deltas with Stream.filter and Stream.runFold.

How do I handle LLM API errors in Effect?▼

Catch failures with Effect.catchTag("AiError", ...) and match on error.reason._tag for cases like RateLimitError, AuthenticationError, or ContentPolicyError. Combine with Effect.retry and an exponential Schedule for transient failures.

Why does LanguageModel leak into my service's type signature?▼

Static accessors like LanguageModel.generateText add LanguageModel to the effect's R requirement. To keep clean service signatures, yield the LanguageModel.LanguageModel tag once during layer construction and call methods on the captured instance.

Can I switch between AI providers or add fallback in Effect?▼

Yes. LanguageModel is a service, so different provider layers can be supplied. Use ExecutionPlan with Effect.withExecutionPlan to define multi-provider fallback with per-provider retry attempts and lifecycle event hooks.

How do I control tool calling behavior in generateText?▼

Pass a toolkit and set toolChoice to "auto", "none", "required", a specific tool, or a restricted oneOf subset. Use concurrency for parallel tool execution or disableToolCallResolution to receive encoded tool calls for manual handling.