Skip to content
Effect 4.0 is here. One ecosystem. Zero dependencies.

Prompt unstable

Defines prompts sent to AI language models.

A prompt is an ordered list of messages. Messages can use roles such as system, user, assistant, and tool, and their content can be split into typed parts such as text, files, reasoning, tool calls, tool results, and approval messages. This module helps build prompts, combine them, and convert raw input or response parts into the shared prompt shape.

96 exports Since v4.0.0 Source

Combinators

Since v4.0.0

Creates a new prompt with a leading system message. If the prompt already has a system message, the new message uses the provided content appended to the first existing system message's content; the original messages remain after it.

Signature

declare const appendSystem: {
(content: string): (self: Prompt) => Prompt;
(self: Prompt, content: string): Prompt;
}

Example Appending system instructions

import { Prompt } from "effect/ai"
const systemPrompt = Prompt.make([{
role: "system",
content: "You are an expert in programming."
}])
const userPrompt = Prompt.make("Hello, world!")
const prompt = Prompt.concat(systemPrompt, userPrompt)
const replaced = Prompt.appendSystem(
prompt,
" You are a helpful assistant."
)
// result content: "You are an expert in programming. You are a helpful assistant."
replaced.content[0].content // => "You are an expert in programming. You are a helpful assistant."

concat

unstable
Since v4.0.0

Concatenates a prompt with additional raw input by concatenating messages.

Details

The returned prompt contains all messages from the original prompt followed by the provided raw input, preserving message order.

Signature

declare const concat: {
(input: RawInput): (self: Prompt) => Prompt;
(self: Prompt, input: RawInput): Prompt;
}

Example Concatenating prompts

import { Prompt } from "effect/ai"
const systemPrompt = Prompt.make([{
role: "system",
content: "You are a helpful assistant."
}])
const merged = Prompt.concat(systemPrompt, "Hello, world!")
merged.content.map((message) => message.role) // => ["system", "user"]
Since v4.0.0

Creates a new prompt with a leading system message. If the prompt already has a system message, the new message uses the provided content prepended to the first existing system message's content; the original messages remain after it.

Signature

declare const prependSystem: {
(content: string): (self: Prompt) => Prompt;
(self: Prompt, content: string): Prompt;
}

Example Prepending system instructions

import { Prompt } from "effect/ai"
const systemPrompt = Prompt.make([{
role: "system",
content: "You are an expert in programming."
}])
const userPrompt = Prompt.make("Hello, world!")
const prompt = Prompt.concat(systemPrompt, userPrompt)
const replaced = Prompt.prependSystem(
prompt,
"You are a helpful assistant. "
)
// result content: "You are a helpful assistant. You are an expert in programming."
replaced.content[0].content // => "You are a helpful assistant. You are an expert in programming."

setSystem

unstable
Since v4.0.0

Creates a new prompt from the specified prompt with the system message set to the specified text content.

Gotchas

This method removes and replaces any previous system message from the prompt.

Signature

declare const setSystem: {
(content: string): (self: Prompt) => Prompt;
(self: Prompt, content: string): Prompt;
}

Example Replacing system instructions

import { Prompt } from "effect/ai"
const systemPrompt = Prompt.make([{
role: "system",
content: "You are a helpful assistant."
}])
const userPrompt = Prompt.make("Hello, world!")
const prompt = Prompt.concat(systemPrompt, userPrompt)
const replaced = Prompt.setSystem(
prompt,
"You are an expert in programming"
)
replaced.content[0].content // => "You are an expert in programming"

Constructors

Since v4.0.0

Constructs a new assistant message.

When to use

Use to add assistant-role prompt history or model responses.

Details

This is the role-specific wrapper around makeMessage("assistant", params).

Signature

declare function assistantMessage(params: MessageConstructorParams<AssistantMessage>): AssistantMessage

empty

unstable
Since v4.0.0

An empty prompt with no messages.

Signature

declare const empty: Prompt

Example Creating an empty prompt

import { Prompt } from "effect/ai"
const emptyPrompt = Prompt.empty
emptyPrompt.content // => []

filePart

unstable
Since v4.0.0

Constructs a FilePart for prompt file attachments.

When to use

Use to create the file-attachment part of a prompt from typed file part parameters.

See

  • makePart for the generic part constructor

Signature

declare function filePart(params: PartConstructorParams<FilePart>): FilePart
Since v4.0.0

Creates a Prompt from an array of messages.

Signature

declare function fromMessages(messages: readonly Array<Message>): Prompt

Example Creating prompts from messages

import { Prompt } from "effect/ai"
const messages: ReadonlyArray<Prompt.Message> = [
Prompt.makeMessage("system", {
content: "You are a coding assistant."
}),
Prompt.makeMessage("user", {
content: [Prompt.makePart("text", { text: "Help me with TypeScript" })]
})
]
const prompt = Prompt.fromMessages(messages)
prompt.content.length // => 2
Since v4.0.0

Creates a Prompt from response parts by folding completed text and reasoning streams into assistant parts, preserving provider metadata as prompt options, placing tool calls and approval requests in an assistant message, and placing non-preliminary tool results in a tool message using their encoded results.

