Skip to content

feat(ai): add experimental_context parameter to prepareStep callback#10171

Merged
lgrammel merged 2 commits intovercel:mainfrom
gdaybrice:feat/experimental-context-prepare-step
Dec 10, 2025
Merged

feat(ai): add experimental_context parameter to prepareStep callback#10171
lgrammel merged 2 commits intovercel:mainfrom
gdaybrice:feat/experimental-context-prepare-step

Conversation

@gdaybrice
Copy link
Copy Markdown
Contributor

@gdaybrice gdaybrice commented Nov 12, 2025

Background

experimental_context is only available in tool execution but not in the prepareStep callback. This prevents developers from using context data (like user session info or auth state) when making step-specific decisions in multi-step workflows.

Summary

Added experimental_context as an optional parameter to the prepareStep callback.

Manual Verification

Tested with both generateText and streamText.

Checklist

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

@ghost ghost added the ai/core core functions like generateText, streamText, etc. Provider utils, and provider spec. label Nov 12, 2025
@gdaybrice
Copy link
Copy Markdown
Contributor Author

Closing for #9682

@gdaybrice gdaybrice closed this Nov 12, 2025
@rogercbe
Copy link
Copy Markdown

Any change to reconsider this PR?

#9682 is not really an alternative since the options cannot be changed (as far as I know) in the tools execution.

Also, options is not available (yet?) on the prepareStep either.

I think it would be very convenient to have the context available on the prepareStep arguments. In our use case, we have a tool that delegates/handoffs to an agent and setting the agentId on the context and the prepareStep would retrieve the necesary tools for that agent and set the system/activeTools for the specific agent.

Can we reconsider this? Or is there a recommended alternative to achieve this?

@gdaybrice
Copy link
Copy Markdown
Contributor Author

Any chance this can be merged please? I'm happy to make any changes if required.

@lgrammel lgrammel merged commit bbdcb81 into vercel:main Dec 10, 2025
17 of 18 checks passed
lgrammel added a commit that referenced this pull request Dec 10, 2025
## Background

Similar to modifying messages, model, etc. it would be useful to be able
to modify the experimental context for each step.

## Summary

* improve jsdoc of `PrepareStepFunction` and `PrepareStepResult`
* allow modification of `experimental_context` in `prepareStep`

## Related Issues

Builds on #10171
Resolves #10482
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/core core functions like generateText, streamText, etc. Provider utils, and provider spec.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants