Skip to main content
Like AOF? Give us a star!
If you find AOF useful, please star us on GitHub. It helps us reach more developers and grow the community.

Context Resource Reference

Complete reference for Context resource specifications. Contexts define execution environment boundaries with cluster configuration, approval requirements, and rate limits.

Overview

A Context represents an execution environment boundary that gets injected at runtime. Contexts enable:

  • Separating agent logic from deployment configuration
  • Multi-tenant deployments with isolated environments
  • Context-specific approval policies
  • Audit logging and rate limiting

Basic Structure

apiVersion: aof.dev/v1
kind: Context
metadata:
name: string # Required: Unique identifier
labels: # Optional: Key-value labels
key: value

spec:
kubeconfig: string # Optional: Path to kubeconfig
namespace: string # Optional: Kubernetes namespace
cluster: string # Optional: Cluster name
env: # Optional: Environment variables
KEY: value
approval: # Optional: Approval configuration
required: bool
allowed_users: [string]
audit: # Optional: Audit logging
enabled: bool
limits: # Optional: Rate limits
max_requests_per_minute: int

Spec Fields

Cluster Configuration

FieldTypeRequiredDescription
kubeconfigstringNoPath to kubeconfig file (supports ${VAR})
namespacestringNoDefault Kubernetes namespace
clusterstringNoCluster name for identification
working_dirstringNoWorking directory for tool execution

Example:

spec:
kubeconfig: ${KUBECONFIG_PROD}
namespace: production
cluster: prod-us-east-1
working_dir: /app

Environment Variables

Environment variables are made available to agents running in this context.

spec:
env:
AWS_PROFILE: production
AWS_REGION: us-east-1
LOG_LEVEL: info
CUSTOM_VAR: ${EXTERNAL_VAR} # Supports expansion

Auto-injected variables:

VariableDescription
AOF_CONTEXTContext name
AOF_NAMESPACEKubernetes namespace (if set)
AOF_CLUSTERCluster name (if set)

Approval Configuration

Control when and who can approve destructive operations.

spec.approval

FieldTypeDefaultDescription
requiredboolfalseEnable approval for destructive ops
allowed_usersarray[]Users who can approve (empty = anyone)
timeout_secondsint300Approval timeout (5 minutes)
require_forarray[]Patterns requiring approval (regex)
allow_self_approvalboolfalseAllow requestor to approve own commands
min_approversint1Minimum approvers required

Basic Approval

spec:
approval:
required: true
allowed_users:
- U12345678 # Slack user ID
- slack:U87654321 # Platform-prefixed ID
- telegram:123456 # Telegram user ID
timeout_seconds: 300

Pattern-Based Approval

Only require approval for specific commands:

spec:
approval:
required: true
require_for:
- "kubectl delete"
- "kubectl scale.*--replicas=0"
- "helm uninstall"
- "aws.*terminate"
allowed_users:
- U015SRELEAD

Multi-Approver Workflow

spec:
approval:
required: true
min_approvers: 2 # Requires 2 people to approve
allow_self_approval: false
allowed_users:
- U015ADMIN
- U016SRELEAD
- U017ONCALL

User ID Formats

Contexts support multiple user ID formats:

FormatExampleDescription
Raw IDU12345678Direct platform ID
Slack prefixedslack:U12345678Explicit Slack ID
Telegram prefixedtelegram:123456789Explicit Telegram ID
Discord prefixeddiscord:123456789012345678Explicit Discord ID

Audit Configuration

Log agent executions for compliance and debugging.

spec.audit

FieldTypeDefaultDescription
enabledboolfalseEnable audit logging
sinkstring-Audit sink URL
eventsarray[]Event types to audit
include_payloadboolfalseInclude full request/response
retentionstring-Retention period (e.g., "90d")

Audit Events

EventDescription
agent_startAgent execution started
agent_completeAgent execution completed
tool_callTool invocation
approval_requestedApproval requested
approval_grantedApproval granted
approval_deniedApproval denied
errorError occurred
allAll events

Example

spec:
audit:
enabled: true
sink: s3://company-audit-logs/aof/prod/
events:
- agent_start
- agent_complete
- tool_call
- approval_granted
- approval_denied
include_payload: false
retention: "90d"

Sink Formats

