Skip to content

Contexts & Authorization

AGBoss strictly separates domain state (DTOs carried in the Path Scope and persisted in checkpoints) from runtime identity and metadata (injected via three hierarchical context classes). Exactly three context tokens exist — ApplicationContext, TenantContext, and ExecutionContext — forming a parent-linked chain inspired by Spring’s context hierarchy.

How the three context levels are structured

Section titled “How the three context levels are structured”

Each level links upward to its parent, so a component injecting ExecutionContext can reach executionContext.tenant and executionContext.tenant.application, and ApplicationContext.environment provides typed access to the application’s environment contract:

Context Class Lifecycle Scope Key Properties Typical Consumers
ApplicationContext Singleton per booted App instance name, version, instanceId, startedAt, environmentName, environment, host (hostname, pid, platform, runtimeVersion) Startup @Injectable services, @Budget (Application scope), observers
TenantContext Per organization / tenant tenantId ("default" when omitted), weight (positive integer for fair @ModelProvider queuing), application, plus custom subclass fields @Budget (Tenant scope), tenant-aware services
ExecutionContext Per workflow execution pass executionId, threadId, ownerId, tenant, signal (AbortSignal), workflow, step (nodeId, visitNumber, idempotencyKey, callId, itemIndex, copyNumber) @Tool, @Action, @Router, @Arbiter, @Judge, @InputGuardrail, @OutputGuardrail, @Channel

Compiler diagnostic [context.prompt-unused]: Because TenantContext and ExecutionContext fields are supplied by your server caller (app.execute(Start, input, { tenant, execution })) and never generated by an LLM, their @Text(), @Integer(), or @OneOf() decorators must omit prompt ([context.prompt-unused]).

How tenantId and ownerId authorization protects threads and pauses

Section titled “How tenantId and ownerId authorization protects threads and pauses”

When an execution starts with tenant: { tenantId: "acme" } and ownerId: "user-42", AGBoss records ownership on the thread and every pause record:

  • Cross-tenant isolation: Calling app.execute, app.resume, or app.cancel with a mismatched tenantId throws UnauthorizedExecutionAccessError and fires OnExecutionRejected before loading any checkpoint state.
  • Owner vs. channel responder: A user-owned thread (ownerId) can only be continued or cancelled by that ownerId, while out-of-process @Channel approvals record answeredBy in the audit trail.