Signature

declare function fromResponseParts(parts: readonly Array<AnyPart>): Prompt

Example Creating prompts from response parts

import { Prompt, Response } from "effect/ai"
const responseParts: ReadonlyArray<Response.AnyPart> = [
Response.makePart("text", {
text: "Hello there!"
}),
Response.makePart("tool-call", {
id: "call_1",
name: "get_time",
params: {},
providerExecuted: false
}),
Response.makePart("tool-result", {
id: "call_1",
name: "get_time",
isFailure: false,
result: "10:30 AM",
encodedResult: "10:30 AM",
providerExecuted: false,
preliminary: false
})
]
const prompt = Prompt.fromResponseParts(responseParts)
// Creates an assistant message with the response content
prompt.content.map((message) => message.role) // => ["assistant", "tool"]

make

unstable
Since v4.0.0

Creates a Prompt from an input.

Details

This is the primary constructor for creating prompts, supporting multiple input formats for convenience and flexibility.

Signature

declare function make(input: RawInput): Prompt

Example Creating prompts from inputs

import { Prompt } from "effect/ai"
// From string - creates a user message
const textPrompt = Prompt.make("Hello, how are you?")
// From messages array
const structuredPrompt = Prompt.make([
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: [{ type: "text", text: "Hi!" }] }
])
const copiedPrompt = Prompt.make(Prompt.empty)
const result = [textPrompt.content[0].role, structuredPrompt.content.length, copiedPrompt.content.length] // => ["user", 2, 0]

makeMessage

unstable
Since v4.0.0

Creates a new message with the specified role.

Signature

declare function makeMessage<Role extends "tool" | "user" | "assistant" | "system">(role: Role, params: Omit<Extract<SystemMessage, {
role: Role;
}> | Extract<UserMessage, {
role: Role;
}> | Extract<AssistantMessage, {
role: Role;
}> | Extract<ToolMessage, {
role: Role;
}>, "role" | "options" | "~effect/ai/Prompt/Message"> & {
readonly options?: Extract<SystemMessage, {
role: Role;
}> | Extract<UserMessage, {
role: Role;
}> | Extract<AssistantMessage, {
role: Role;
}> | Extract<ToolMessage, {
role: Role;
}>["options"];
}): Extract<SystemMessage, {
role: Role;
}> | Extract<UserMessage, {
role: Role;
}> | Extract<AssistantMessage, {
role: Role;
}> | Extract<ToolMessage, {
role: Role;
}>

Example Creating messages

import { Prompt } from "effect/ai"
const textPart = Prompt.makePart("text", {
text: "Hello, world!"
})
const userMessage = Prompt.makeMessage("user", {
content: [textPart]
})
const result = [userMessage.role, userMessage.content.length] // => ["user", 1]

makePart

unstable
Since v4.0.0

Creates a new content part of the specified type.

Signature

declare function makePart<Type extends "tool-approval-request" | "file" | "text" | "reasoning" | "tool-call" | "tool-result" | "tool-approval-response">(type: Type, params: Omit<Extract<TextPart, {
type: Type;
}> | Extract<ReasoningPart, {
type: Type;
}> | Extract<FilePart, {
type: Type;
}> | Extract<ToolCallPart, {
type: Type;
}> | Extract<ToolResultPart, {
type: Type;
}> | Extract<ToolApprovalResponsePart, {
type: Type;
}> | Extract<ToolApprovalRequestPart, {
type: Type;
}>, "type" | "~effect/ai/Prompt/Part" | "options"> & {
readonly options?: Extract<TextPart, {
type: Type;
}> | Extract<ReasoningPart, {
type: Type;
}> | Extract<FilePart, {
type: Type;
}> | Extract<ToolCallPart, {
type: Type;
}> | Extract<ToolResultPart, {
type: Type;
}> | Extract<ToolApprovalResponsePart, {
type: Type;
}> | Extract<ToolApprovalRequestPart, {
type: Type;
}>["options"];
}): Extract<TextPart, {
type: Type;
}> | Extract<ReasoningPart, {
type: Type;
}> | Extract<FilePart, {
type: Type;
}> | Extract<ToolCallPart, {
type: Type;
}> | Extract<ToolResultPart, {
type: Type;
}> | Extract<ToolApprovalResponsePart, {
type: Type;
}> | Extract<ToolApprovalRequestPart, {
type: Type;
}>

Example Creating content parts

import { Prompt } from "effect/ai"
const textPart = Prompt.makePart("text", {
text: "Hello, world!"
})
const filePart = Prompt.makePart("file", {
mediaType: "image/png",
fileName: "screenshot.png",
data: new Uint8Array([1, 2, 3])
})
const result = [textPart.type, filePart.type] // => ["text", "file"]
Since v4.0.0

Constructs a new reasoning part.

Signature

declare function reasoningPart(params: PartConstructorParams<ReasoningPart>): ReasoningPart
Since v4.0.0

Constructs a new system message.

Signature

declare function systemMessage(params: MessageConstructorParams<SystemMessage>): SystemMessage

textPart

unstable
Since v4.0.0

Constructs a new text part.

Signature

declare function textPart(params: PartConstructorParams<TextPart>): TextPart

Constructs a new tool approval request part.

Signature

declare function toolApprovalRequestPart(params: PartConstructorParams<ToolApprovalRequestPart>): ToolApprovalRequestPart

Constructs a new tool approval response part.

Signature

declare function toolApprovalResponsePart(params: PartConstructorParams<ToolApprovalResponsePart>): ToolApprovalResponsePart
Since v4.0.0

Constructs a new tool call part.

Signature

declare function toolCallPart(params: PartConstructorParams<ToolCallPart>): ToolCallPart

toolMessage

unstable
Since v4.0.0

Constructs a new tool message.

Signature

declare function toolMessage(params: MessageConstructorParams<ToolMessage>): ToolMessage
Since v4.0.0

Constructs a new tool result part.

Signature

declare function toolResultPart(params: PartConstructorParams<ToolResultPart>): ToolResultPart

userMessage

unstable
Since v4.0.0

Constructs a new user message.

Signature

declare function userMessage(params: MessageConstructorParams<UserMessage>): UserMessage

Guards

isMessage

unstable
Since v4.0.0

Type guard to check if a value is a Message.

Signature

declare function isMessage(u: unknown): u is Message

isPart

unstable
Since v4.0.0

Type guard to check if a value is a Part.

Signature

declare function isPart(u: unknown): u is Part

isPrompt

unstable
Since v4.0.0

Type guard to check if a value is a Prompt.

Signature

declare function isPrompt(u: unknown): u is Prompt

Models

AssistantMessage

interface unstable
Since v4.0.0

Message representing large language model assistant responses.

Signature

interface AssistantMessage extends BaseMessage<"assistant", AssistantMessageOptions> {
readonly content: readonly Array<AssistantMessagePart>;
}

Example Creating assistant messages

import { Prompt } from "effect/ai"
const assistantMessage: Prompt.AssistantMessage = Prompt.makeMessage(
"assistant",
{
content: [
Prompt.makePart("text", {
text:
"I can check the current weather for San Francisco."
}),
Prompt.makePart("tool-call", {
id: "call_123",
name: "get_weather",
params: { city: "San Francisco" },
providerExecuted: false
}),
Prompt.makePart("tool-result", {
id: "call_123",
name: "get_weather",
isFailure: false,
result: {
temperature: 72,
condition: "sunny"
},
providerExecuted: true
}),
Prompt.makePart("text", {
text: "The weather in San Francisco is currently 72ยฐF and sunny."
})
]
}
)
assistantMessage.content.map((part) => part.type) // => ["text", "tool-call", "tool-result", "text"]

AssistantMessageEncoded

interface unstable
Since v4.0.0

Encoded representation of assistant messages for serialization.

Signature

interface AssistantMessageEncoded extends BaseMessageEncoded<"assistant", AssistantMessageOptions> {
readonly content: string | readonly Array<AssistantMessagePartEncoded>;
}
Since v4.0.0

Union type of content parts allowed in assistant messages.

Signature

type AssistantMessagePart = TextPart | FilePart | ReasoningPart | ToolCallPart | ToolResultPart | ToolApprovalRequestPart
Since v4.0.0

Union type of encoded content parts for assistant messages.

Signature

type AssistantMessagePartEncoded = TextPartEncoded | FilePartEncoded | ReasoningPartEncoded | ToolCallPartEncoded | ToolResultPartEncoded | ToolApprovalRequestPartEncoded

BaseMessage

interface unstable
Since v4.0.0

Base interface for all message types.

Details

It provides the common structure shared by all messages, including the role and provider options.

Signature

interface BaseMessage<Role extends string, Options extends ProviderOptions> {
readonly "~effect/ai/Prompt/Message": "~effect/ai/Prompt/Message";
readonly options: Options;
readonly role: Role;
}

BaseMessageEncoded

interface unstable
Since v4.0.0

Base interface for encoded message types.

Signature

interface BaseMessageEncoded<Role extends string, Options extends ProviderOptions> {
readonly options?: Options;
readonly role: Role;
}

BasePart

interface unstable
Since v4.0.0

Base interface for all content parts.

Details

It provides the common structure shared by all content parts, including the part type and provider options.

Signature

interface BasePart<Type extends string, Options extends ProviderOptions> {
readonly "~effect/ai/Prompt/Part": "~effect/ai/Prompt/Part";
readonly options: Options;
readonly type: Type;
}

BasePartEncoded

interface unstable
Since v4.0.0

Base interface for encoded content parts.

Signature

interface BasePartEncoded<Type extends string, Options extends ProviderOptions> {
readonly options?: Options;
readonly type: Type;
}

FilePart

interface unstable
Since v4.0.0

Content part representing a file attachment.

Details

Files can be provided as base64 data strings, byte arrays, or URLs, and can represent images, documents, or other binary data.

Signature

interface FilePart extends BasePart<"file", FilePartOptions> {
readonly data: string | Uint8Array<ArrayBufferLike> | URL;
readonly fileName?: string;
readonly mediaType: string;
}

Example Creating file parts

