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
decide
function decide<TAdapter, TQuestions>(options): Promise<{ [K in string | number | symbol]: InferEvaluateAnswer<TQuestions[K]> } & object>;Defined in: packages/ai/src/activities/evaluate/index.ts:502
Ask typed questions about state and get answers your code can branch on.
You have state (a ticket, a record, a log) and you need typed answers, not prose. Pass questions built with choice, score, and boolean. Then branch on result.queue.value in ordinary TypeScript.
The question key meta is reserved. Throws if questions is empty or uses that key.
When the adapter throws an EvaluateError that carries usage, decide() reports that usage through onUsage and the evaluate:usage event, then runs onError and rethrows the same error.
Type Parameters#
TAdapter#
TAdapter extends EvaluateAdapter<string, EvaluateProviderOptions<TAdapter>>
TQuestions#
TQuestions extends Record<string, WireQuestion>
Parameters#
options#
EvaluateActivityOptions<TAdapter, TQuestions>
Returns#
Promise<{ [K in string | number | symbol]: InferEvaluateAnswer<TQuestions[K]> } & object>
Example#
Route a support ticket
import { decide, choice, score, boolean } from '@tanstack/ai'
import { typesafeDecider } from '@tanstack/ai-typesafe'
const result = await decide({
adapter: typesafeDecider('jev-latest'),
state: ticket,
questions: {
queue: choice({
instructions: 'Which team should handle this ticket?',
options: {
billing: 'Payments, invoices, refunds',
tech: 'Bugs, outages, integrations',
sales: 'Pricing, upgrades, new accounts',
},
}),
urgency: score({
instructions: 'How urgent is this ticket?',
levels: ['low', 'medium', 'high'],
}),
refund: boolean({
instructions: 'Is the customer asking for a refund?',
}),
},
})
result.queue.value
result.meta.model
result.meta.usage