Skip to main content

context.identities

Request-scoped identity context for passing OAuth tokens to skill execution.

This module provides a context variable to store OAuth identities during request processing, allowing skill executors to access tokens without threading them through all the pydantic-ai layers.

Usage: ```python # In the transport layer (vercel_ai.py): from agent_runtimes.context.identities import set_request_identities, clear_request_identities

async def handle_vercel_request(self, request: Request):
identities = body.get("identities")
set_request_identities(identities)
try:
# Process request...
finally:
clear_request_identities()

# In skill executor or toolset:
from agent_runtimes.context.identities import get_identity_env

env = get_identity_env() # Returns {"GITHUB_TOKEN": "...", ...}
```

set_request_user_jwt

def set_request_user_jwt(token: str | None) -> None

Set the authenticated user JWT for the current request context.

get_request_user_jwt

def get_request_user_jwt() -> str | None

Get the authenticated user JWT for the current request context.

clear_request_user_jwt

def clear_request_user_jwt() -> None

Clear the user JWT for the current request context.

set_request_identities

def set_request_identities(identities: list[dict[str, Any]] | None) -> None

Set the identities for the current request context.

Arguments:

  • identities - List of identity objects with provider and accessToken.

get_request_identities

def get_request_identities() -> list[dict[str, Any]] | None

Get the identities for the current request context.

Returns:

List of identity objects, or None if not set.

clear_request_identities

def clear_request_identities() -> None

Clear the identities for the current request context.

get_identity_env

def get_identity_env() -> dict[str, str]

Get environment variables for identities in the current request context.

Maps OAuth identities to their corresponding environment variable names:

  • github -> GITHUB_TOKEN
  • gitlab -> GITLAB_TOKEN
  • google -> GOOGLE_ACCESS_TOKEN
  • microsoft -> AZURE_ACCESS_TOKEN

Returns:

Dictionary of environment variable names to token values.

IdentityContextManager Objects

class IdentityContextManager()

Context manager for setting identities during request processing.

Usage: async with IdentityContextManager(identities): # Process request...