Skip to content

feat(swarm): compile semantic strategic options for Agent Zero - #73

Merged
christopherjnelson merged 1 commit into
mainfrom
feat/semantic-strategic-options
Sep 22, 2026
Merged

christopherjnelson merged 1 commit into
mainfrom
feat/semantic-strategic-options

Conversation

@christopherjnelson

Copy link
Copy Markdown
Member

Summary

Agent Zero now chooses among engine-compiled, worker-relative semantic strategic options instead of global raw-H3 targets. Code owns geometry and legality; the model makes bounded judgments over opaque option IDs. See ADR 0034.

Why: in the 20-agent / ~469-cell real-provider run, ~140 of ~183 worker decisions were hold, final infection was ~22/469 cells, and planner prompts reached ~15–16k tokens. v1 serialized every world cell plus a global target list built from lexicographically sorted H3 IDs sliced to 80 — worlds over 80 cells silently lost targets.

Changes

  • apps/game-api/src/strategic-options.ts (new): deterministic compiler, ≤8 options per worker — hold (always), continue-active, expand (≤3, radius-4 scan with widening, one per 60° sector), evade (≤2, only under pressure, never reduces separation), reinforce (≤1, prefers reclaiming abandoned territory), relocate (≤1). Priority-aware bounding; greedy cross-worker deconfliction; every option pre-validated with swarmDirectiveIssue().
  • Contract swarm-planner-v2: model returns only { workerId, optionId, priority, riskTolerance }. Request carries a worldSummary and per-worker options — no cells, raw H3, or agent IDs; default-valued option fields omitted. Server maps optionId → (mission, targetCell); decode rejects unknown, cross-worker, repeated, and v1-shaped raw-H3 plans. #assertSwarmPlan checks each directive against the options offered to that agent.
  • Export schema v13, no compatibility path for earlier exports.
  • Pressure, replan thresholds/reasons, capture context, and directive completion semantics unchanged. Zero's own action system unchanged (prompt projection is {id, description} only).
  • Docs: ADR 0034, ARCHITECTURE, SECURITY, TESTING, README, GAMEPLAY_FOUNDATION.

Prompt size (real buildSwarmPlannerRequest)

Scenario Bytes ≈ tokens
8 workers / 127 cells 13,047 ~3.3k
8 workers / 469 cells 13,281 ~3.3k
20 workers / 469 cells 29,478 ~7.4k
v1 shape, 20 / 469 (estimate) 39,567 ~9.9k

Request size now scales with roster, not world size.

Tests

Option compiler geometry/bounds/determinism/diversity/pressure tests; planner rejection tests; an end-to-end SimulationService → OpenRouterSwarmPlanner (mocked fetch) test asserting no H3 cell or agent UUID reaches the model and chosen options map to authoritative directives. Threat-awareness tests unchanged and green.

Validation

Owner-confirmed local: pnpm validate (245 tests) and pnpm test:e2e (2/2).

Follow-up

Owner real-provider scale run (20 agents, radius 12, trail hunter, Gemini Flash low, Jev, 10–20 ticks) to compare directive distribution, hold %, dispersion, captures, prompt tokens/cost against the prior run.

🤖 Generated with Claude Code

Introduces swarm-planner-v2: the model request contains no raw H3 cell IDs
and no agent IDs. Server compiles bounded semantic options (≤8/worker) with
opaque optionIds; Agent Zero selects optionId per worker; server resolves
optionId → (mission, targetCell) authoritatively.

- packages/shared: add strategicOptionSchema, worldSummarySchema,
  WorkerOptions; update ZeroStrategicObservation (remove strategicTargetCells,
  add worldSummary + workerOptions); bump schemaVersion → 13;
  SWARM_PLANNER_CONTRACT_VERSION → 'swarm-planner-v2'
- apps/game-api: new strategic-options.ts compiler (hold always first,
  continue-active, expand ≤3 sector-diversified radius-4-first scan,
  evade ≤2 under pressure, reinforce ≤1, relocate capped at 1,
  priority-aware bounding, swarmDirectiveIssue final filter)
- apps/game-api: simulation-service.ts wires compileStrategicOptions,
  removes offeredOptions map from #assertSwarmPlan, reverts
  hold+null-target at-target telemetry change
- packages/agent-runtime: swarm-planner.ts updated for v2 contract
  (compactPlanSchema uses optionId, decodePlanChoice resolves server-side,
  planAuthorityIssue checks mission:targetCell keys, no raw cells in request)
- docs: ADR 0034, update ARCHITECTURE/SECURITY/TESTING/README/GAMEPLAY_FOUNDATION
- tests: 13 strategic-options unit tests (including 20-agent/radius-12
  swarmDirectiveIssue assertion and priority-bounding reclaim-abandoned test);
  swarm test redesigned for completed-directive identity reporting

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@christopherjnelson
christopherjnelson marked this pull request as ready for review September 22, 2026 23:49
@christopherjnelson
christopherjnelson merged commit 26bcdde into main Sep 22, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant