Repository navigation
fix(sdk): use accumulated responseMessages in retainStepMessages for AI SDK 7 #5101
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,8 @@ export type SteeringInjection = { | |
| type StepInput = { | ||
| messages: ModelMessage[]; | ||
| steps: Array<{ response: { messages: ModelMessage[] } }>; | ||
| /** AI SDK 7+: response messages accumulated across all steps so far. */ | ||
| responseMessages?: ModelMessage[]; | ||
| }; | ||
|
|
||
| /** | ||
|
|
@@ -41,7 +43,7 @@ export function retainStepMessages<T extends StepInput, R extends { messages?: M | |
| retainedFrom = undefined; | ||
| responseCount = 0; | ||
| } | ||
| const responses = input.steps.at(-1)?.response.messages ?? []; | ||
| const responses = input.responseMessages ?? input.steps.at(-1)?.response.messages ?? []; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Missing release note for SDK fix This customer-facing Learn moreThe SDK is a published package, and this change fixes a failure customers can encounter when a conversation uses multiple tool steps. The repository requires a changeset for user-facing package bug fixes. None is included in this PR. Example: A customer upgrades to the release containing this change to fix missing tool results. The package changelog gives them no notice that the fix is available. Recommended fix: Add a patch changeset for Was this helpful? React with 👍 or 👎 to provide feedback.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔍 Compaction rebuild retains the old response source The separate chatCompact rebuild still slices per-step responses by a cumulative count. Compaction-enabled AI SDK 7 agents can therefore lose later tool results despite this retention fix. Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| if (retainedFrom) { | ||
| responseCount += alreadyIncluded(retainedFrom, responses.slice(responseCount)); | ||
| retainedFrom = undefined; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Missing regression comment on new test
The new
retainStepMessagestest lacks the required// Catches: <bug>comment identifying the regression it protects.Learn more
Repository testing guidance requires every new unit test to identify its distinct regression in a one-line
// Catches: <bug>comment. This test exercises loss of later tool results after a prepare-step message override, but it does not include that comment.Example: A future maintainer reading this test sees a three-step scenario without the mandatory comment explaining that the regression is dropped tool results after step two.
Recommended fix: Place a
// Catches: AI SDK 7 dropping tool results after the second step when prepareStep returns messages.comment directly above this test.Was this helpful? React with 👍 or 👎 to provide feedback.