import { Prompt } from "effect/ai"
const imagePart: Prompt.FilePart = Prompt.makePart("file", {
mediaType: "image/jpeg",
fileName: "photo.jpg",
data: "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQ..."
})
const documentPart: Prompt.FilePart = Prompt.makePart("file", {
mediaType: "application/pdf",
fileName: "report.pdf",
data: new Uint8Array([1, 2, 3])
})
const result = [imagePart.mediaType, documentPart.fileName] // => ["image/jpeg", "report.pdf"]

FilePartEncoded

interface unstable
Since v4.0.0

Encoded representation of file parts for serialization.

Signature

interface FilePartEncoded extends BasePartEncoded<"file", FilePartOptions> {
readonly data: string | Uint8Array<ArrayBufferLike> | URL;
readonly fileName?: string;
readonly mediaType: string;
}

Message

type unstable
Since v4.0.0

A type representing all possible message types in a conversation.

Signature

type Message = SystemMessage | UserMessage | AssistantMessage | ToolMessage

MessageEncoded

type unstable
Since v4.0.0

A type representing all possible encoded message types for serialization.

Signature

type MessageEncoded = SystemMessageEncoded | UserMessageEncoded | AssistantMessageEncoded | ToolMessageEncoded

Part

type unstable
Since v4.0.0

Union type representing all possible content parts within messages.

Details

Parts are the building blocks of message content, supporting text, files, reasoning, tool calls, tool results, tool approval responses, and tool approval requests.

Signature

type Part = TextPart | ReasoningPart | FilePart | ToolCallPart | ToolResultPart | ToolApprovalResponsePart | ToolApprovalRequestPart

PartEncoded

type unstable
Since v4.0.0

Encoded representation of a Part.

Signature

type PartEncoded = TextPartEncoded | ReasoningPartEncoded | FilePartEncoded | ToolCallPartEncoded | ToolResultPartEncoded | ToolApprovalResponsePartEncoded | ToolApprovalRequestPartEncoded

Prompt

interface unstable
Since v4.0.0

A Prompt contains a sequence of messages that form the context of a conversation with a large language model.

Signature

interface Prompt extends Pipeable {
readonly "~effect/ai/Prompt": "~effect/ai/Prompt";
readonly content: readonly Array<Message>;
}

PromptEncoded

interface unstable
Since v4.0.0

Encoded representation of prompts for serialization.

Signature

interface PromptEncoded {
readonly content: readonly Array<MessageEncoded>;
}

RawInput

type unstable
Since v4.0.0

Raw input accepted by make: a string, an iterable of encoded messages, or an existing Prompt.

Signature

type RawInput = string | Iterable<MessageEncoded> | Prompt

Example Accepting raw prompt input

import { Prompt } from "effect/ai"
// String input - creates a user message
const stringInput: Prompt.RawInput = "Hello, world!"
// Message array input
const messagesInput: Prompt.RawInput = [
{ role: "system", content: "You are helpful." },
{ role: "user", content: [{ type: "text", text: "Hi!" }] }
]
const promptInput: Prompt.RawInput = Prompt.empty
const result = [typeof stringInput, Array.isArray(messagesInput), promptInput.content.length] // => ["string", true, 0]

ReasoningPart

interface unstable
Since v4.0.0

Content part carrying reasoning text in an assistant message, such as a provider-supplied reasoning summary or explanation.

Signature

interface ReasoningPart extends BasePart<"reasoning", ReasoningPartOptions> {
readonly text: string;
}

Example Creating reasoning parts

import { Prompt } from "effect/ai"
const reasoningPart: Prompt.ReasoningPart = Prompt.makePart("reasoning", {
text:
"Summary: the response compares the requested options by price and availability."
})
reasoningPart.type // => "reasoning"

ReasoningPartEncoded

interface unstable
Since v4.0.0

Encoded representation of reasoning parts for serialization.

Signature

interface ReasoningPartEncoded extends BasePartEncoded<"reasoning", ReasoningPartOptions> {
readonly text: string;
}

SystemMessage

interface unstable
Since v4.0.0

Message representing system instructions or context.

Signature

interface SystemMessage extends BaseMessage<"system", SystemMessageOptions> {
readonly content: string;
}

Example Creating system messages

import { Prompt } from "effect/ai"
const systemMessage: Prompt.SystemMessage = Prompt.makeMessage("system", {
content: "You are a helpful assistant specialized in mathematics. " +
"Always show your work step by step."
})
systemMessage.role // => "system"

SystemMessageEncoded

interface unstable
Since v4.0.0

Encoded representation of system messages for serialization.

Signature

interface SystemMessageEncoded extends BaseMessageEncoded<"system", SystemMessageOptions> {
readonly content: string;
}

TextPart

interface unstable
Since v4.0.0

Content part representing plain text.

Details

Text parts are the basic content type used for textual information in messages.

Signature

interface TextPart extends BasePart<"text", TextPartOptions> {
readonly text: string;
}

Example Creating text parts

import { Prompt } from "effect/ai"
const textPart: Prompt.TextPart = Prompt.makePart("text", {
text: "Hello, how can I help you today?"
})
textPart.text // => "Hello, how can I help you today?"

TextPartEncoded

interface unstable
Since v4.0.0

