Open History to see the last commit
1---
2id: BoundActivities
3title: BoundActivities
4---
5
6Defined in: [packages/ai/src/activities/chat/agents/bound.ts:97](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/agents/bound.ts#L97)
7
8Activity functions bound to one child run. Each takes the same options as
9the plain function. Options you pass win over the bound defaults.
10
11## Properties
12
13### chat
14
15```ts
16chat: <TAdapter, TSchema, TStream, TTools, TInterrupts, TContext, TMiddleware, TAgents>(options) => TextActivityResult<TSchema, TStream, TTools>;
17```
18
19Defined in: [packages/ai/src/activities/chat/agents/bound.ts:98](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/agents/bound.ts#L98)
20
21Text activity - handles agentic text generation, one-shot text generation, and agentic structured output.
22
23This activity supports four modes:
241. **Streaming agentic text**: Stream responses with automatic tool execution
252. **Streaming one-shot text**: Simple streaming request/response without tools
263. **Non-streaming text**: Returns a ChatResult with the text and every chunk (stream: false)
274. **Agentic structured output**: Run tools, then return structured data
28
29#### Type Parameters
30
31##### TAdapter
32
33`TAdapter` *extends* [`AnyTextAdapter`](../type-aliases/AnyTextAdapter.md)
34
35##### TSchema
36
37`TSchema` *extends* [`SchemaInput`](../type-aliases/SchemaInput.md) \| `undefined` = `undefined`
38
39##### TStream
40
41`TStream` *extends* `boolean` = `boolean`
42
43##### TTools
44
45`TTools` *extends*
46 \| readonly (
47 \| `Omit`\<[`Tool`](Tool.md)\<`any`, `any`, `any`, `any`\>, `"execute"`\> & `object` & `object`
48 \| [`ProviderTool`](ProviderTool.md)\<`string`, `TAdapter`\[`"~types"`\]\[`"toolCapabilities"`\]\[`number`\]\>)[]
49 \| `undefined` =
50 \| readonly (
51 \| `Omit`\<[`Tool`](Tool.md)\<`any`, `any`, `any`, `any`\>, `"execute"`\> & `object` & `object`
52 \| [`ProviderTool`](ProviderTool.md)\<`string`, `TAdapter`\[`"~types"`\]\[`"toolCapabilities"`\]\[`number`\]\>)[]
53 \| `undefined`
54
55##### TInterrupts
56
57`TInterrupts` *extends* readonly [`InterruptDefinition`](InterruptDefinition.md)\<`any`, `any`, `any`, `any`, `any`\>[] = \[\]
58
59##### TContext
60
61`TContext` = `unknown`
62
63##### TMiddleware
64
65`TMiddleware` *extends* `unknown`[] \| `undefined` = `undefined`
66
67##### TAgents
68
69`TAgents` *extends* readonly [`DefinedAgent`](DefinedAgent.md)\<`string`, readonly `SubagentTool`[], [`SchemaInput`](../type-aliases/SchemaInput.md) \| `undefined`, readonly [`InterruptDefinition`](InterruptDefinition.md)\<`any`, `any`, `any`, `any`, `any`\>[], `any`, `unknown`, [`AgentProduces`](../type-aliases/AgentProduces.md) \| `undefined`\>[] = readonly [`DefinedAgent`](DefinedAgent.md)\<`string`, readonly `SubagentTool`[], [`SchemaInput`](../type-aliases/SchemaInput.md) \| `undefined`, readonly [`InterruptDefinition`](InterruptDefinition.md)\<`any`, `any`, `any`, `any`, `any`\>[], `any`, `unknown`, [`AgentProduces`](../type-aliases/AgentProduces.md) \| `undefined`\>[]
70
71#### Parameters
72
73##### options
74
75`TextActivityOptionsWithContext`\<`TAdapter`, `TSchema`, `TStream`, `TTools`, `TInterrupts`, `TContext`, `TMiddleware`, `TAgents`\>
76
77#### Returns
78
79`TextActivityResult`\<`TSchema`, `TStream`, `TTools`\>
80
81#### Examples
82
83**Full agentic text (streaming with tools)**
84
85```ts
86import { chat } from '@tanstack/ai'
87import { openaiText } from '@tanstack/ai-openai'
88
89for await (const chunk of chat({
90 adapter: openaiText('gpt-5.5'),
91 messages: [{ role: 'user', content: 'What is the weather?' }],
92 tools: [weatherTool]
93})) {
94 if (chunk.type === 'TEXT_MESSAGE_CONTENT') {
95 console.log(chunk.delta)
96 }
97}
98```
99
100**One-shot text (streaming without tools)**
101
102```ts
103for await (const chunk of chat({
104 adapter: openaiText('gpt-5.5'),
105 messages: [{ role: 'user', content: 'Hello!' }]
106})) {
107 console.log(chunk)
108}
109```
110
111**Non-streaming text (stream: false)**
112
113```ts
114const { text, chunks } = await chat({
115 adapter: openaiText('gpt-5.5'),
116 messages: [{ role: 'user', content: 'Hello!' }],
117 stream: false
118})
119// text is a string with the full response
120// chunks is every chunk the run produced, in order
121```
122
123**Agentic structured output (tools + structured response)**
124
125```ts
126import { z } from 'zod'
127
128const result = await chat({
129 adapter: openaiText('gpt-5.5'),
130 messages: [{ role: 'user', content: 'Research and summarize the topic' }],
131 tools: [researchTool, analyzeTool],
132 outputSchema: z.object({
133 summary: z.string(),
134 keyPoints: z.array(z.string())
135 })
136})
137// result is { summary: string, keyPoints: string[] }
138```
139
140***
141
142### decide
143
144```ts
145decide: <TAdapter, TQuestions>(options) => Promise<{ [K in string | number | symbol]: InferEvaluateAnswer<TQuestions[K]> } & object>;
146```
147
148Defined in: [packages/ai/src/activities/chat/agents/bound.ts:110](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/agents/bound.ts#L110)
149
150Ask typed questions about `state` and get answers your code can branch on.
151
152You have state (a ticket, a record, a log) and you need typed answers, not
153prose. Pass questions built with `choice`, `score`, and `boolean`. Then
154branch on `result.queue.value` in ordinary TypeScript.
155
156The question key `meta` is reserved. Throws if `questions` is empty or uses
157that key.
158
159#### Type Parameters
160
161##### TAdapter
162
163`TAdapter` *extends* [`EvaluateAdapter`](EvaluateAdapter.md)\<`string`, `EvaluateProviderOptions`\<`TAdapter`\>\>
164
165##### TQuestions
166
167`TQuestions` *extends* `Record`\<`string`, [`WireQuestion`](../type-aliases/WireQuestion.md)\>
168
169#### Parameters
170
171##### options
172
173`EvaluateActivityOptions`\<`TAdapter`, `TQuestions`\>
174
175#### Returns
176
177`Promise`\<\{ \[K in string \| number \| symbol\]: InferEvaluateAnswer\<TQuestions\[K\]\> \} & `object`\>
178
179#### Example
180
181**Route a support ticket**
182
183```ts
184import { decide, choice, score, boolean } from '@tanstack/ai'
185import { typesafeDecider } from '@tanstack/ai-typesafe'
186
187const result = await decide({
188 adapter: typesafeDecider('jev-latest'),
189 state: ticket,
190 questions: {
191 queue: choice({
192 instructions: 'Which team should handle this ticket?',
193 options: {
194 billing: 'Payments, invoices, refunds',
195 tech: 'Bugs, outages, integrations',
196 sales: 'Pricing, upgrades, new accounts',
197 },
198 }),
199 urgency: score({
200 instructions: 'How urgent is this ticket?',
201 levels: ['low', 'medium', 'high'],
202 }),
203 refund: boolean({
204 instructions: 'Is the customer asking for a refund?',
205 }),
206 },
207})
208
209result.queue.value
210result.meta.model
211result.meta.usage
212```
213
214***
215
216### embed
217
218```ts
219embed: <TAdapter>(options) => Promise<EmbeddingResult>;
220```
221
222Defined in: [packages/ai/src/activities/chat/agents/bound.ts:108](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/agents/bound.ts#L108)
223
224Embed activity - generates embedding vectors from text and image inputs.
225
226Accepts a single item or an array of items; the result always carries an
227`embeddings` array with one vector per input item, in input order.
228
229#### Type Parameters
230
231##### TAdapter
232
233`TAdapter` *extends* [`EmbeddingAdapter`](EmbeddingAdapter.md)\<`string`, `any`, `any`, `any`\>
234
235#### Parameters
236
237##### options
238
239`EmbedOptions`\<`TAdapter`\>
240
241#### Returns
242
243`Promise`\<[`EmbeddingResult`](EmbeddingResult.md)\>
244
245#### Examples
246
247**Embed a single text**
248
249```ts
250import { embed } from '@tanstack/ai'
251import { openaiEmbedding } from '@tanstack/ai-openai'
252
253const result = await embed({
254 adapter: openaiEmbedding('text-embedding-3-small'),
255 input: 'a red guitar',
256})
257
258console.log(result.embeddings[0].vector)
259```
260
261**Batch with requested dimensions**
262
263```ts
264const result = await embed({
265 adapter: openaiEmbedding('text-embedding-3-large'),
266 input: ['a red guitar', 'a blue drum kit'],
267 dimensions: 1024,
268})
269```
270
271**Multimodal embedding (text + image fused into one vector)**
272
273```ts
274import { cohereEmbedding } from '@tanstack/ai-cohere'
275
276// A nested array of parts fuses them into a single vector. The outer array
277// is the item list, so this embeds one fused item into one vector.
278const result = await embed({
279 adapter: cohereEmbedding('embed-v4.0'),
280 input: [
281 [
282 { type: 'text', content: 'product photo' },
283 { type: 'image', source: { type: 'data', value: base64, mimeType: 'image/png' } },
284 ],
285 ],
286 modelOptions: { inputType: 'search_document' },
287})
288```
289
290***
291
292### generateAudio
293
294```ts
295generateAudio: <TAdapter, TStream>(options) => AudioActivityResult<TStream>;
296```
297
298Defined in: [packages/ai/src/activities/chat/agents/bound.ts:102](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/agents/bound.ts#L102)
299
300Audio generation activity - generates audio from text prompts.
301
302Uses AI models to create music, sound effects, and other audio content.
303
304#### Type Parameters
305
306##### TAdapter
307
308`TAdapter` *extends* [`AudioAdapter`](AudioAdapter.md)\<`string`, `AudioProviderOptions`\<`TAdapter`\>\>
309
310##### TStream
311
312`TStream` *extends* `boolean` = `false`
313
314#### Parameters
315
316##### options
317
318`AudioActivityOptions`\<`TAdapter`, `TStream`\>
319
320#### Returns
321
322`AudioActivityResult`\<`TStream`\>
323
324#### Example
325
326**Generate music from a prompt**
327
328```ts
329import { generateAudio } from '@tanstack/ai'
330import { falAudio } from '@tanstack/ai-fal'
331
332const result = await generateAudio({
333 adapter: falAudio('fal-ai/diffrhythm'),
334 prompt: 'An upbeat electronic track with synths',
335 duration: 10
336})
337
338console.log(result.audio.url) // URL to generated audio
339```
340
341***
342
343### generateImage
344
345```ts
346generateImage: <TAdapter, TStream>(options) => ImageActivityResult<TStream>;
347```
348
349Defined in: [packages/ai/src/activities/chat/agents/bound.ts:100](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/agents/bound.ts#L100)
350
351Image activity - generates images from text prompts.
352
353Uses AI image generation models to create images based on natural language descriptions.
354
355#### Type Parameters
356
357##### TAdapter
358
359`TAdapter` *extends* [`ImageAdapter`](ImageAdapter.md)\<`string`, `any`, `any`, `any`, [`ModelInputModalitiesByName`](../type-aliases/ModelInputModalitiesByName.md)\>
360
361##### TStream
362
363`TStream` *extends* `boolean` = `false`
364
365#### Parameters
366
367##### options
368
369`ImageActivityOptions`\<`TAdapter`, `TStream`\>
370
371#### Returns
372
373`ImageActivityResult`\<`TStream`\>
374
375#### Examples
376
377**Generate a single image**
378
379```ts
380import { generateImage } from '@tanstack/ai'
381import { openaiImage } from '@tanstack/ai-openai'
382
383const result = await generateImage({
384 adapter: openaiImage('dall-e-3'),
385 prompt: 'A serene mountain landscape at sunset'
386})
387
388console.log(result.images[0].url)
389```
390
391**Generate multiple images**
392
393```ts
394const result = await generateImage({
395 adapter: openaiImage('dall-e-2'),
396 prompt: 'A cute robot mascot',
397 numberOfImages: 4,
398 size: '512x512'
399})
400
401result.images.forEach((image, i) => {
402 console.log(`Image ${i + 1}: ${image.url}`)
403})
404```
405
406**With provider-specific options**
407
408```ts
409const result = await generateImage({
410 adapter: openaiImage('dall-e-3'),
411 prompt: 'A professional headshot photo',
412 size: '1024x1024',
413 modelOptions: {
414 quality: 'hd',
415 style: 'natural'
416 }
417})
418```
419
420***
421
422### generateLiveVideo
423
424```ts
425generateLiveVideo: <TAdapter, TStream>(options) => LiveVideoActivityResult<TStream>;
426```
427
428Defined in: [packages/ai/src/activities/chat/agents/bound.ts:107](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/agents/bound.ts#L107)
429
430**`Experimental`**
431
432Live generation activity - opens a live, prompt-steerable video session.
433
434#### Type Parameters
435
436##### TAdapter
437
438`TAdapter` *extends* [`LiveVideoAdapter`](LiveVideoAdapter.md)\<`string`, `LiveVideoProviderOptions`\<`TAdapter`\>\>
439
440##### TStream
441
442`TStream` *extends* `boolean` = `false`
443
444#### Parameters
445
446##### options
447
448`LiveVideoActivityOptions`\<`TAdapter`, `TStream`\>
449
450#### Returns
451
452`LiveVideoActivityResult`\<`TStream`\>
453
454#### Example
455
456**Mint a session token on the server**
457
458```ts
459import { generateLiveVideo } from '@tanstack/ai'
460import { reactorVideo } from '@tanstack/ai-reactor'
461
462const live = await generateLiveVideo({
463 adapter: reactorVideo('helios'),
464 prompt: 'A red sports car powerslides a mountain hairpin',
465})
466
467// Hand live.token, live.model, and live.prompt to the browser.
468```
469
470 Live generation is an experimental feature and may change.
471
472***
473
474### generateSpeech
475
476```ts
477generateSpeech: <TAdapter, TStream>(options) => TTSActivityResult<TStream>;
478```
479
480Defined in: [packages/ai/src/activities/chat/agents/bound.ts:103](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/agents/bound.ts#L103)
481
482TTS activity - generates speech from text.
483
484Uses AI text-to-speech models to create audio from natural language text.
485
486#### Type Parameters
487
488##### TAdapter
489
490`TAdapter` *extends* [`TTSAdapter`](TTSAdapter.md)\<`string`, `TTSProviderOptions`\<`TAdapter`\>\>
491
492##### TStream
493
494`TStream` *extends* `boolean` = `false`
495
496#### Parameters
497
498##### options
499
500`TTSActivityOptions`\<`TAdapter`, `TStream`\>
501
502#### Returns
503
504`TTSActivityResult`\<`TStream`\>
505
506#### Examples
507
508**Generate speech from text**
509
510```ts
511import { generateSpeech } from '@tanstack/ai'
512import { openaiSpeech } from '@tanstack/ai-openai'
513
514const result = await generateSpeech({
515 adapter: openaiSpeech('tts-1-hd'),
516 text: 'Hello, welcome to TanStack AI!',
517 voice: 'nova'
518})
519
520console.log(result.audio) // base64-encoded audio
521```
522
523**With format and speed options**
524
525```ts
526const result = await generateSpeech({
527 adapter: openaiSpeech('tts-1'),
528 text: 'This is slower speech.',
529 voice: 'alloy',
530 format: 'wav',
531 speed: 0.8
532})
533```
534
535***
536
537### generateTranscription
538
539```ts
540generateTranscription: <TAdapter, TStream>(options) => TranscriptionActivityResult<TStream>;
541```
542
543Defined in: [packages/ai/src/activities/chat/agents/bound.ts:105](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/agents/bound.ts#L105)
544
545Transcription activity - converts audio to text.
546
547Uses AI speech-to-text models to transcribe audio content.
548
549#### Type Parameters
550
551##### TAdapter
552
553`TAdapter` *extends* [`TranscriptionAdapter`](TranscriptionAdapter.md)\<`string`, `TranscriptionProviderOptions`\<`TAdapter`\>\>
554
555##### TStream
556
557`TStream` *extends* `boolean` = `false`
558
559#### Parameters
560
561##### options
562
563`TranscriptionActivityOptions`\<`TAdapter`, `TStream`\>
564
565#### Returns
566
567`TranscriptionActivityResult`\<`TStream`\>
568
569#### Examples
570
571**Transcribe an audio file**
572
573```ts
574import { generateTranscription } from '@tanstack/ai'
575import { openaiTranscription } from '@tanstack/ai-openai'
576
577const result = await generateTranscription({
578 adapter: openaiTranscription('whisper-1'),
579 audio: audioFile, // File, Blob, or base64 string
580 language: 'en'
581})
582
583console.log(result.text)
584```
585
586**With verbose output for timestamps**
587
588```ts
589const result = await generateTranscription({
590 adapter: openaiTranscription('whisper-1'),
591 audio: audioFile,
592 responseFormat: 'verbose_json'
593})
594
595result.segments?.forEach(segment => {
596 console.log(`[${segment.start}s - ${segment.end}s]: ${segment.text}`)
597})
598```
599
600**Streaming transcription result**
601
602```ts
603for await (const chunk of generateTranscription({
604 adapter: openaiTranscription('whisper-1'),
605 audio: audioFile,
606 stream: true
607})) {
608 console.log(chunk)
609}
610```
611
612***
613
614### generateVideo
615
616```ts
617generateVideo: <TAdapter, TStream>(options) => TStream extends true ? AsyncIterable<AGUIEvent, any, any> : Promise<VideoJobResult>;
618```
619
620Defined in: [packages/ai/src/activities/chat/agents/bound.ts:101](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/agents/bound.ts#L101)
621
622**`Experimental`**
623
624Generate video - creates a video generation job from a text prompt.
625
626Uses AI video generation models to create videos based on natural language descriptions.
627Unlike image generation, video generation is asynchronous and requires polling for completion.
628
629When `stream: true` is passed, handles the full job lifecycle automatically:
630create job → poll for status → stream updates → yield final result.
631
632 Video generation is an experimental feature and may change.
633
634#### Type Parameters
635
636##### TAdapter
637
638`TAdapter` *extends* [`VideoAdapter`](VideoAdapter.md)\<`string`, `any`, `any`, `any`, `any`, `any`\>
639
640##### TStream
641
642`TStream` *extends* `boolean` = `false`
643
644#### Parameters
645
646##### options
647
648`VideoCreateOptions`\<`TAdapter`, `TStream`\>
649
650#### Returns
651
652`TStream` *extends* `true` ? `AsyncIterable`\<[`AGUIEvent`](../type-aliases/AGUIEvent.md), `any`, `any`\> : `Promise`\<[`VideoJobResult`](VideoJobResult.md)\>
653
654#### Examples
655
656**Create a video generation job**
657
658```ts
659import { generateVideo, getVideoJobStatus } from '@tanstack/ai'
660import { openaiVideo } from '@tanstack/ai-openai'
661
662// Start a video generation job
663const { jobId } = await generateVideo({
664 adapter: openaiVideo('sora-2'),
665 prompt: 'A cat chasing a dog in a sunny park'
666})
667
668console.log('Job started:', jobId)
669
670// The submission only OPENS the run; the poll that sees a terminal state is
671// what completes it. The `jobId` is the whole correlation — pass the same
672// `middleware` and `threadId` when you use them.
673const status = await getVideoJobStatus({
674 adapter: openaiVideo('sora-2'),
675 jobId,
676})
677```
678
679**Stream the full video generation lifecycle**
680
681```ts
682import { generateVideo, toServerSentEventsResponse } from '@tanstack/ai'
683import { openaiVideo } from '@tanstack/ai-openai'
684
685const stream = generateVideo({
686 adapter: openaiVideo('sora-2'),
687 prompt: 'A cat chasing a dog in a sunny park',
688 stream: true,
689 pollingInterval: 3000,
690})
691
692return toServerSentEventsResponse(stream)
693```
694
695***
696
697### generateVoice
698
699```ts
700generateVoice: <TAdapter, TStream>(options) => VoiceActivityResult<TStream>;
701```
702
703Defined in: [packages/ai/src/activities/chat/agents/bound.ts:104](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/agents/bound.ts#L104)
704
705Voice activity - creates a reusable voice.
706
707Providers create voices in one of two ways, and some support both: design a
708new voice from a text description, or clone one from reference audio. Either
709way the result carries voice ids you pass back to `generateSpeech()`.
710
711#### Type Parameters
712
713##### TAdapter
714
715`TAdapter` *extends* [`VoiceAdapter`](VoiceAdapter.md)\<`string`, `VoiceProviderOptions`\<`TAdapter`\>\>
716
717##### TStream
718
719`TStream` *extends* `boolean` = `false`
720
721#### Parameters
722
723##### options
724
725`VoiceActivityOptions`\<`TAdapter`, `TStream`\>
726
727#### Returns
728
729`VoiceActivityResult`\<`TStream`\>
730
731#### Examples
732
733**Design a voice from a description**
734
735```ts
736import { generateVoice, generateSpeech } from '@tanstack/ai'
737import { elevenlabsVoiceDesign, elevenlabsSpeech } from '@tanstack/ai-elevenlabs'
738
739const designed = await generateVoice({
740 adapter: elevenlabsVoiceDesign('eleven_ttv_v3'),
741 prompt: 'A warm, gravelly narrator in his sixties with a slight Irish lilt',
742})
743
744const [preview] = designed.voices
745if (!preview) throw new Error('No voice candidates returned')
746
747const speech = await generateSpeech({
748 adapter: elevenlabsSpeech('eleven_v4'),
749 text: 'Once upon a time...',
750 voice: preview.voiceId,
751})
752```
753
754**Save the voice to the provider's library**
755
756```ts
757const saved = await generateVoice({
758 adapter: elevenlabsVoiceDesign('eleven_ttv_v3'),
759 prompt: 'A bright, upbeat product demo host',
760 name: 'Demo Host',
761 description: 'Bright, upbeat, mid-30s',
762})
763```
764
765***
766
767### generateWorld
768
769```ts
770generateWorld: <TAdapter, TStream>(options) => WorldActivityResult<TStream>;
771```
772
773Defined in: [packages/ai/src/activities/chat/agents/bound.ts:106](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/agents/bound.ts#L106)
774
775**`Experimental`**
776
777World generation activity. Live adapters mint a session token. Job
778adapters return a viewer URL or an in-progress operation id.
779
780#### Type Parameters
781
782##### TAdapter
783
784`TAdapter` *extends* [`WorldAdapter`](WorldAdapter.md)\<`string`, `WorldProviderOptions`\<`TAdapter`\>\>
785
786##### TStream
787
788`TStream` *extends* `boolean` = `false`
789
790#### Parameters
791
792##### options
793
794`WorldActivityOptions`\<`TAdapter`, `TStream`\>
795
796#### Returns
797
798`WorldActivityResult`\<`TStream`\>
799
800#### Example
801
802**Mint a session token on the server**
803
804```ts
805import { generateWorld } from '@tanstack/ai'
806import { reactorWorld } from '@tanstack/ai-reactor'
807
808const world = await generateWorld({
809 adapter: reactorWorld('visko-orbis-stable'),
810 prompt: 'A neon cyberpunk city at night, slow aerial drift',
811})
812
813// Hand world.token, world.model, and world.prompt to the browser.
814```
815
816 World generation is an experimental feature and may change.
817
818***
819
820### rerank
821
822```ts
823rerank: <TAdapter, TDocument>(options) => Promise<RerankResult<TDocument>>;
824```
825
826Defined in: [packages/ai/src/activities/chat/agents/bound.ts:109](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/agents/bound.ts#L109)
827
828Rerank activity - reorders documents by relevance to a query.
829
830#### Type Parameters
831
832##### TAdapter
833
834`TAdapter` *extends* [`RerankAdapter`](RerankAdapter.md)\<`string`, `RerankProviderOptions`\<`TAdapter`\>\>
835
836##### TDocument
837
838`TDocument` *extends* `string` \| `object` = `string`
839
840#### Parameters
841
842##### options
843
844`RerankActivityOptions`\<`TAdapter`, `TDocument`\>
845
846#### Returns
847
848`Promise`\<[`RerankResult`](RerankResult.md)\<`TDocument`\>\>
849
850#### Examples
851
852**Basic reranking**
853
854```ts
855import { rerank } from '@tanstack/ai'
856import { cohereRerank } from '@tanstack/ai-cohere'
857
858const { ranking, rerankedDocuments } = await rerank({
859 adapter: cohereRerank('rerank-v3.5'),
860 query: 'talk about rain',
861 documents: ['sunny day at the beach', 'rainy afternoon in the city'],
862 topN: 2,
863})
864
865console.log(rerankedDocuments[0]) // 'rainy afternoon in the city'
866```
867
868**Reranking object documents**
869
870```ts
871const { ranking } = await rerank({
872 adapter: cohereRerank('rerank-v3.5'),
873 query: 'best laptop for travel',
874 documents: [
875 { id: 1, text: 'A heavy gaming desktop' },
876 { id: 2, text: 'A lightweight ultrabook with all-day battery' },
877 ],
878})
879
880// ranking[0].document is the original object, fully typed.
881console.log(ranking[0].document.id)
882```
883
884***
885
886### summarize
887
888```ts
889summarize: <TAdapter, TStream>(options) => SummarizeActivityResult<TStream>;
890```
891
892Defined in: [packages/ai/src/activities/chat/agents/bound.ts:99](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/agents/bound.ts#L99)
893
894Summarize activity - generates summaries from text.
895
896Supports both streaming and non-streaming modes.
897
898#### Type Parameters
899
900##### TAdapter
901
902`TAdapter` *extends* [`SummarizeAdapter`](SummarizeAdapter.md)\<`string`, `object`\>
903
904##### TStream
905
906`TStream` *extends* `boolean` = `false`
907
908#### Parameters
909
910##### options
911
912`SummarizeActivityOptions`\<`TAdapter`, `TStream`\>
913
914#### Returns
915
916`SummarizeActivityResult`\<`TStream`\>
917
918#### Examples
919
920**Basic summarization**
921
922```ts
923import { summarize } from '@tanstack/ai'
924import { openaiSummarize } from '@tanstack/ai-openai'
925
926const result = await summarize({
927 adapter: openaiSummarize('gpt-4o-mini'),
928 text: 'Long article text here...'
929})
930
931console.log(result.summary)
932```
933
934**Summarization with style**
935
936```ts
937const result = await summarize({
938 adapter: openaiSummarize('gpt-4o-mini'),
939 text: 'Long article text here...',
940 style: 'bullet-points',
941 maxLength: 100
942})
943```
944
945**Focused summarization**
946
947```ts
948const result = await summarize({
949 adapter: openaiSummarize('gpt-4o-mini'),
950 text: 'Long technical document...',
951 focus: ['key findings', 'methodology']
952})
953```
954
955**Streaming summarization**
956
957```ts
958for await (const chunk of summarize({
959 adapter: openaiSummarize('gpt-4o-mini'),
960 text: 'Long article text here...',
961 stream: true
962})) {
963 if (chunk.type === 'content') {
964 process.stdout.write(chunk.delta)
965 }
966}
967```