FormatExampleDescription
S3s3://bucket/prefix/AWS S3 bucket
Filefile:///var/log/aof/audit.logLocal file
HTTPhttps://audit.company.com/ingestHTTP endpoint
Stdoutstdout://Console output

Rate Limits

Protect resources and control costs.

spec.limits

FieldTypeDescription
max_requests_per_minuteintRequest rate limit
max_tokens_per_dayintDaily token limit
max_concurrentintMax parallel executions
max_execution_time_secondsintPer-request timeout
max_cost_per_dayfloatDaily cost limit (credits)

Example

spec:
limits:
max_requests_per_minute: 60
max_tokens_per_day: 1000000
max_concurrent: 5
max_execution_time_seconds: 300
max_cost_per_day: 50.00

Secret References

Reference external secrets for credentials.

spec:
secrets:
- name: aws-credentials
key: access-key-id
env_var: AWS_ACCESS_KEY_ID
- name: aws-credentials
key: secret-access-key
env_var: AWS_SECRET_ACCESS_KEY
FieldTypeRequiredDescription
namestringYesSecret name
keystringNoSpecific key in secret
env_varstringNoEnvironment variable to set

Complete Examples

Production Context

apiVersion: aof.dev/v1
kind: Context
metadata:
name: prod
labels:
environment: production
team: platform
spec:
kubeconfig: ${KUBECONFIG_PROD}
namespace: production
cluster: prod-us-east-1

env:
AWS_PROFILE: production
AWS_REGION: us-east-1
LOG_LEVEL: warn

approval:
required: true
require_for:
- "kubectl delete"
- "kubectl scale"
- "helm uninstall"
- "aws.*terminate"
allowed_users:
- U015SRELEAD
- U016ADMIN
timeout_seconds: 300
allow_self_approval: false

audit:
enabled: true
sink: s3://company-audit/prod/
events: [all]
retention: "365d"

limits:
max_requests_per_minute: 30
max_concurrent: 3
max_execution_time_seconds: 600

Staging Context

apiVersion: aof.dev/v1
kind: Context
metadata:
name: staging
labels:
environment: staging
spec:
kubeconfig: ${KUBECONFIG_STAGING}
namespace: staging
cluster: staging-us-east-1

env:
AWS_PROFILE: staging
LOG_LEVEL: debug

# No approval required for staging
approval:
required: false

limits:
max_requests_per_minute: 100
max_concurrent: 10

Development Context

apiVersion: aof.dev/v1
kind: Context
metadata:
name: dev
spec:
namespace: default

env:
LOG_LEVEL: debug
DEV_MODE: "true"

# No restrictions for development

Multi-Tenant Customer Context

apiVersion: aof.dev/v1
kind: Context
metadata:
name: customer-acme
labels:
tenant: acme
tier: enterprise
spec:
namespace: tenant-acme

env:
TENANT_ID: acme
TENANT_TIER: enterprise

approval:
required: true
allowed_users:
- acme-admin@acme.com

limits:
max_requests_per_minute: 100
max_tokens_per_day: 5000000
max_cost_per_day: 100.00

audit:
enabled: true
sink: s3://acme-audit-logs/aof/

Environment Variable Expansion

Context values support ${VAR_NAME} expansion:

spec:
kubeconfig: ${KUBECONFIG_PROD} # Expanded at runtime
env:
API_KEY: ${EXTERNAL_API_KEY} # Expanded at runtime
STATIC_VALUE: "not-expanded" # Used as-is

Expansion order:

  1. System environment variables
  2. Context env values (can reference system vars)
  3. Auto-injected AOF variables

Validation

# Validate context YAML
aofctl validate -f context.yaml

# List loaded contexts
aofctl get contexts

# Describe specific context
aofctl describe context prod

Validation Rules

  • Name is required
  • min_approvers must be >= 1
  • max_concurrent must be > 0
  • Approval patterns must be valid regex

Usage with AgentFlow

Contexts are referenced in AgentFlow specs:

# contexts/prod.yaml
apiVersion: aof.dev/v1
kind: Context
metadata:
name: prod
spec:
namespace: production
approval:
required: true

---
# flows/k8s-flow.yaml
apiVersion: aof.dev/v1
kind: AgentFlow
metadata:
name: k8s-ops-flow
spec:
context:
ref: prod # Reference to Context
nodes:
- id: execute
type: Agent
config:
agent: k8s-agent
connections:
- from: start
to: execute

See Also