Skip to content

Agent Runtime

The execution engine at the heart of Commander. The AgentRuntime manages the full lifecycle of a single agent: LLM calls, tool execution, verification, checkpointing, and retry — all within configurable token and step budgets.

Architecture

AgentRuntime.execute(ctx)

  ├─ acquireSlot()        ← Concurrency semaphore
  ├─ [Tenant check]       ← Rate limit + concurrency quota
  ├─ resolve storage      ← Tenant-scoped memory + caching

  ├─ [Retry loop: 0..maxRetries]
  │   ├─ callWithTimeout()       ← LLM provider call
  │   ├─ [Tool execution loop]
  │   │   ├─ planner.plan()      ← Dependency-aware execution plan
  │   │   ├─ executeTool()       ← StepErrorBoundary → tool.execute()
  │   │   └─ cache.set()         ← Cache result
  │   ├─ verification.check()    ← 5 quality gates
  │   └─ checkpoint()            ← Atomic save

  ├─ releaseSlot()
  └─ flush traces + samples

Main Loop

Each agent run follows this sequence:

  1. Slot acquisition — A concurrency semaphore prevents exceeding max concurrent runs
  2. Tenant validation — Rate limits and concurrency quotas are checked per tenant
  3. LLM call — The provider is called with a configurable timeout
  4. Tool execution — The LLM's tool requests are executed. The ToolPlanner builds a dependency-aware execution plan so parallelizable tools run concurrently
  5. Verification — The output passes through a 5-gate verification pipeline. If it fails, the runtime retries
  6. Checkpointing — State is persisted atomically at every step for crash recovery
  7. Tracing — Execution traces and LLM samples are flushed to persistent stores

Key Components

ComponentFilePurpose
AgentRuntimeruntime/agentRuntime.tsMain execution loop
ToolPlannerruntime/toolPlanner.tsDependency-aware tool execution plan
ToolOrchestratorruntime/toolOrchestrator.tsExecutes planned tool calls
StepErrorBoundaryruntime/stepErrorBoundary.tsPer-step recovery: skip, retry, or abort
StepTimeoutManagerruntime/stepTimeoutManager.tsPer-step timeout enforcement
ContextCompactorruntime/contextCompactor.tsToken-aware message compaction
ContextWindowruntime/contextWindow.tsSliding window context management
TokenGovernorruntime/tokenGovernor.tsToken budget enforcement
CycleDetectorruntime/cycleDetector.tsLoop detection to prevent infinite execution
ToolOutputManagerruntime/toolOutputManager.tsToken-budgeted tool output management

Configuration

typescript
interface AgentRuntimeConfig {
  maxStepsPerRun: number;      // Max LLM→tool cycles per run
  maxRetries: number;          // Max verification retries
  timeoutMs: number;           // Per-LLM-call timeout
  maxConcurrency: number;      // Max concurrent agent runs
  budgetHardCapTokens: number; // Absolute token ceiling
}

Execution Plan

Tools are not executed in LLM response order. The ToolPlanner analyzes dependencies between tool calls and produces a parallel-aware execution plan:

  • Independent tools execute concurrently
  • Dependent tools execute sequentially after their prerequisites
  • The plan is validated before any tool runs, catching circular dependencies early

MIT Licensed — Built for multi-agent orchestration.