Request Context
Copy page
Pass dynamic context to your agents via HTTP headers for personalized interactions
Overview
Request context allows you to pass request-specific values (like user IDs, authentication tokens, or organization metadata) to your agent graph at runtime via HTTP headers. These values are validated, cached per conversation, and made available throughout your agent system for:
- Context Fetchers: Dynamic data retrieval based on request values
- External Tools: Authentication and personalization for API calls
- Agent Prompts: Personalized responses using context variables
Passing request context via headers
Include context values as HTTP headers when calling your agent API. These headers are validated against your configured schema and cached for the conversation.
Header keys are normalized to lowercase. Define them as lowercase in your schema and reference them as lowercase in templates.
Configuring request context
Define a schema for your request context and configure how it's used in your agent graph.
How it works
Validation: Headers are validated against your configured schema when a request arrives
Caching: Validated context is cached per conversation for reuse across multiple interactions
Reuse: Subsequent requests with the same conversationId
automatically use cached context values
Updates: Provide new header values to update the context for an ongoing conversation
Context values persist across conversation turns. To update them, send new header values with the same conversation ID.
Using request context in your agents
Request context values are available throughout your agent system using template syntax {{requestContext.field_name}}
:
In Context Fetchers
Use request values to fetch dynamic data from external APIs:
In Agent Prompts
Reference context directly in agent prompts for personalization:
In External Tools
Configure external agents or MCP servers with dynamic headers:
Best practices
- Use lowercase keys: Always define schema properties in lowercase and reference them as lowercase in templates
- Validate early: Test your schema configuration with sample headers before deploying
- Cache wisely: Remember that context persists per conversation - design accordingly
- Secure sensitive data: For long-lived secrets, use the Credentials system instead of request context
- Keep it minimal: Only include context values that are actually needed by your agents
Common use cases
Multi-tenant applications
Pass tenant-specific configuration to customize agent behavior per customer:
User authentication
Provide user identity and session information for personalized interactions:
API gateway integration
Forward headers from your API gateway for consistent authentication:
Troubleshooting
Invalid request context errors
If you receive a 400 error about invalid request context:
- Verify your schema matches the headers you're sending
- Ensure all header keys are lowercase
- Check that required fields are present
- Validate the data types match your schema
Context not persisting
If context values aren't available in subsequent requests:
- Ensure you're using the same
conversationId
across requests - Verify headers are being sent correctly
- Check that your context config is properly attached to the graph
Related documentation
- Context Fetchers - Learn about fetching and caching external data
- External Agents - Configure external agent integrations
- Credentials - Manage secure credentials for your agents