- User Tokens - Issued by your identity provider (OIDC/OAuth) for human users accessing the platform
- Context Tokens - Generated programmatically for agents to access resources with limited permissions during a conversation
Understanding the Permission System
Agent Stack’s permission system has two independent dimensions that work together:- Privacy and Ownership - Controls who can access resources (user roles and entity visibility)
- Context Scoping - Controls where resources are associated and how agents access them
Privacy and Ownership
This determines who can access and manage resources based on entity type and user role.Entity Types
Platform Entities - Shared across all users in the platform:| Entity | Description |
|---|---|
| system_configuration | Platform-wide configuration |
| model_providers | Available LLM/embedding model providers |
| Entity | Description |
|---|---|
| files | Uploaded files and documents |
| vector_stores | Vector databases for embeddings |
| variables | User-specific variables |
| contexts | Conversation contexts |
| context_data | Context history and data |
| feedback | User feedback submissions |
| Entity | Description |
|---|---|
| providers | Agent providers |
| provider_builds | Agent provider builds |
User Roles and Access
Agent Stack uses three role-based access levels: USER - Standard user role:- Platform Entities: Read-only access
- User-Private Entities: Full read/write access to their own resources
- Semi-Private Entities: Read-only access (can view all providers/builds but cannot manage them).
- All USER permissions
- Semi-Private Entities: Can create and manage their own providers and provider builds
- Full access to all resources across the platform
Context Scoping and Agent Access
This dimension controls where resources are associated and how agents access them through context tokens. A context represents a single conversation with an agent. Resources can be associated with either:- User level (not tied to any specific conversation)
- Context level (linked to a specific conversation)
Context-Scopeable Resources
These resources can be associated with either the user level or a specific context:- files: Can be user-level (not associated with any context) or context-associated (linked to a specific context)
- vector_stores: Can be user-level or context-associated
- context_data: Conversation history (always associated with a context)
Context Permissions for Agents
When agents interact with resources, they use context tokens with limited permissions. You can grant specific permissions for each resource type:Available Permissions
| Resource | Available Operations | Context Scopeable | Description |
|---|---|---|---|
| files | read, write, extract, * | ✔︎ | User files and documents |
| vector_stores | read, write, * | ✔︎ | Vector databases for embeddings |
| context_data | read, write, * | ✔︎ | Conversation history |
| llm | * | LLM inference services | |
| embeddings | * | Embedding generation services | |
| a2a_proxy | * | Agent-to-agent communication | |
| model_providers | read, write, * | Model provider management | |
| variables | read, write, * | User variables | |
| providers | read, write, * | Agent providers | |
| contexts | read, write, * | Context management | |
| connectors | read, write, proxy, * | External service connectors | |
| feedback | write | User feedback submissions |
Global vs. Local Permission Grants
When generating a context token, you specify two independent permission sets that control what the token can access:Global Permissions
Grants the token access to ALL user resources, regardless of which context they’re associated with. What the token can access:- All user-level files and vector stores (not associated with any context)
- Files and vector stores associated with ANY context (including other contexts)
- Agent needs to search across all user files from previous conversations
- Agent needs to access a shared knowledge base (user-level vector store)
- Agent creates persistent resources that should be accessible to other contexts
Context Permissions (Local)
Grants the token access ONLY to resources associated with this specific context. What the token can access:- Files and vector stores associated with this specific context
- Context data (conversation history) for this context
- A restricted surface area - only resources linked to this conversation
- Sandboxed agent that should only see files uploaded in this conversation
- Limiting agent access to prevent data leakage across conversations
- Working with conversation-specific temporary data
Creating Context Tokens
Context tokens allow agents to authenticate with limited permissions. Here’s the flow:Generating a Context Token
Here is an example how you can create a context and generate a custom token with specific permissions:Important Notes
- Context tokens cannot be used to generate other tokens
- The permissions you grant must be a subset of your own permissions
- Context token expiration is 20 minutes. If an agent runs longer it must request a new token using
AuthRequireda2a message.
Using Context Tokens in Agent Runs
When calling an agent using the Agent Stack SDK, you pass the context token through extension configurations. Here’s a complete example:Full Agent Run Client Example
Inside Your Agent
When you declare thePlatformApiExtensionServer in your agent function, the Agent Stack SDK automatically authenticates your platform API calls using the context token that was passed through the extension metadata.
How it works
- The client passes the context token via
PlatformApiExtensionClient.api_auth_metadata() - The
PlatformApiExtensionServerreceives the token and sets up the authentication context - All
File,VectorStore, and other platform API calls automatically use this token - By default, context-scopeable resources are associated with the context (via
context_id="auto")
Resource Scoping with context_id
When creating context-scopeable resources (files, vector stores) using the SDK, the context_id parameter determines whether they are scoped globally (user-level) or locally (context-level).
The auto Parameter
Both File.create() and VectorStore.create() include a context_id parameter with special "auto" behavior.
context_id="auto"(default) - Automatically scopes the resource to the current context if used inside an agent with activePlatformApiExtensioncontext_id=None- Scopes the resource globally (outside the context)context_id=specific_context_id- Scopes the resource explicitly to the context ID passed in
Advanced: API Authentication
The Agent Stack platform API accepts two types of tokens for authentication:- Access Token - Issued by your identity provider (OIDC/OAuth) when a user logs in
- Context Token - Generated programmatically for agents with limited permissions
Authorization: Bearer {token} header for all
API endpoints. However, as you may have noticed in the example above, you would use A2A extensions to send context
token to the agent. The agent will then use the context token in the Bearer authorization header
to authenticate itself with the platform API, this is abstracted away in the SDK.
To make this crystal clear, let’s break down the full low-level interaction with an agent that wants to upload a file.
We will use the square brackets [] to denote the Authorization: Bearer header and placeholders
ACCESS_TOKEN and CONTEXT_TOKEN for the user access token and context token, respectively.
Part 1: Client code:
1
OAuth flow
Execute the Authorization code flow or similar to obtain an ACCESS_TOKEN from the identity
provider (in this flow, the user will log in to the system with their credentials).
2
Create Context token
Create a context token with specific permissions, these are 2 API requests:
- Create a context:
POST /api/v1/contexts[ACCESS_TOKEN] - Create context token:
POST /api/v1/contexts/{context_id}/token[ACCESS_TOKEN]. The body contains a request forfiles.writecontext permission grant.
3
Prepare agent message
- Fulfill extension demands and configure message metadata, add CONTEXT_TOKEN to:
- LLM and embedding fulfillments
- PlatformApiExtensionClient
- Set
context_idto associate the message with the context and token created in previous step
4
Call Agent
Send message to the agent:
POST /api/v1/a2a/{provider_id} [ACCESS_TOKEN].Proxy request authorizationThe request header contains ACCESS_TOKEN to authorize user.
This token is consumed by the platform API (a2a proxy endpoint) and not forwarded to the agent.Extension payloadThe request body contains the CONTEXT_TOKEN that the agent receives and can use later to call
the Platform API.
1
Agent card configuration
The agent requests the platform API extension using dependency injection:
2
Receive context token
When the agent is invoked through the A2A protocol, the
PlatformApiExtensionServer will consume the
CONTEXT_TOKEN from the extension metadata and set up the authentication context.3
Upload file
In your agent code you will use the
File.create() method to upload a file to the context. The method will
call POST /api/v1/files?context_id={context_id} [CONTEXT_TOKEN].Using the “auto” behavior of
File.create, the file will be uploaded to the context by specifying
the context_id query parameter. This ID is taken from the user message payload.The SDK will automatically attach the CONTEXT_TOKEN to the request header. The token must contain the
files.write context permission grant for this to work.At no point did Agent receive or use
ACCESS_TOKEN. This is on purpose, because based on user role this token
can possess destructive permissions - to delete other agents, read all user data (if the user is ADMIN, etc.).To prevent API misuse by untrusted agents, avoid passing the access token to the agent.