function chat<TAdapter, TSchema, TStream, TTools, TInterrupts, TContext, TMiddleware>(options): TextActivityResult<TSchema, TStream, TTools>;Defined in: packages/ai/src/activities/chat/index.ts:4643
Text activity - handles agentic text generation, one-shot text generation, and agentic structured output.
This activity supports four modes:
TAdapter extends AnyTextAdapter
TSchema extends SchemaInput | undefined = undefined
TStream extends boolean = boolean
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 extends readonly InterruptDefinition<any, any, any, any, any>[] = []
TContext = unknown
TMiddleware extends unknown[] | undefined = undefined
TextActivityOptionsWithContext<TAdapter, TSchema, TStream, TTools, TInterrupts, TContext, TMiddleware>
TextActivityResult<TSchema, TStream, TTools>
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?' }],
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!' }]
})) {
console.log(chunk)
}Non-streaming text (stream: false)
const text = await chat({
adapter: openaiText('gpt-5.5'),
messages: [{ role: 'user', content: 'Hello!' }],
stream: false
})
// text is a string with the full responseAgentic 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' }],
tools: [researchTool, analyzeTool],
outputSchema: z.object({
summary: z.string(),
keyPoints: z.array(z.string())
})
})
// result is { summary: string, keyPoints: string[] }