Encoded representation of text parts for serialization.

Signature

interface TextPartEncoded extends BasePartEncoded<"text", TextPartOptions> {
readonly text: string;
}

ToolApprovalRequestPart

interface unstable
Since v4.0.0

Content part representing a tool approval request from the framework.

Details

Tool approval request parts are stored in assistant messages when a tool requires user approval before execution. The user responds with a ToolApprovalResponsePart in a tool message.

Signature

interface ToolApprovalRequestPart extends BasePart<"tool-approval-request", ToolApprovalRequestPartOptions> {
readonly approvalId: string;
readonly toolCallId: string;
}

Example Creating tool approval requests

import { Prompt } from "effect/ai"
const approvalRequest: Prompt.ToolApprovalRequestPart = Prompt.makePart(
"tool-approval-request",
{
approvalId: "approval_123",
toolCallId: "call_456"
}
)
const result = [approvalRequest.approvalId, approvalRequest.toolCallId] // => ["approval_123", "call_456"]
Since v4.0.0

Encoded representation of tool approval request parts for serialization.

Signature

interface ToolApprovalRequestPartEncoded extends BasePartEncoded<"tool-approval-request", ToolApprovalRequestPartOptions> {
readonly approvalId: string;
readonly toolCallId: string;
}

ToolApprovalResponsePart

interface unstable
Since v4.0.0

Content part representing a user's response to a tool approval request.

When to use

Use when tool messages must approve or deny tool execution for tools with the needsApproval property set.

Signature

interface ToolApprovalResponsePart extends BasePart<"tool-approval-response", ToolApprovalResponsePartOptions> {
readonly approvalId: string;
readonly approved: boolean;
readonly reason?: string;
}

Example Creating tool approval responses

import { Prompt } from "effect/ai"
const approvalResponse: Prompt.ToolApprovalResponsePart = Prompt.makePart(
"tool-approval-response",
{
approvalId: "approval_123",
approved: true
}
)
const denialResponse: Prompt.ToolApprovalResponsePart = Prompt.makePart(
"tool-approval-response",
{
approvalId: "approval_456",
approved: false,
reason: "Operation not allowed"
}
)
const result = [approvalResponse.approved, denialResponse.approved] // => [true, false]
Since v4.0.0

Encoded representation of tool approval response parts for serialization.

Signature

interface ToolApprovalResponsePartEncoded extends BasePartEncoded<"tool-approval-response", ToolApprovalResponsePartOptions> {
readonly approvalId: string;
readonly approved: boolean;
readonly reason?: string;
}

ToolCallPart

interface unstable
Since v4.0.0

Content part representing a tool call request.

Signature

interface ToolCallPart extends BasePart<"tool-call", ToolCallPartOptions> {
readonly id: string;
readonly name: string;
readonly params: unknown;
readonly providerExecuted: boolean;
}

Example Creating tool call parts

import { Prompt } from "effect/ai"
const toolCallPart: Prompt.ToolCallPart = Prompt.makePart("tool-call", {
id: "call_123",
name: "get_weather",
params: { city: "San Francisco", units: "celsius" },
providerExecuted: false
})
toolCallPart.name // => "get_weather"

ToolCallPartEncoded

interface unstable
Since v4.0.0

Encoded representation of tool call parts for serialization.

Signature

interface ToolCallPartEncoded extends BasePartEncoded<"tool-call", ToolCallPartOptions> {
readonly id: string;
readonly name: string;
readonly params: unknown;
readonly providerExecuted?: boolean;
}

ToolMessage

interface unstable
Since v4.0.0

Message carrying tool-side content, including tool execution results and responses to tool approval requests.

Signature

interface ToolMessage extends BaseMessage<"tool", ToolMessageOptions> {
readonly content: readonly Array<ToolMessagePart>;
}

Example Creating tool messages

import { Prompt } from "effect/ai"
const toolMessage: Prompt.ToolMessage = Prompt.makeMessage("tool", {
content: [
Prompt.makePart("tool-result", {
id: "call_123",
name: "search_web",
isFailure: false,
result: {
query: "TypeScript best practices",
results: [
{ title: "TypeScript Handbook", url: "https://..." },
{ title: "Effective TypeScript", url: "https://..." }
]
},
providerExecuted: false
})
]
})
const result = [toolMessage.role, toolMessage.content[0].type] // => ["tool", "tool-result"]

ToolMessageEncoded

interface unstable
Since v4.0.0

Encoded representation of tool messages for serialization.

Signature

interface ToolMessageEncoded extends BaseMessageEncoded<"tool", ToolMessageOptions> {
readonly content: readonly Array<ToolMessagePartEncoded>;
}

ToolMessagePart

type unstable
Since v4.0.0

Union type of content parts allowed in tool messages.

Signature

type ToolMessagePart = ToolResultPart | ToolApprovalResponsePart
Since v4.0.0

Union type of encoded content parts for tool messages.

Signature

type ToolMessagePartEncoded = ToolResultPartEncoded | ToolApprovalResponsePartEncoded

ToolResultPart

interface unstable
Since v4.0.0

Content part representing the result of a tool call.

Signature

interface ToolResultPart extends BasePart<"tool-result", ToolResultPartOptions> {
readonly id: string;
readonly isFailure: boolean;
readonly name: string;
readonly providerExecuted: boolean;
readonly result: unknown;
}

Example Creating tool result parts

import { Prompt } from "effect/ai"
const toolResultPart: Prompt.ToolResultPart = Prompt.makePart("tool-result", {
id: "call_123",
name: "get_weather",
isFailure: false,
result: {
temperature: 22,
condition: "sunny",
humidity: 65
},
providerExecuted: false
})
const result = [toolResultPart.name, toolResultPart.isFailure] // => ["get_weather", false]

ToolResultPartEncoded

interface unstable
Since v4.0.0

Encoded representation of tool result parts for serialization.

Signature

interface ToolResultPartEncoded extends BasePartEncoded<"tool-result", ToolResultPartOptions> {
readonly id: string;
readonly isFailure: boolean;
readonly name: string;
readonly providerExecuted?: boolean;
readonly result: unknown;
}

UserMessage

interface unstable
Since v4.0.0

Message representing user input or questions.

Signature

interface UserMessage extends BaseMessage<"user", UserMessageOptions> {
readonly content: readonly Array<UserMessagePart>;
}

Example Creating user messages

import { Prompt } from "effect/ai"
const textUserMessage: Prompt.UserMessage = Prompt.makeMessage("user", {
content: [
Prompt.makePart("text", {
text: "Can you analyze this image for me?"
})
]
})
const multimodalUserMessage: Prompt.UserMessage = Prompt.makeMessage("user", {
content: [
Prompt.makePart("text", {
text: "What do you see in this image?"
}),
Prompt.makePart("file", {
mediaType: "image/jpeg",
fileName: "vacation.jpg",
data: "data:image/jpeg;base64,..."
})
]
})
const result = [textUserMessage.content.length, multimodalUserMessage.content.length] // => [1, 2]

UserMessageEncoded

interface unstable
Since v4.0.0

Encoded representation of user messages for serialization.

Signature

interface UserMessageEncoded extends BaseMessageEncoded<"user", UserMessageOptions> {
readonly content: string | readonly Array<UserMessagePartEncoded>;
}

UserMessagePart

type unstable
Since v4.0.0

Union type of content parts allowed in user messages.

Signature

type UserMessagePart = TextPart | FilePart
Since v4.0.0

Union type of encoded content parts for user messages.

Signature

type UserMessagePartEncoded = TextPartEncoded | FilePartEncoded

Options

AssistantMessageOptions

interface unstable
Since v4.0.0

Represents provider-specific options that can be associated with a AssistantMessage through module augmentation.

Signature

interface AssistantMessageOptions extends ProviderOptions {
[key: string]: Json;
}

FilePartOptions

interface unstable
Since v4.0.0

Represents provider-specific options that can be associated with a FilePart through module augmentation.

Signature

interface FilePartOptions extends ProviderOptions {
[key: string]: Json;
}
Since v4.0.0

Schema for provider-specific options that can be attached to content parts and messages.

Details

Provider-specific options are keyed by provider-specific names, and each value is JSON or null.

Signature

declare const ProviderOptions: Schema.$Record<Schema.String, Schema.NullOr<Schema.Codec<Schema.Json>>>

ProviderOptions

type unstable
Since v4.0.0

Type of provider-specific options that can be attached to prompt messages and content parts.

Signature

type ProviderOptions = typeof ProviderOptions.Type

ReasoningPartOptions

interface unstable
Since v4.0.0

Represents provider-specific options that can be associated with a ReasoningPart through module augmentation.

Signature

interface ReasoningPartOptions extends ProviderOptions {
[key: string]: Json;
}

SystemMessageOptions

interface unstable
Since v4.0.0

Represents provider-specific options that can be associated with a SystemMessage through module augmentation.

Signature

interface SystemMessageOptions extends ProviderOptions {
[key: string]: Json;
}

TextPartOptions

interface unstable
Since v4.0.0

Represents provider-specific options that can be associated with a TextPart through module augmentation.

Signature

interface TextPartOptions extends ProviderOptions {
[key: string]: Json;
}
Since v4.0.0

Represents provider-specific options that can be associated with a ToolApprovalRequestPart through module augmentation.

Signature

interface ToolApprovalRequestPartOptions extends ProviderOptions {
[key: string]: Json;
}
Since v4.0.0

Represents provider-specific options that can be associated with a ToolApprovalResponsePart through module augmentation.

Signature

interface ToolApprovalResponsePartOptions extends ProviderOptions {
[key: string]: Json;
}

ToolCallPartOptions

interface unstable
Since v4.0.0

Represents provider-specific options that can be associated with a ToolCallPart through module augmentation.

Signature

interface ToolCallPartOptions extends ProviderOptions {
[key: string]: Json;
}

ToolMessageOptions

interface unstable
Since v4.0.0

Represents provider-specific options that can be associated with a ToolMessage through module augmentation.

Signature

interface ToolMessageOptions extends ProviderOptions {
[key: string]: Json;
}

ToolResultPartOptions

interface unstable
Since v4.0.0

Represents provider-specific options that can be associated with a ToolResultPart through module augmentation.

Signature

interface ToolResultPartOptions extends ProviderOptions {
[key: string]: Json;
}

UserMessageOptions

interface unstable
Since v4.0.0

Represents provider-specific options that can be associated with a UserMessage through module augmentation.

Signature

interface UserMessageOptions extends ProviderOptions {
[key: string]: Json;
}

Schemas

Since v4.0.0

Schema for validation and encoding of assistant messages.

Details

Assistant content can be a string decoded through ContentFromString or an array of text, file, reasoning, tool-call, tool-result, and tool-approval-request parts.

Signature

declare const AssistantMessage: Struct<{
readonly "~effect/ai/Prompt/Message": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Message">>;
readonly content: Union<readonly [decodeTo<NonEmptyArray<toType<Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<...>>;
readonly options: withDecodingDefault<$Record<..., ...>>;
readonly text: String;
readonly type: Literal<"text">;
}>>>, String, never, never>, $Array<Union<readonly [Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<...>>;
readonly options: withDecodingDefault<$Record<..., ...>>;
readonly text: String;
readonly type: Literal<"text">;
}>, Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<...>>;
readonly data: Union<readonly [..., ..., ...]>;
readonly fileName: optional<String>;
readonly mediaType: String;
readonly options: withDecodingDefault<$Record<..., ...>>;
readonly type: Literal<"file">;
}>, Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<...>>;
readonly options: withDecodingDefault<$Record<..., ...>>;
readonly text: String;
readonly type: Literal<"reasoning">;
}>, Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<...>>;
readonly id: String;
readonly name: String;
readonly options: withDecodingDefault<$Record<..., ...>>;
readonly params: Unknown;
readonly providerExecuted: withDecodingDefault<Boolean>;
readonly type: Literal<"tool-call">;
}>, Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<...>>;
readonly id: String;
readonly isFailure: Boolean;
readonly name: String;
readonly options: withDecodingDefault<$Record<..., ...>>;
readonly providerExecuted: withDecodingDefault<Boolean>;
readonly result: Unknown;
readonly type: Literal<"tool-result">;
}>, Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<...>>;
readonly approvalId: String;
readonly options: withDecodingDefault<$Record<..., ...>>;
readonly toolCallId: String;
readonly type: Literal<"tool-approval-request">;
}>]>>]>;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly role: Literal<"assistant">;
}>
Since v4.0.0

Schema for validation and encoding of assistant message content parts.

Signature

declare const AssistantMessagePart: Union<readonly [Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly text: String;
readonly type: Literal<"text">;
}>, Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly data: Union<readonly [String, Uint8Array, URL]>;
readonly fileName: optional<String>;
readonly mediaType: String;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly type: Literal<"file">;
}>, Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly text: String;
readonly type: Literal<"reasoning">;
}>, Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly id: String;
readonly name: String;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly params: Unknown;
readonly providerExecuted: withDecodingDefault<Boolean>;
readonly type: Literal<"tool-call">;
}>, Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly id: String;
readonly isFailure: Boolean;
readonly name: String;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly providerExecuted: withDecodingDefault<Boolean>;
readonly result: Unknown;
readonly type: Literal<"tool-result">;
}>, Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly approvalId: String;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly toolCallId: String;
readonly type: Literal<"tool-approval-request">;
}>]>
Since v4.0.0

Schema that decodes a string into content containing a single TextPart and, when encoding, emits the text value of the first part.

Signature

declare const ContentFromString: Schema.decodeTo<Schema.NonEmptyArray<Schema.toType<Schema.Struct<{
readonly "~effect/ai/Prompt/Part": Schema.withDecodingDefaultKey<Schema.Literal<"~effect/ai/Prompt/Part">>;
readonly options: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.NullOr<Schema.Codec<Schema.Json>>>>;
readonly text: Schema.String;
readonly type: Schema.Literal<"text">;
}>>>, Schema.String>

FilePart

unstable
Since v4.0.0

Schema for validation and encoding of file parts.

Signature

declare const FilePart: Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly data: Union<readonly [String, Uint8Array, URL]>;
readonly fileName: optional<String>;
readonly mediaType: String;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly type: Literal<"file">;
}>

Message

unstable
Since v4.0.0

Schema for validation and encoding of messages.

Signature

declare const Message: Codec<Message, MessageEncoded, never, never>

Part

unstable
Since v4.0.0

Schema for validation and encoding of content parts.

Signature

declare const Part: Union<readonly [Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly text: String;
readonly type: Literal<"text">;
}>, Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly text: String;
readonly type: Literal<"reasoning">;
}>, Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly data: Union<readonly [String, Uint8Array, URL]>;
readonly fileName: optional<String>;
readonly mediaType: String;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly type: Literal<"file">;
}>, Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly id: String;
readonly name: String;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly params: Unknown;
readonly providerExecuted: withDecodingDefault<Boolean>;
readonly type: Literal<"tool-call">;
}>, Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly id: String;
readonly isFailure: Boolean;
readonly name: String;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly providerExecuted: withDecodingDefault<Boolean>;
readonly result: Unknown;
readonly type: Literal<"tool-result">;
}>, Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly approvalId: String;
readonly approved: Boolean;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly reason: optional<String>;
readonly type: Literal<"tool-approval-response">;
}>, Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly approvalId: String;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly toolCallId: String;
readonly type: Literal<"tool-approval-request">;
}>]>

