Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add multi-step usechat suggestion #3467

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions content/docs/03-ai-sdk-core/15-tools-and-tool-calling.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,22 @@ const { text, steps } = await generateText({

<Note>You can use `streamText` in a similar way.</Note>

## 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
},
});
```
Comment on lines +99 to +113
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm they need to work in combination. Server side roundtrips have many advantages.


### Steps

To access intermediate tool calls and results, you can use the `steps` property in the result object
Expand Down
Loading