Skip to content

feat(ai): add generic type to experimental_context#13102

Draft
lgrammel wants to merge 34 commits intomainfrom
lg/GJysF7Eo
Draft

feat(ai): add generic type to experimental_context#13102
lgrammel wants to merge 34 commits intomainfrom
lg/GJysF7Eo

Conversation

@lgrammel
Copy link
Copy Markdown
Collaborator

@lgrammel lgrammel commented Mar 5, 2026

Background

experimental_context for tools and step preparation was introduced in an earlier release without typing (type: unknown). Before marking context as stable, it should support smart generic typing for usage in tools, prepareStep, and telemetry.

Summary

Introduce generics on experimental_context. Each tool has a contextSchema for the tool-specific context. The context on the AI function call is a union of the tool contexts and can have additional properties for prepareStep and telemetry.

Limitations

The experimental_context setting is optional even when a context is needed, i.e. it will not throw type validation errors unless a context is specified.

Manual Verification

  • run and check types on examples/ai-functions/src/generate-text/openai/tool-call-with-context.ts
  • streamText
  • agent

Tasks

  • prototype generic context and tool context merging
  • investigate type errors
  • implement generateText
  • implement streamText
  • implement agent / tool loop agent
  • figure out support in provider-defined tools
  • add type tests
  • add jsdoc
  • documentation
  • remove prototypes
  • better name for ExpandedContext
  • changeset

Future Work

  • mark experimental_context stable
  • add sanitizeContext function
  • add tool context wrapper for name mapping and safety
  • add context to StopCondition
  • move ToolSet into provider-utils package
  • investigate how to fix context optionality limitation

Related Issues

@tigent tigent bot added ai/core core functions like generateText, streamText, etc. Provider utils, and provider spec. ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label feature New feature or request labels Mar 5, 2026
lgrammel added 2 commits March 5, 2026 17:18
This reverts commit 50c741f.
@lgrammel lgrammel changed the title 1 feat(ai): generic context Mar 9, 2026
@lgrammel lgrammel changed the title feat(ai): generic context feat(ai): add generic type to experimental_context Apr 1, 2026
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. ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant