Skip to content

Commit b32c141

Browse files
authored
feat (ai): add array support to stopWhen (#6339)
## Background When an additional stop condition such as `hasToolCall` is used, it makes sense to still keep a step limit condition in case the additional condition is never met to prevent infinite loops. ## Summary Add support for multiple stop conditions passed as an array with `or` semantics. When any stop condition is met, the multi-step loop is aborted. ## Tasks - [x] implementation - [x] add tests - [x] changeset update - [x] jsdoc - [x] extract
1 parent 9315076 commit b32c141

File tree

8 files changed

+1665
-1143
lines changed

8 files changed

+1665
-1143
lines changed

.changeset/chatty-steaks-search.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+
feat (ai): add array support to stopWhen

packages/ai/core/generate-text/__snapshots__/generate-text.test.ts.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`options.maxSteps > 2 steps: initial, tool-result > onStepFinish should be called for each step 1`] = `
3+
exports[`options.stopWhen > 2 steps: initial, tool-result > onStepFinish should be called for each step 1`] = `
44
[
55
DefaultStepResult {
66
"content": [
@@ -133,7 +133,7 @@ exports[`options.maxSteps > 2 steps: initial, tool-result > onStepFinish should
133133
]
134134
`;
135135

136-
exports[`options.maxSteps > 2 steps: initial, tool-result > result.response.messages should contain response messages from all steps 1`] = `
136+
exports[`options.stopWhen > 2 steps: initial, tool-result > result.response.messages should contain response messages from all steps 1`] = `
137137
[
138138
{
139139
"content": [
@@ -171,7 +171,7 @@ exports[`options.maxSteps > 2 steps: initial, tool-result > result.response.mess
171171
]
172172
`;
173173

174-
exports[`options.maxSteps > 2 steps: initial, tool-result > result.steps should contain all steps 1`] = `
174+
exports[`options.stopWhen > 2 steps: initial, tool-result > result.steps should contain all steps 1`] = `
175175
[
176176
DefaultStepResult {
177177
"content": [
@@ -304,7 +304,7 @@ exports[`options.maxSteps > 2 steps: initial, tool-result > result.steps should
304304
]
305305
`;
306306

307-
exports[`options.maxSteps > 2 steps: initial, tool-result with prepareStep > onStepFinish should be called for each step 1`] = `
307+
exports[`options.stopWhen > 2 steps: initial, tool-result with prepareStep > onStepFinish should be called for each step 1`] = `
308308
[
309309
DefaultStepResult {
310310
"content": [
@@ -437,7 +437,7 @@ exports[`options.maxSteps > 2 steps: initial, tool-result with prepareStep > onS
437437
]
438438
`;
439439

440-
exports[`options.maxSteps > 2 steps: initial, tool-result with prepareStep > result.response.messages should contain response messages from all steps 1`] = `
440+
exports[`options.stopWhen > 2 steps: initial, tool-result with prepareStep > result.response.messages should contain response messages from all steps 1`] = `
441441
[
442442
{
443443
"content": [
@@ -475,7 +475,7 @@ exports[`options.maxSteps > 2 steps: initial, tool-result with prepareStep > res
475475
]
476476
`;
477477

478-
exports[`options.maxSteps > 2 steps: initial, tool-result with prepareStep > result.steps should contain all steps 1`] = `
478+
exports[`options.stopWhen > 2 steps: initial, tool-result with prepareStep > result.steps should contain all steps 1`] = `
479479
[
480480
DefaultStepResult {
481481
"content": [

0 commit comments

Comments
 (0)