Skip to content

エージェントランタイム

Commander の心臓部である実行エンジンです。AgentRuntime は単一エージェントのライフサイクル全体を管理します。LLM 呼び出し、ツール実行、検証、チェックポイント、再試行 — すべて設定可能なトークン・ステップ予算の中で。

構造

AgentRuntime.execute(ctx)

  ├─ acquireSlot()        ← 同時実行セマフォ
  ├─ [Tenant check]       ← rate limit + 同時実行クォータ
  ├─ resolve storage      ← テナントスコープのメモリ + キャッシュ

  ├─ [Retry loop: 0..maxRetries]
  │   ├─ callWithTimeout()       ← LLM プロバイダー
  │   ├─ [Tool execution loop]
  │   │   ├─ planner.plan()      ← 依存関係を意識した計画
  │   │   ├─ executeTool()       ← StepErrorBoundary → tool.execute()
  │   │   └─ cache.set()
  │   ├─ verification.check()    ← 5 品質ゲート
  │   └─ checkpoint()            ← atomic 保存

  ├─ releaseSlot()
  └─ flush traces + samples

メインループ

  1. スロット取得 — 最大同時 run を超えない
  2. テナント検証 — rate limit・同時実行クォータ
  3. LLM 呼び出し — タイムアウト設定可
  4. ツール実行ToolPlanner が依存を解析し並列可能なものを同時実行
  5. 検証 — 5 ゲート失敗時は再試行
  6. チェックポイント — 各ステップで atomic 永続化
  7. トレーシング — 実行トレースと LLM サンプルを flush

主要コンポーネント

コンポーネントファイル役割
AgentRuntimeruntime/agentRuntime.tsメインループ
ToolPlannerruntime/toolPlanner.ts依存関係付きツール計画
ToolOrchestratorruntime/toolOrchestrator.ts計画の実行
StepErrorBoundaryruntime/stepErrorBoundary.tsステップ単位 skip/retry/abort
StepTimeoutManagerruntime/stepTimeoutManager.tsステップタイムアウト
ContextCompactorruntime/contextCompactor.tsトークン意識の圧縮
ContextWindowruntime/contextWindow.tsスライディングウィンドウ
TokenGovernorruntime/tokenGovernor.tsトークン予算
CycleDetectorruntime/cycleDetector.ts無限ループ検出
ToolOutputManagerruntime/toolOutputManager.tsツール出力の予算管理

設定

typescript
interface AgentRuntimeConfig {
  maxStepsPerRun: number;
  maxRetries: number;
  timeoutMs: number;
  maxConcurrency: number;
  budgetHardCapTokens: number;
}

実行計画

ツールは LLM 応答順そのままでありません。独立ツールは並列、依存ツールは前提の後に順次。循環依存は実行前に検出します。

関連

MIT — マルチエージェント編成のために。