From 1826a84aa5cdab94986869833b12c369c41b1792 Mon Sep 17 00:00:00 2001 From: Nico Albanese Date: Mon, 4 Nov 2024 11:01:32 +0000 Subject: [PATCH] docs: add multi-step usechat note --- .../03-ai-sdk-core/15-tools-and-tool-calling.mdx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/content/docs/03-ai-sdk-core/15-tools-and-tool-calling.mdx b/content/docs/03-ai-sdk-core/15-tools-and-tool-calling.mdx index ca1d21b30ab6..e81572adb12d 100644 --- a/content/docs/03-ai-sdk-core/15-tools-and-tool-calling.mdx +++ b/content/docs/03-ai-sdk-core/15-tools-and-tool-calling.mdx @@ -96,6 +96,22 @@ const { text, steps } = await generateText({ You can use `streamText` in a similar way. +## Multi-Step Calls with `useChat` + +To access multi-step calls on the client with [ `useChat` ](/docs/reference/ai-sdk-ui/use-chat), you should set `maxSteps` within the `useChat` options rather than within the `generateText` or `streamText` call. This will allow you to access all steps in callbacks like `onToolCall` and `onFinish`. + +```tsx highlight="2" +const { messages } = useChat({ + maxSteps: 3, + onFinish: message => { + // access message from each step + }, + onToolCall: ({ toolCall }) => { + // access tool call from each step + }, +}); +``` + ### Steps To access intermediate tool calls and results, you can use the `steps` property in the result object