Skip to content

Commit c03cafe

Browse files
authored
chore (core, ui): rename maxAutomaticRoundtrips to maxToolRoundtrips (#1799)
1 parent 2047f10 commit c03cafe

File tree

13 files changed

+51
-33
lines changed

13 files changed

+51
-33
lines changed

‎.changeset/mean-shrimps-lie.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'ai': patch
3+
---
4+
5+
chore (core, ui): rename maxAutomaticRoundtrips to maxToolRoundtrips

‎content/docs/05-ai-sdk-ui/03-chatbot-with-tool-calling.mdx‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ The tool result contains all information about the tool call as well as the resu
3939

4040
<Note>
4141
In order to automatically send another request to the server when all tool
42-
calls are server-side, you need to set `maxAutomaticRoundtrips` to a value
43-
greater than 0 in the `useChat` options. It is disabled by default for
44-
backward compatibility.
42+
calls are server-side, you need to set `maxToolRoundtrips` to a value greater
43+
than 0 in the `useChat` options. It is disabled by default for backward
44+
compatibility.
4545
</Note>
4646

4747
## Example
@@ -115,7 +115,7 @@ There are three things worth mentioning:
115115
It asks the user for confirmation and displays the result once the user confirms or denies the execution.
116116
The result is added to the chat using `addToolResult`.
117117

118-
1. The `maxAutomaticRoundtrips` option is set to 5.
118+
1. The `maxToolRoundtrips` option is set to 5.
119119
This enables several tool use iterations between the client and the server.
120120

121121
```tsx filename='app/page.tsx'
@@ -127,7 +127,7 @@ import { Message, useChat } from 'ai/react';
127127
export default function Chat() {
128128
const { messages, input, handleInputChange, handleSubmit, addToolResult } =
129129
useChat({
130-
maxAutomaticRoundtrips: 5,
130+
maxToolRoundtrips: 5,
131131

132132
// run client-side tools that are automatically executed:
133133
async onToolCall({ toolCall }) {

‎content/docs/07-reference/ai-sdk-core/01-generate-text.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ const result = await generateText({
320320
'An optional abort signal that can be used to cancel the call.',
321321
},
322322
{
323-
name: 'maxAutomaticRoundtrips',
323+
name: 'maxToolRoundtrips',
324324
type: 'number',
325325
isOptional: true,
326326
description:

‎content/docs/07-reference/ai-sdk-ui/01-use-chat.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Allows you to easily create a conversational user interface for your chatbot app
105105
"An optional boolean that determines whether to send extra fields you've added to `messages`. Defaults to `false` and only the `content` and `role` fields will be sent to the API endpoint.",
106106
},
107107
{
108-
name: 'maxAutomaticRoundtrips',
108+
name: 'maxToolRoundtrips',
109109
type: 'number',
110110
description:
111111
'React only. Maximal number of automatic roundtrips for tool calls. An automatic tool call roundtrip is a call to the server with the tool call results when all tool calls in the last assistant message have results. A maximum number is required to prevent infinite loops in the case of misconfigured tools. By default, it is set to 0, which will disable the feature.',

‎content/examples/02-next-pages/tools/render-interface-during-tool-call.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export default function Chat() {
4848
const { messages, input, handleInputChange, handleSubmit, addToolResult } =
4949
useChat({
5050
api: '/api/use-chat-tools-ui',
51-
experimental_maxAutomaticRoundtrips: 5,
51+
maxToolRoundtrips: 5,
5252

5353
// run client-side tools that are automatically executed:
5454
async onToolCall({ toolCall }) {

‎content/examples/03-node/03-tools/05-call-tools-with-automatic-roundtrips.mdx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ description: Learn how to call tools with automatic roundtrips in a Node.js appl
88
Models call tools to gather information or perform actions that are not directly available to the model.
99
When tool results are available, the model can use them to generate another response.
1010

11-
You can enable automatic roundtrips in `generateText` by setting the `maxAutomaticRoundtrips` option to
11+
You can enable automatic roundtrips in `generateText` by setting the `maxToolRoundtrips` option to
1212
a number greater than 0.
1313
This option specifies the maximum number of automatic roundtrips that can be made to prevent infinite loops.
1414

@@ -19,7 +19,7 @@ import { z } from 'zod'
1919

2020
const { text } = await generateText({
2121
model: openai('gpt-4-turbo'),
22-
maxAutomaticRoundtrips: 5
22+
maxToolRoundtrips: 5
2323
tools: {
2424
weather: tool({
2525
description: 'Get the weather in a location',

‎examples/ai-core/src/complex/math-agent/agent.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async function main() {
4141
}),
4242
},
4343
toolChoice: 'required',
44-
maxAutomaticRoundtrips: 10,
44+
maxToolRoundtrips: 10,
4545
});
4646
}
4747

‎examples/ai-core/src/generate-text/google-vertex-tool-call.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ async function main() {
2424
},
2525
}),
2626
},
27-
maxAutomaticRoundtrips: 5,
27+
maxToolRoundtrips: 5,
2828
});
2929

3030
console.log(text);

‎examples/next-openai-pages/pages/use-chat-tools-ui.tsx‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default function Chat() {
55
const { messages, input, handleInputChange, handleSubmit, addToolResult } =
66
useChat({
77
api: '/api/use-chat-tools-ui',
8-
experimental_maxAutomaticRoundtrips: 5,
8+
maxAutomaticRoundtrips: 5,
99

1010
// run client-side tools that are automatically executed:
1111
async onToolCall({ toolCall }) {
@@ -22,9 +22,9 @@ export default function Chat() {
2222
});
2323

2424
return (
25-
<div className="flex flex-col w-full max-w-md py-24 mx-auto stretch gap-4">
25+
<div className="flex flex-col w-full max-w-md gap-4 py-24 mx-auto stretch">
2626
{messages?.map((m: Message) => (
27-
<div key={m.id} className="whitespace-pre-wrap flex flex-col gap-1">
27+
<div key={m.id} className="flex flex-col gap-1 whitespace-pre-wrap">
2828
<strong>{`${m.role}: `}</strong>
2929
{m.content}
3030
{m.toolInvocations?.map((toolInvocation: ToolInvocation) => {
@@ -35,7 +35,7 @@ export default function Chat() {
3535
return (
3636
<div
3737
key={toolCallId}
38-
className="text-gray-500 flex flex-col gap-2"
38+
className="flex flex-col gap-2 text-gray-500"
3939
>
4040
{toolInvocation.args.message}
4141
<div className="flex gap-2">
@@ -79,15 +79,15 @@ export default function Chat() {
7979
key={toolCallId}
8080
className="flex flex-col gap-2 p-4 bg-blue-400 rounded-lg"
8181
>
82-
<div className="flex flex-row justify-between items-center">
83-
<div className="text-4xl text-blue-50 font-medium">
82+
<div className="flex flex-row items-center justify-between">
83+
<div className="text-4xl font-medium text-blue-50">
8484
{toolInvocation.result.value}°
8585
{toolInvocation.result.unit === 'celsius' ? 'C' : 'F'}
8686
</div>
8787

88-
<div className="h-9 w-9 bg-amber-400 rounded-full flex-shrink-0" />
88+
<div className="flex-shrink-0 rounded-full h-9 w-9 bg-amber-400" />
8989
</div>
90-
<div className="flex flex-row gap-2 text-blue-50 justify-between">
90+
<div className="flex flex-row justify-between gap-2 text-blue-50">
9191
{toolInvocation.result.weeklyForecast.map(
9292
(forecast: any) => (
9393
<div
@@ -104,7 +104,7 @@ export default function Chat() {
104104
) : toolInvocation.toolName === 'getLocation' ? (
105105
<div
106106
key={toolCallId}
107-
className="text-gray-500 bg-gray-100 rounded-lg p-4"
107+
className="p-4 text-gray-500 bg-gray-100 rounded-lg"
108108
>
109109
User is in {toolInvocation.result}.
110110
</div>

‎examples/next-openai/app/use-chat-tools/page.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default function Chat() {
77
const { messages, input, handleInputChange, handleSubmit, addToolResult } =
88
useChat({
99
api: '/api/use-chat-tools',
10-
maxAutomaticRoundtrips: 5,
10+
maxToolRoundtrips: 5,
1111

1212
// run client-side tools that are automatically executed:
1313
async onToolCall({ toolCall }) {

0 commit comments

Comments
 (0)