Documentation / @agentick/kernel / KernelContext
Interface: KernelContext ​
Defined in: kernel/src/context.ts:171
Execution context that flows through all async operations via AsyncLocalStorage.
The KernelContext contains all state needed during execution:
- Identity and tracing (requestId, traceId, user)
- Event buses (events, executionHandle)
- Cancellation (signal)
- Communication (channels)
- Execution tracking (procedureGraph, procedurePid, origin)
- Extensible storage (metadata, metrics)
Access the current context with Context.get() from anywhere in your code - no need to pass it explicitly through function calls.
Examples ​
const ctx = Context.create({
user: { id: 'user-1' },
metadata: { conversationId: 'conv-123' }
});
await Context.run(ctx, async () => {
// Context is available here and in all async calls
const current = Context.get();
console.log(current.user?.id); // 'user-1'
});interface AppContext extends KernelContext {
customHandle?: MyCustomHandle;
appMetadata: AppSpecificMetadata;
}See ​
- Context - Static methods to create/access context
- UserContext - User information structure
Properties ​
[KERNEL_CONTEXT_SYMBOL]? ​
optional[KERNEL_CONTEXT_SYMBOL]:boolean
Defined in: kernel/src/context.ts:260
Type brand for context detection
channels? ​
optionalchannels:ChannelServiceInterface
Defined in: kernel/src/context.ts:193
Channel service for bidirectional communication (optional). Injected by Engine when channels are configured. Tools and components can access channels via this service.
events ​
events:
EventEmitter
Defined in: kernel/src/context.ts:183
Global request event bus for subscribing to all events
executionHandle? ​
optionalexecutionHandle:EventEmitter<any>
Defined in: kernel/src/context.ts:187
Operation-specific event emitter (from .withHandle())
executionId? ​
optionalexecutionId:string
Defined in: kernel/src/context.ts:222
Current execution ID. Set when entering an execution boundary. All procedures within this execution share this ID.
executionType? ​
optionalexecutionType:string
Defined in: kernel/src/context.ts:228
Type of execution at this boundary (e.g., 'engine', 'model', 'component_tool', 'fork', 'spawn'). Only meaningful at execution boundaries.
metadata ​
metadata:
ContextMetadata
Defined in: kernel/src/context.ts:179
Application-specific metadata
metrics ​
metrics:
ContextMetrics
Defined in: kernel/src/context.ts:181
Accumulated execution metrics
middleware? ​
optionalmiddleware:object
Defined in: kernel/src/context.ts:253
Middleware registry for procedure execution. Procedures read this at execution time to get instance-level middleware. Typically set by createApp() from the Agentick instance.
getMiddlewareFor() ​
getMiddlewareFor(
procedureName):Middleware[]
Parameters ​
procedureName ​
string
Returns ​
origin? ​
optionalorigin:ProcedureNode
Defined in: kernel/src/context.ts:210
Origin procedure node - the root procedure that initiated this execution chain. Undefined for the root procedure itself (since it IS the origin). Set automatically by ExecutionTracker when procedures are executed.
parentExecutionId? ​
optionalparentExecutionId:string
Defined in: kernel/src/context.ts:234
Parent execution ID for nested executions (e.g., component_tool called from engine). Enables DevTools to show execution hierarchy.
procedureGraph? ​
optionalprocedureGraph:ProcedureGraph
Defined in: kernel/src/context.ts:198
Procedure graph for tracking procedure execution hierarchy. Automatically initialized when first procedure is executed.
procedureNode? ​
optionalprocedureNode:ProcedureNode
Defined in: kernel/src/context.ts:204
Current procedure node in the graph
procedurePid? ​
optionalprocedurePid:string
Defined in: kernel/src/context.ts:202
Current procedure PID (for tracking nested procedures).
requestId ​
requestId:
string
Defined in: kernel/src/context.ts:173
Unique identifier for this request/execution
sessionId? ​
optionalsessionId:string
Defined in: kernel/src/context.ts:240
Session ID (set by session's runWithContext). Available during all session execution — tool calls, transformCompiled, etc.
signal? ​
optionalsignal:AbortSignal
Defined in: kernel/src/context.ts:185
Abort signal for cooperative cancellation
tick? ​
optionaltick:number
Defined in: kernel/src/context.ts:246
Current tick number (set by engine during tick loop). Enables events to include tick context for correlation.
traceId ​
traceId:
string
Defined in: kernel/src/context.ts:175
Correlation ID for distributed tracing
user? ​
optionaluser:UserContext
Defined in: kernel/src/context.ts:177
User information (from auth)