Skip to content

feat: add request.messages to StepResult#15052

Merged
lgrammel merged 15 commits into
mainfrom
lg/Zo19e5t
May 6, 2026
Merged

feat: add request.messages to StepResult#15052
lgrammel merged 15 commits into
mainfrom
lg/Zo19e5t

Conversation

@lgrammel
Copy link
Copy Markdown
Collaborator

@lgrammel lgrammel commented May 6, 2026

Background

Accessing the input messages for a particular step can help with compaction, e.g. when you want to continue compacted messages in prepareStep.

Summary

Add request.messages to StepResult.

Example

In prepareStep, you can access the input messages from the last step via steps.at(-1).request.messages

Future Work

  • add include.requestSteps flag
  • limit response.messages on StepResult to only the messages from that step
  • add inputMessages, responseMessages to prepareStep params
  • change usage of messages response from prepareStep (continue using those messages)
  • implement support in WorkflowAgent @gr2m
  • add compaction example to examples and documentation

Related Issues

Relates to #9631 and #6615

@lgrammel lgrammel changed the title Lg/zo19e5t feat: add request.messages to StepResult May 6, 2026
@lgrammel lgrammel marked this pull request as ready for review May 6, 2026 14:45
Copy link
Copy Markdown
Collaborator

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

Looks good, but there are some test failures: https://github.com/vercel/ai/actions/runs/25442150126/job/74636080596?pr=15052

Should we add an example in examples/ai-functions/src/agent where we add some simple compaction logic based on this? that way we have a reference in the repo we can run for testing (and adjust in the future if/when we add a primitive for compaction).

@lgrammel
Copy link
Copy Markdown
Collaborator Author

lgrammel commented May 6, 2026

@felixarntz was holding off on the compaction example until all the planned changes land. at the end the compaction example will be much simpler than just adding it now

@lgrammel lgrammel enabled auto-merge (squash) May 6, 2026 15:31
@lgrammel lgrammel merged commit 79b2468 into main May 6, 2026
19 checks passed
@lgrammel lgrammel deleted the lg/Zo19e5t branch May 6, 2026 15:36
lgrammel added a commit that referenced this pull request May 6, 2026
…e storage opt-in (#15057)

## Background

Storing the request messages on each step can lead to memory issues,
similar to storing the request and response body. See #12126

## Summary

* make `request.messages` optional
* add an `include.requestMessages` option for opting into keeping them
for each step (default false)

## Related Issues
Similar to #12126
Builds on #15052
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

🚀 Published in:

Package Version
ai 7.0.0-canary.122
@ai-sdk/angular 3.0.0-canary.122
@ai-sdk/azure 4.0.0-canary.50
@ai-sdk/google 4.0.0-canary.54
@ai-sdk/google-vertex 5.0.0-canary.73
@ai-sdk/langchain 3.0.0-canary.122
@ai-sdk/llamaindex 3.0.0-canary.122
@ai-sdk/openai 4.0.0-canary.50
@ai-sdk/otel 1.0.0-canary.68
@ai-sdk/react 4.0.0-canary.122
@ai-sdk/rsc 3.0.0-canary.123
@ai-sdk/svelte 5.0.0-canary.122
@ai-sdk/vue 4.0.0-canary.122
@ai-sdk/workflow 1.0.0-canary.37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants