Identity
AI agents that act on behalf of users need secure identity and authorization mechanisms to access external services like GitHub, Gmail, Kaggle, or enterprise APIs. This section describes the identity strategy for Agent Runtimes.
Overview
Agent identity is more complex than traditional application identity because:
- Delegation: Agents act on behalf of users, requiring clear authorization chains
- Multi-service access: A single agent may need tokens for GitHub, Gmail, Slack, and more
- Dynamic tool discovery: Agents discover MCP servers at runtime, requiring dynamic credential management
- Autonomy vs. control: Balancing agent autonomy with user oversight and consent
- Programmatic execution: OAuth tokens must flow securely to skill scripts and codemode execution
┌─────────────────────────────────────────────────────────────────────┐
│ User (Resource Owner) │
└──────────────────────────────────────── ─────────────────────────────┘
│
OAuth 2.1 Authorization
▼
┌─────────────────────────────────────────────────────────────────────┐
│ Agent Runtimes Server │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────────┐ │
│ │ Token Manager │ │ Agent Context │ │ Tool Executors │ │
│ │ (OAuth flows) │ │ (User identity)│ │ (Token injection) │ │
│ └────────┬────────┘ └────────┬────────┘ └──────────┬──────────┘ │
└───────────┼───── ───────────────┼───────────────────────┼────────────┘
│ │ │
▼ ▼ ▼
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ GitHub │ │ Gmail │ │ Skills & │
│ API │ │ API │ │ Code Mode │
└──────────────┘ └──────────────┘ └──────────────┘
Identity Types
Type 1: User-Delegated Access (OAuth 2.1)
Use case: Agent accesses user's GitHub repositories, Gmail, or other personal services.
The agent acts as an OAuth client, obtaining tokens that represent the user's delegated authorization. This follows the standard OAuth 2.1 authorization code flow with PKCE (Proof Key for Code Exchange).
Based on the agent identity landscape, there are different approaches depending on your trust model:
| Scenario | Recommended Approach | Agent Runtimes Support |
|---|---|---|
| Public agents (internet-facing) | PKCE + DCR | ✅ Both implemented |
| Internal agents (within org) | SPIFFE/SPIRE | 🔜 Planned |
| Service-to-service | Client Credentials | ✅ Conceptual support |
The implementation provides:
- PKCE for secure authorization code flows with public clients
- DCR (Dynamic Client Registration) for agents that discover OAuth providers at runtime
- Identity Context for automatic token injection into skill script execution
# User initiates OAuth flow through the UI
# Agent receives delegated access token
agent_context = AgentContext(
user_id="user-123",
oauth_tokens={
"github": GitHubToken(access_token="gho_...", scopes=["repo", "read:user"]),
"gmail": GmailToken(access_token="ya29...", scopes=["gmail.readonly"]),
}
)
# Agent tools use these tokens
@agent.tool
async def list_repos(ctx: RunContext[AgentContext]) -> list[dict]:
token = ctx.deps.oauth_tokens["github"]
async with httpx.AsyncClient() as client:
response = await client.get(
"https://api.github.com/user/repos",
headers={"Authorization": f"Bearer {token.access_token}"}
)
return response.json()
Type 2: MCP Server Authentication
Use case: Agent connects to an MCP server that requires OAuth authentication (e.g., Kaggle MCP).
MCP servers follow the MCP Authorization Specification based on OAuth 2.1.
{
"mcpServers": {
"kaggle": {
"url": "https://www.kaggle.com/mcp",
"auth": {
"type": "oauth2",
"clientId": "your-client-id",
"scopes": ["datasets:read", "notebooks:execute"]
}
}
}
}
When the agent invokes a Kaggle MCP tool, the runtime:
- Checks if a valid token exists for this user + MCP server
- If not, initiates OAuth flow (user sees consent screen)
- Stores the token securely
- Attaches token to MCP requests
Type 3: Agent-to-Agent Communication (SPIFFE/SPIRE)
Use case: Internal agents communicating within your organization's infrastructure.
For workload-to-workload identity within a trust domain, use SPIFFE (Secure Production Identity Framework for Everyone):
from agent_runtimes.identity import SPIFFEIdentity
# Agent obtains its SVID (SPIFFE Verifiable Identity Document)
identity = SPIFFEIdentity()
svid = await identity.get_x509_svid()
# Use SVID for mutual TLS with other agents
async with identity.create_secure_channel("spiffe://acme.com/agents/data-processor") as channel:
response = await channel.request({"action": "process_data", "payload": data})
SPIFFE provides:
- Automatic identity: No static credentials—workloads receive short-lived certificates
- Zero-trust: Every request is authenticated via mutual TLS
- Cross-platform: Works with Kubernetes, VMs, bare metal
Type 4: Service Account Access
Use case: Agent accesses backend services using application-level credentials.
For server-to-server communication where no user is involved, use the OAuth 2.1 Client Credentials flow:
from agent_runtimes.identity import ServiceCredentials
# Configure service account
service = ServiceCredentials(
client_id=os.getenv("ANALYTICS_CLIENT_ID"),
client_secret=os.getenv("ANALYTICS_CLIENT_SECRET"),
token_endpoint="https://auth.example.com/oauth/token",
scopes=["analytics:read"]
)
# Agent uses service token (auto-refreshed)
@agent.tool
async def get_metrics(ctx: RunContext) -> dict:
token = await service.get_token()
# Use token for API calls
Provider Setup Guides
This section provides step-by-step instructions for setting up identity with common providers.
Kaggle
Kaggle provides access to datasets, models, competitions, and notebooks. Unlike GitHub, Kaggle does not offer public OAuth app registration, so Agent Runtimes uses token-based authentication.
Kaggle uses two authentication methods:
- MCP OAuth — Handled automatically by
mcp-remote(browser-based login on first tool call) - API Token — Manual token for Agent Runtimes identity integration
For the Agent Runtimes UI identity features, use the API Token method described below.
Step 1: Generate Your Kaggle API Token
- Go to kaggle.com/settings/account
- Scroll down to the API section
- Click Create New Token
- A file
kaggle.jsonwill download containing your credentials:{"username":"your-username","key":"your-api-key"} - The
keyvalue is yourKAGGLE_TOKEN
- Never commit your token to version control
- The token provides full access to your Kaggle account
- You can revoke and regenerate tokens anytime from the settings page
Step 2: Connect via the UI
The Agent Runtimes UI provides a built-in flow for connecting Kaggle:
- Open the Agent Configuration panel
- Find the "Connected Accounts" section — This section always appears and shows available identity providers
- Click "Connect Kaggle" — The card expands to show a token input form
- Click "Get API Key" — Opens kaggle.com/settings/account in a new tab
- Paste your API key from
kaggle.jsoninto the input field - Press Enter or click "Connect" — The token is securely stored in your browser's localStorage
┌─────────────────────────────────────────────────────────┐
│ Connected Accounts │