Agent( )

Pattern

Tool Context: experimental_context

Inject request-scoped context (user identity, database handles, session) into ToolLoopAgent tools via experimental_context, so the model never supplies sensitive identity in tool inputs.

IntermediateJun 2026View the full pattern on desktop
Tool Context: experimental_context preview

Problems solved

  • Keep user identity out of model-controlled tool inputs
  • Share database or service handles across tools via experimental_context
  • Scope tool execution to the authenticated request
  • Reduce prompt-injection risk around cross-user data access

Use cases

  • Per-user account assistants
  • Multi-tenant agent tools
  • Injecting DB or session into isolated tool calls
  • Identity-scoped agent backends

AI SDK APIs

ToolLoopAgentexperimental_contexttoolstepCountIsgateway

Tags

aiagentsexperimental-contexttool-contextsecurityauthtool-loop-agentai-sdkagent-api

Requirements

Node.js
24+
Memory
512MB
Other
  • OpenAI API key

Environment variables

External services

openai

Ready to use?

View the full interactive pattern with live preview and copy the source code.

View the pattern on desktop

Related patterns