This skill should be used when the user asks about "Effect AI", "@effect/ai", "LLM integration", "AI tool use", "AI execution planning", "building AI agents", "AI providers", "structured AI output", "AI completions", "Effect OpenAI", "Effect Anthropic", or needs to understand how Effect integrates with AI/LLM services.
Effect AI (@effect/ai) provides type-safe integration with AI/LLM services:
npm install @effect/ai @effect/ai-openai
# or
npm install @effect/ai @effect/ai-anthropic
import { AiChat } from "@effect/ai";
import { OpenAiChat } from "@effect/ai-openai";
import { Effect, Layer } from "effect";
const OpenAiLive = OpenAiChat.layer({
apiKey: Config.redacted("OPENAI_API_KEY"),
model: "gpt-4",
});
import { AnthropicChat } from "@effect/ai-anthropic";
const AnthropicLive = AnthropicChat.layer({
apiKey: Config.redacted("ANTHROPIC_API_KEY"),
model: "claude-3-opus-20240229",
});
const program = Effect.gen(function* () {
const ai = yield* AiChat.AiChat;
const response = yield* ai.generateText({
prompt: "Explain functional programming in one sentence.",
});
return response.text;
});
const result = yield * program.pipe(Effect.provide(OpenAiLive));
const chat = Effect.gen(function* () {
const ai = yield* AiChat.AiChat;
const response = yield* ai.generateText({
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "What is Effect-TS?" },
],
});
return response.text;
});
Define tools that AI can call:
import { AiTool } from "@effect/ai";
import { Schema } from "effect";
const WeatherInput = Schema.Struct({
city: Schema.String,
unit: Schema.optional(Schema.Literal("celsius", "fahrenheit")),
});
const getWeather = AiTool.make({
name: "get_weather",
description: "Get current weather for a city",...