effect-ai-language-model

Implements type-safe LLM text generation, structured output, streaming, and tool calling with Effect.

1|Updated Aug 24, 2026
One-click install
npx skills add https://github.com/lambdasolver2/opencode-effect-harness --skill effect-ai-language-model-lambdasolver2
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: effect-ai-language-model
Source: https://github.com/lambdasolver2/opencode-effect-harness/tree/main/packages/module-typescript/assets/skills/effect-ai-language-model
Command: npx skills add https://github.com/lambdasolver2/opencode-effect-harness --skill effect-ai-language-model-lambdasolver2

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires effect.

What problem does it solve? Building LLM-powered features in TypeScript often leads to untyped responses, ad-hoc error handling, and callback-heavy streaming code. This Skill provides patterns for using the Effect AI LanguageModel service so LLM interactions are type-safe, composable, and integrated with Effect's error handling and concurrency model. ## Core Features & Use Cases - Text Generation: Use generateText for single-turn completions, multi-turn conversations with prompt history, and tool calling with configurable toolChoice modes. - Structured Output: Use generateObject with Effect Schema to force schema-validated responses, including tagged ADT extraction. - Streaming: Use streamText to process real-time text, reasoning, and tool-parameter deltas as typed Stream parts. - Provider Implementation: Build custom LanguageModel providers with LanguageModel.make, plus multi-provider fallback via ExecutionPlan. - Use Case: You are building a chat feature that extracts structured contact data from user messages, streams responses to the UI, and falls back between Anthropic and OpenAI providers on failure. ## Quick Start Ask the AI to write an Effect program that uses LanguageModel.generateObject with a Schema to extract structured data from a user prompt.

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 generate structured 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, and you can optionally set objectName to aid model understanding.

How do I stream LLM responses with Effect?

Use LanguageModel.streamText, which returns an Effect Stream of typed 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 errors in Effect AI?

Catch failures with Effect.catchTag("AiError", ...) and match on error.reason._tag for specific cases like RateLimitError, AuthenticationError, or StructuredOutputError. Avoid constructing generic Error instances; use AiError.make with tagged reasons.

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

Static accessors like LanguageModel.generateText add LanguageModel to the effect's R requirement. To avoid this, yield the LanguageModel.LanguageModel tag during layer construction and capture it in the closure, keeping service method signatures clean.

Can I switch between LLM providers with Effect AI?

Yes. Use ExecutionPlan from effect/ExecutionPlan to define multi-provider fallback with per-provider retry attempts, such as Anthropic with three attempts followed by OpenAI with two. You can also read the active provider via Model.ProviderName.

How do I control tool calling behavior in generateText?

Set the toolChoice option: "auto" lets the model decide, "none" forces text-only, "required" forces a tool call, and { tool: "name" } or oneOf restricts which tools are available. Use disableToolCallResolution to receive tool calls without executing them.