Runtime Configuration
The ExecutionRuntime is AgentKit's production-grade execution engine. Every action call flows through a pipeline of safety and observability layers:
ExecutionRuntime
Create a runtime by passing a PolicyEngine and an optional configuration object:
ExecutionConfig Reference
| Option | Type | Default | Description |
|---|---|---|---|
maxRetries | number | 2 | Maximum retry attempts on transient failures |
retryDelayMs | number | 200 | Base delay before first retry (exponential backoff: delay * 2^(attempt-1)) |
defaultTimeoutMs | number | undefined | Global timeout for all actions (overridden by per-call timeoutMs) |
noRetryHighRiskWrites | boolean | true | Skip retries for non-read actions to prevent duplicate state changes |
validateOutput | boolean | true | Validate action output against zodOutputSchema or outputSchema |
logger | RuntimeLogger | consoleLogger | Structured JSON logger |
metrics | RuntimeMetrics | NoopRuntimeMetrics | Metrics collector |
idempotencyStore | IdempotencyStore | InMemoryIdempotencyStore | Idempotency backend |
idempotencyTtlSeconds | number | 3600 | TTL for idempotency entries |
hooks | ExecutionHooks | undefined | Lifecycle callbacks |
ExecutionResult
Every runtime.run() call returns a typed result:
Policy Engine
The PolicyEngine evaluates four checks before allowing an action to execute:
- Network allowlist -- is the request's network in
allowedNetworks? - Action network support -- does the action support this network?
- Write permissions -- if
writeEnabledis false, all non-read actions are blocked - Risk level gate -- does the action's risk exceed
maxRiskWithoutConfirmwithout explicit confirmation?
Risk Level Hierarchy
If maxRiskWithoutConfirm is set to 'low', any action with risk medium or high requires { confirmed: true } in the execution options.
Actions with requiresConfirmation: true always need confirmation regardless of the policy setting.
Policy Blocked Result
Idempotency
Idempotency prevents duplicate execution when the same action is retried with the same key. AgentKit supports two backends:
Environment-Based Factory
You can also configure the store via environment variables:
Using Idempotency Keys
Pass an idempotencyKey in the execution options:
The Redis backend uses atomic SET NX for lock acquisition and a Lua script for safe lock release, preventing race conditions in distributed deployments.
Retries and Timeouts
Retry Behavior
- Uses exponential backoff:
retryDelayMs * 2^(attempt - 1) - Non-retryable errors (validation, policy, not-found, aborted) break immediately
- When
noRetryHighRiskWritesis true (default), non-read actions skip retries entirely
Per-Action Timeout
Timeout uses Promise.race and aborts the action's signal on expiry.
Prometheus Metrics
AgentKit has built-in Prometheus metrics support:
Exported Metrics
| Metric | Type | Labels | Description |
|---|---|---|---|
agentkit_runtime_counter_total | counter | metric, action, code | Success/error counts per action |
agentkit_runtime_histogram_count | gauge | metric, action | Request count per action |
agentkit_runtime_histogram_avg | gauge | metric, action | Average latency in ms |
agentkit_runtime_histogram_max | gauge | metric, action | Maximum latency in ms |
Internal counter names: runtime.success, runtime.error, runtime.idempotency_hit
Internal histogram name: runtime.latency_ms
Execution Hooks
Hooks provide observation callbacks for every stage of action execution. They are ideal for logging, alerting, and audit trails.
Hook Event Types
| Hook | Event Fields |
|---|---|
onActionStart | traceId, action, attempt, input, timestamp |
onActionSuccess | traceId, action, attempt, output, durationMs, timestamp |
onActionError | traceId, action, attempts, errorCode, errorMessage, durationMs, timestamp |
onPolicyBlocked | traceId, action, reason, timestamp |
Actions with sensitiveOutputFields automatically redact those fields from the output in onActionSuccess events. The original unredacted output is still returned in the ExecutionResult.
Error Codes
All runtime errors use structured error codes:
| Code | Description | Retryable? |
|---|---|---|
INVALID_INPUT | Zod/JSON Schema validation failed | No |
INVALID_OUTPUT | Output validation failed | No |
POLICY_BLOCKED | Policy engine rejected the action | No |
ACTION_NOT_FOUND | Action name not registered | No |
ABORTED | Operation cancelled via AbortSignal | No |
ADAPTER_REQUEST_FAILED | HTTP adapter request failed | Yes |
WALLET_SIGN_FAILED | Wallet signing operation failed | Yes |
WALLET_TRANSFER_FAILED | Wallet transfer operation failed | Yes |
TIMEOUT | Action exceeded timeout | Yes |
IDEMPOTENCY_CONFLICT | Another execution in progress for this key | Yes |
INTERNAL_ERROR | Unexpected error | Yes |
Structured Logging
The default consoleLogger outputs structured JSON logs:
You can provide a custom logger implementing the RuntimeLogger interface: