Open History to see the last commit
1---
2id: decide
3title: decide
4---
5
6```ts
7function decide<TAdapter, TQuestions>(options): Promise<{ [K in string | number | symbol]: InferEvaluateAnswer<TQuestions[K]> } & object>;
8```
9
10Defined in: packages/ai/src/activities/evaluate/index.ts:497
11
12Ask typed questions about `state` and get answers your code can branch on.
13
14You have state (a ticket, a record, a log) and you need typed answers, not
15prose. Pass questions built with `choice`, `score`, and `boolean`. Then
16branch on `result.queue.value` in ordinary TypeScript.
17
18The question key `meta` is reserved. Throws if `questions` is empty or uses
19that key.
20
21## Type Parameters
22
23### TAdapter
24
25`TAdapter` *extends* [`EvaluateAdapter`](../interfaces/EvaluateAdapter.md)\<`string`, `EvaluateProviderOptions`\<`TAdapter`\>\>
26
27### TQuestions
28
29`TQuestions` *extends* `Record`\<`string`, [`WireQuestion`](../type-aliases/WireQuestion.md)\>
30
31## Parameters
32
33### options
34
35`EvaluateActivityOptions`\<`TAdapter`, `TQuestions`\>
36
37## Returns
38
39`Promise`\<\{ \[K in string \| number \| symbol\]: InferEvaluateAnswer\<TQuestions\[K\]\> \} & `object`\>
40
41## Example
42
43**Route a support ticket**
44
45```ts
46import { decide, choice, score, boolean } from '@tanstack/ai'
47import { typesafeDecider } from '@tanstack/ai-typesafe'
48
49const result = await decide({
50 adapter: typesafeDecider('jev-latest'),
51 state: ticket,
52 questions: {
53 queue: choice({
54 instructions: 'Which team should handle this ticket?',
55 options: {
56 billing: 'Payments, invoices, refunds',
57 tech: 'Bugs, outages, integrations',
58 sales: 'Pricing, upgrades, new accounts',
59 },
60 }),
61 urgency: score({
62 instructions: 'How urgent is this ticket?',
63 levels: ['low', 'medium', 'high'],
64 }),
65 refund: boolean({
66 instructions: 'Is the customer asking for a refund?',
67 }),
68 },
69})
70
71result.queue.value
72result.meta.model
73result.meta.usage
74```