Prompt

unstable
Since v4.0.0

Schema for AI prompt instances.

Signature

declare const Prompt: Codec<Prompt, PromptEncoded, never, never>
Since v4.0.0

Schema for validation and encoding of reasoning parts.

Signature

declare const ReasoningPart: Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly text: String;
readonly type: Literal<"reasoning">;
}>
Since v4.0.0

Schema for validation and encoding of system messages.

Signature

declare const SystemMessage: Struct<{
readonly "~effect/ai/Prompt/Message": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Message">>;
readonly content: String;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly role: Literal<"system">;
}>

TextPart

unstable
Since v4.0.0

Schema for validation and encoding of text parts.

Signature

declare const TextPart: Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly text: String;
readonly type: Literal<"text">;
}>

Schema for validation and encoding of tool approval request parts.

Signature

declare const ToolApprovalRequestPart: Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly approvalId: String;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly toolCallId: String;
readonly type: Literal<"tool-approval-request">;
}>

Schema for validation and encoding of tool approval response parts.

Signature

declare const ToolApprovalResponsePart: Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly approvalId: String;
readonly approved: Boolean;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly reason: optional<String>;
readonly type: Literal<"tool-approval-response">;
}>
Since v4.0.0

Schema for validation and encoding of tool call parts.

Signature

declare const ToolCallPart: Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly id: String;
readonly name: String;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly params: Unknown;
readonly providerExecuted: withDecodingDefault<Boolean>;
readonly type: Literal<"tool-call">;
}>

ToolMessage

unstable
Since v4.0.0

Schema for validation and encoding of tool messages.

Signature

declare const ToolMessage: Struct<{
readonly "~effect/ai/Prompt/Message": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Message">>;
readonly content: $Array<Union<readonly [Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly id: String;
readonly isFailure: Boolean;
readonly name: String;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<..., ..., ..., ...>>>>;
readonly providerExecuted: withDecodingDefault<Boolean>;
readonly result: Unknown;
readonly type: Literal<"tool-result">;
}>, Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly approvalId: String;
readonly approved: Boolean;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<..., ..., ..., ...>>>>;
readonly reason: optional<String>;
readonly type: Literal<"tool-approval-response">;
}>]>>;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly role: Literal<"tool">;
}>
Since v4.0.0

Schema for validation and encoding of tool message content parts.

Signature

declare const ToolMessagePart: Union<readonly [Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly id: String;
readonly isFailure: Boolean;
readonly name: String;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly providerExecuted: withDecodingDefault<Boolean>;
readonly result: Unknown;
readonly type: Literal<"tool-result">;
}>, Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly approvalId: String;
readonly approved: Boolean;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly reason: optional<String>;
readonly type: Literal<"tool-approval-response">;
}>]>
Since v4.0.0

Schema for validation and encoding of tool result parts.

Signature

declare const ToolResultPart: Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly id: String;
readonly isFailure: Boolean;
readonly name: String;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly providerExecuted: withDecodingDefault<Boolean>;
readonly result: Unknown;
readonly type: Literal<"tool-result">;
}>

UserMessage

unstable
Since v4.0.0

Schema for validation and encoding of user messages.

Signature

declare const UserMessage: Struct<{
readonly "~effect/ai/Prompt/Message": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Message">>;
readonly content: Union<readonly [decodeTo<NonEmptyArray<toType<Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<...>>;
readonly options: withDecodingDefault<$Record<..., ...>>;
readonly text: String;
readonly type: Literal<"text">;
}>>>, String, never, never>, $Array<Union<readonly [Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<...>>;
readonly options: withDecodingDefault<$Record<..., ...>>;
readonly text: String;
readonly type: Literal<"text">;
}>, Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<...>>;
readonly data: Union<readonly [..., ..., ...]>;
readonly fileName: optional<String>;
readonly mediaType: String;
readonly options: withDecodingDefault<$Record<..., ...>>;
readonly type: Literal<"file">;
}>]>>]>;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly role: Literal<"user">;
}>
Since v4.0.0

Schema for validation and encoding of user message content parts.

Signature

declare const UserMessagePart: Union<readonly [Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly text: String;
readonly type: Literal<"text">;
}>, Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly data: Union<readonly [String, Uint8Array, URL]>;
readonly fileName: optional<String>;
readonly mediaType: String;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly type: Literal<"file">;
}>]>

Utility Types

Since v4.0.0

A utility type for specifying the parameters required to construct a specific message for a prompt.

Signature

type MessageConstructorParams<M extends Message> = Omit<M, typeof MessageTypeId | "role" | "options"> & {
readonly options?: M["options"];
}
Since v4.0.0

A utility type for specifying the parameters required to construct a specific part of a prompt.

Signature

type PartConstructorParams<P extends Part> = Omit<P, typeof PartTypeId | "type" | "options"> & {
readonly options?: Part["options"];
}