summaryrefslogtreecommitdiffhomepage
path: root/packages/kernel/src/contracts/dispatch.ts
blob: c2914cf79ac1178b457dfaa8430b0a9e39b35a7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
 * Dispatch policy — controls how the kernel runs a step's tool calls.
 *
 * Two orthogonal axes, split so every combination is coherent:
 * - `maxConcurrent`: how many tools run at once (0=unlimited, 1=sequential, 2+=cap)
 * - `eager`: when execution starts (true=on arrival, false=after step finishes)
 *
 * The policy is a kernel input, never ambient — the session-orchestrator
 * resolves it and hands the final value to `runTurn`.
 */

/**
 * Controls how the kernel dispatches tool calls within a step.
 *
 * **`maxConcurrent`:**
 * - `0` — unlimited parallelism (deliberate opt-in; reopens the dedup footgun)
 * - `1` — sequential execution (a concurrency limit of 1 is exactly serial)
 * - `2+` — at most N tools run concurrently
 *
 * **`eager`:**
 * - `true` — launch each tool-call the instant it streams in from the provider
 *   (overlaps tool execution with the rest of generation)
 * - `false` — wait until the step's finish event, then dispatch the batch
 *
 * **Default:** `{ maxConcurrent: 1, eager: true }` — never two tools at once
 * (safe for any tool), yet the first tool starts during generation.
 */
export interface ToolDispatchPolicy {
	readonly maxConcurrent: number;
	readonly eager: boolean;
}