PhaseWeaver Agent Execution Runtime v0.1 · 2026-11-07 简体中文 README GitHub

Make the tool phase
a programmable memory decision

An execution runtime between agent orchestration and the inference engine

PhaseWeaver watches an agent move between reasoning ↔ tools ↔ waiting and turns KV-cache disposition (retain / offload / drop / release) into an explicit decision. Between parent and child agents, it makes ownership transfer eliminate repeated prefill. All numbers are [L1] deterministic simulation, not real-GPU measurements.

1Problem: the GPU waits during tool calls

Only one stream computes at a time, yet both trajectories hold their memory.

Agent A Agent B GPU idle 22 s idle 14 s 01020 304050 60 s A reasoning B reasoning tool (memory held) GPU busy
Fig. 1. Schematic, not measured: the GPU is busy 24 of 60 seconds (40%). The busy intervals are exactly the union of the two reasoning windows, [0,11] and [33,46].

2Architecture: three layers, one contract

Agents expose phases; the runtime owns resources; the engine owns compute. The contract is just reason and call_tool.

Agent code / orchestration framework reason(prompt, out) · call_tool(spec) phase events (the only contract) PhaseWeaver runtime Execution unit tree Phase × ContextState seven invariants · per-unit accounting Disposition leases RETAIN / OFFLOAD / DROP / RELEASE capability negotiation · explicit degradation Scheduler B0 · B2 · autopilot calibrated against the duty-cycle bound Tool supervision start · cancel · reap process group / Job Object Event log append-only replay → metrics timeline → attribution same seed, same result Extensible: backend / policy / tool / profile via entry points; third-party packages install cleanly submit · complete · handoff stats · available_bytes Inference engine vLLM · SGLang · mock (block-level KV accounting)
Fig. 2. The runtime owns the resource lifecycle, not the agent's reasoning loop. Engine differences are absorbed by adapters that declare their capabilities honestly.

3One turn: who decides, and when

Reasoning alternates with tool calls; the memory decision happens at the phase boundary.

queuedQUEUED reasoningREASONING tool callACTING reasoningREASONING doneCOMPLETED admit complete() tool returns complete() acquire lease lease ACTIVE park(disposition) RETAIN | OFFLOAD | DROP restore() · reuse KV release runtime engine runtime + tool engine runtime GPU idle idle GPU busy (reasoning) memory held the disposition is chosen from slack / pressure / thrash
Fig. 3. Beige boxes are phases; grey text below each is the resource action. The moving line steps through the turn in order; the decision is made when the tool starts, not when the engine eventually evicts under LRU.

4States and invariants: no residency without a lease

Phase and KV ownership are orthogonal; seven invariants are checked after every transition.

NONE submit() ACTIVE park restore RETAINED OFFLOADED DROPPED RETAIN OFFLOAD DROP restore restore recompute HANDED_OFF fork join returns solid: enter this state dashed: back to ACTIVE Any non-terminal state can reach RELEASED via RELEASE (arrows omitted for clarity); a terminal unit must hold no lease.
Fig. 4. Seven KV-ownership states. The three disposition paths highlight in turn; red is the parent/child transfer path, where ownership is unique and rolls back if the lease cannot follow.

5KV handoff: the child continues from the parent

By default a child re-prefills the whole context; handoff turns that cost into zero.

parent unit ACTIVE child (zero prefill) ACTIVE · holds lease parent (after join) RETAINED ① handoff() the only await ② join returns it zero recompute
Fig. 5. After the engine call returns, lease, handle and state move together; the loop shows the round trip. If the lease cannot follow, the blocks go back and the child falls back to prefill. Motion respects reduced-motion settings.

6Results: handoff pays off by an order of magnitude on structured work

2 GiB · 3 seeds · deterministic simulation [L1]; values are printed on the charts.

00.100.200.28 goodput (tasks/s) multi-agent orchestration 0.1220.1670.218 chained delegation 0.0050.2220.256 baseline B0 B2 fixed KV handoff
Fig. 6. The delegation baseline barely runs: every hop re-prefills the whole context and memory saturates repeatedly (2.7 failed tasks per run).
−60%−40%−20% 0+20%+40% +60% goodput p99 latency recompute tokens +15.6% +30.2% −20.6% −22.0% −52% −25% nested delegation fan-out
Fig. 7. Relative to B2. Handoff raises goodput and lowers tail latency and recompute; fan-out gains less because only the first child inherits the parent's context.

7Limits

Simulation onlyReal-GPU adapters exist, but L3 measurements are still missing (issue #3).
autopilot is not optimalA safe default; it does not win everywhere, so the system exposes a policy portfolio.
Known debtLease-capacity waiting still polls; multi-node scheduling is out of scope.
python scripts/delivery_check.py                    # six delivery gates
python -m phaseweaver.demo scenarios --seeds 3      # scenario matrix