Class References
Function References
- text
- textOptions
- combineStrategies
- convertMessagesToModelMessages
- convertZodToJsonSchema
- createReplayStream
- embedding
- generateMessageId
- maxIterations
- messages
- modelMessageToUIMessage
- modelMessagesToUIMessages
- normalizeToUIMessage
- parsePartialJSON
- summarize
- toServerSentEventsStream
- toServerSentEventsResponse
- toolDefinition
- uiMessageToModelMessages
- realtimeToken
- untilFinishReason
Interface References
- AIAdapter
- AIAdapterConfig
- AgentLoopState
- AudioPart
- AudioVisualization
- BaseStreamChunk
- TextCompletionChunk
- TextOptions
- ChunkRecording
- ChunkStrategy
- ClientTool
- ContentPartSource
- ContentStreamChunk
- DefaultMessageMetadataByModality
- DocumentPart
- DoneStreamChunk
- EmbeddingOptions
- EmbeddingResult
- ErrorStreamChunk
- ImagePart
- InternalToolCallState
- JSONParser
- ModelMessage
- ProcessorResult
- ProcessorState
- RealtimeAdapter
- RealtimeClientOptions
- RealtimeConnection
- RealtimeMessage
- RealtimeSessionConfig
- RealtimeToken
- RealtimeTokenAdapter
- RealtimeTokenOptions
- ResponseFormat
- ServerTool
- StreamProcessorEvents
- StreamProcessorHandlers
- StreamProcessorOptions
- SummarizationOptions
- SummarizationResult
- TextPart
- ThinkingPart
- ThinkingStreamChunk
- Tool
- ToolCall
- ToolCallPart
- ToolCallStreamChunk
- ToolConfig
- ToolDefinition
- ToolDefinitionConfig
- ToolDefinitionInstance
- ToolInputAvailableStreamChunk
- ToolResultPart
- ToolResultStreamChunk
- UIMessage
- VideoPart
Type Alias References
- AgentLoopStrategy
- AnyClientTool
- TextStreamOptionsForModel
- TextStreamOptionsUnion
- ConstrainedContent
- ConstrainedModelMessage
- ContentPart
- ContentPartForModalities
- ExtractModalitiesForModel
- ExtractModelsFromAdapter
- InferToolInput
- InferToolName
- InferToolOutput
- MessagePart
- RealtimeEvent
- RealtimeMessagePart
- RealtimeMode
- RealtimeStatus
- ModalitiesArrayToUnion
- Modality
- StreamChunk
- ToolCallState
- ToolResultState
Variable References
chat
function chat<TAdapter, TSchema, TStream, TTools, TInterrupts, TContext, TMiddleware, TAgents>(options): TextActivityResult<TSchema, TStream, TTools>;Defined in: packages/ai/src/activities/chat/index.ts:6128
Text activity - handles agentic text generation, one-shot text generation, and agentic structured output.
This activity supports four modes:
- Streaming agentic text: Stream responses with automatic tool execution
- Streaming one-shot text: Simple streaming request/response without tools
- Non-streaming text: Returns a ChatResult with the text and every chunk (stream: false)
- Agentic structured output: Run tools, then return structured data
Type Parameters#
TAdapter#
TAdapter extends AnyTextAdapter
TSchema#
TSchema extends SchemaInput | undefined = undefined
TStream#
TStream extends boolean = boolean
TTools#
TTools extends | readonly ( | Omit<Tool<any, any, any, any>, "execute"> & object & object | ProviderTool<string, TAdapter["~types"]["toolCapabilities"][number]>)[] | undefined = | readonly ( | Omit<Tool<any, any, any, any>, "execute"> & object & object | ProviderTool<string, TAdapter["~types"]["toolCapabilities"][number]>)[] | undefined
TInterrupts#
TInterrupts extends readonly InterruptDefinition<any, any, any, any, any>[] = []
TContext#
TContext = unknown
TMiddleware#
TMiddleware extends unknown[] | undefined = undefined
TAgents#
TAgents extends readonly DefinedAgent<string, readonly SubagentTool[], SchemaInput | undefined, readonly InterruptDefinition<any, any, any, any, any>[], any, unknown, AgentProduces | undefined>[] = readonly DefinedAgent<string, readonly SubagentTool[], SchemaInput | undefined, readonly InterruptDefinition<any, any, any, any, any>[], any, unknown, AgentProduces | undefined>[]
Parameters#
options#
TextActivityOptionsWithContext<TAdapter, TSchema, TStream, TTools, TInterrupts, TContext, TMiddleware, TAgents>
Returns#
TextActivityResult<TSchema, TStream, TTools>
Examples#
Full agentic text (streaming with tools)
import { chat } from '@tanstack/ai'
import { openaiText } from '@tanstack/ai-openai'
for await (const chunk of chat({
adapter: openaiText('gpt-5.5'),
messages: [{ role: 'user', content: 'What is the weather?' }],
threadId,
tools: [weatherTool]
})) {
if (chunk.type === 'TEXT_MESSAGE_CONTENT') {
console.log(chunk.delta)
}
}One-shot text (streaming without tools)
for await (const chunk of chat({
adapter: openaiText('gpt-5.5'),
messages: [{ role: 'user', content: 'Hello!' }],
threadId,
})) {
console.log(chunk)
}Non-streaming text (stream: false)
const { text, chunks } = await chat({
adapter: openaiText('gpt-5.5'),
messages: [{ role: 'user', content: 'Hello!' }],
threadId,
stream: false
})
// text is a string with the full response
// chunks is every chunk the run produced, in orderAgentic structured output (tools + structured response)
import { z } from 'zod'
const result = await chat({
adapter: openaiText('gpt-5.5'),
messages: [{ role: 'user', content: 'Research and summarize the topic' }],
threadId,
tools: [researchTool, analyzeTool],
outputSchema: z.object({
summary: z.string(),
keyPoints: z.array(z.string())
})
})
// result is { summary: string, keyPoints: string[] }