Agent( )
Pattern
INT·Jun 26

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.

View Full Pattern on Desktop
Tool Context: experimental_context preview

Problems Solved

  • Keep user identity out of model-controlled tool inputs
  • Share a database or service handle across all tools
  • Scope tool execution to the authenticated request
  • Prevent prompt-injection from accessing other users' data

Use Cases

  • Per-user account assistants
  • Multi-tenant agent tools
  • Injecting DB/session into isolated tool calls
  • Secure identity scoping for agent tools

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 Pattern on Desktop
End of Pattern