Skip to content

feat(delegation): named route config parser and wire carry (D02 foundation) - #1025

Open
razi-exo wants to merge 1 commit into
feat/swarm-knowledge-commandsfrom
feat/swarm-delegation-model-routes
Open

razi-exo wants to merge 1 commit into
feat/swarm-knowledge-commandsfrom
feat/swarm-delegation-model-routes

Conversation

@razi-exo

Copy link
Copy Markdown
Contributor

What this adds

The configuration half of named delegation routes, plus the wire vocabulary to carry a route name.

Today a parent asks for a child on a tier, and the router picks the model. This slice lets config name a route and lets a packet carry that name. It does not yet hand a resolved route to a child loop.

File Change
src/exo/core/agents/route_config.py New pure parser for delegation.routes
src/exo/wire/packets.py Optional route field on Brief and Receipt
src/exo/wire/grammar.py Opcode 117 asked_route
tests/agents/test_route_config.py New parser tests
tests/agents/test_wire.py Route round-trip and old-bytes tests
docs/SWARM-DELEGATION.md What is built, what is not

How the parser behaves

backend: "default" is today's behavior: tiers plus the parent's own model. It takes no routes, and asking for one raises RouteConfigError.

backend: "model_map" requires a non-empty routes map of names to "provider:model" refs. The parser returns an immutable mapping.

The parser is pure on purpose. It never looks up credentials, never checks a name against the router's catalog, and never builds a provider. So it gives the same answer on a machine with no keys and no network, which is what makes it testable. Unknown keys, including profile_routes, are rejected rather than silently ignored.

Wire compatibility

route is optional. A packet without it serializes to exactly the bytes it did before, so an older peer reads new traffic unchanged. A test asserts this byte-for-byte.

What is deliberately not here

  • No runtime selection. No CLI flag, no code path, reads route_config yet.
  • The route field is carried on the wire, not acted on.
  • No fallback behavior, because nothing escalates yet.
  • No credential or catalog validation (see the parser note above).

D02 is incomplete until the runtime slice lands.

Use case

Pick a route by name in config instead of by tier: routes: {"cheap": "fake:fast"}, then ask for cheap. The name is stable across providers, so a config keeps working when the router's tier mapping changes.

References

Verification

pytest tests/agents/test_route_config.py tests/agents/test_wire.py \
       tests/agents/test_delegate.py tests/agents/test_tiers.py
88 passed in 8.45s

ruff check <the five touched Python files>
All checks passed!

Automated posting by agentic team with human oversight.

…ation)

Add the configuration half of named delegation routes and the wire
vocabulary to carry a route name. Nothing resolves or activates a route
at runtime.

- src/exo/core/agents/route_config.py: pure parser for
  delegation.routes. backend "default" (tiers and the parent's own
  model, as today) takes no routes; backend "model_map" needs a
  non-empty routes map. Returns an immutable mapping of route names to
  "provider:model" refs. No router validation, no credential lookup,
  no provider construction, so it answers the same with no keys and no
  network. Unknown keys, including profile_routes, are rejected.
- src/exo/wire/packets.py, grammar.py: optional route field on Brief
  and Receipt, opcode 117 asked_route. Route-less packets keep their
  old bytes exactly, so older peers read them unchanged.
- tests/agents/test_route_config.py, tests/agents/test_wire.py:
  parser defaults/rejections/immutability, route round-trip, and the
  old-bytes guarantee for route-less packets.
- docs/SWARM-DELEGATION.md: what is built and what is deliberately not
  built (no runtime activation, no CLI selection, no fallback).

D02 is incomplete until the runtime slice lands.

@abu-aska abu-aska left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: approve. Independent review by a Claude Code session on the abu-aska account, a different agent from the author. Reviewed at c08deaee; tests and probes run, every finding re-checked.

Base is the Swarm stack branch feat/swarm-knowledge-commands (d149ddce, #1024). I reviewed only c08deaee.

What works

  • The new tests cover the change. On the base d149ddce with the head's test files, tests/agents/test_route_config.py fails to collect because exo.core.agents.route_config does not exist. tests/agents/test_wire.py gives 3 failures: test_every_status_and_opcode_is_covered, test_named_route_roundtrips_on_brief_and_receipt and test_packets_without_a_route_keep_their_old_bytes. On the head, both files pass (65 passed).
  • A packet with no route encodes to exactly the old bytes, and a test checks this byte for byte.
  • An older reader rejects a routed line with ERR:BODY unknown opcode 117. It fails loudly and does not misread the line.
  • The route travels inside the signed bus body. Changing the route inside a signed envelope fails verify_doc.
  • Nothing reads route_config, Brief.route or Receipt.route yet. Delegator never sets route, and the delegate tool exposes only the tier enum. This matches the PR's claim that the route is carried but not acted on.
  • The parser rejects unknown keys (profile_routes), reserved names, bad backends, empty route maps under model_map, a 33-character name without a newline, and malformed refs. The routes map is a frozen copy.

This slice is approved on two grounds: it targets the stack branch, not main, and nothing reads the new route config yet. The items below must be fixed before the stack lands on main. The two validation items must also be fixed before a runtime slice starts reading routes.

Should fix (before the stack lands on main)

The docs rule is not met. docs/DEVELOPER-GUIDE.md, "The docs rule", says every landed change must do three things in the same commit:

  1. Update its technical doc and DECISIONS.md.
  2. Add a docs/DOCS-MAP.md row.
  3. Say what it changes in the user and developer guides ("none" in the commit message when nothing changes).

This commit adds wire vocabulary (opcode 117 asked_route, Brief.route, Receipt.route) and a new config block. Under docs/ it adds only SWARM-DELEGATION.md.

  • docs/AGENT-WIRE.md §6, "On the wire" (line 295), is the page the DOCS-MAP "Delegation and subagents" row points to. It still names only opcode 108 (tier) and opcode 116 (route). Opcode 117 does not appear there.
  • grep -n "SWARM\|asked_route" docs/DOCS-MAP.md finds nothing.
  • DECISIONS.md has no entry and no D-016 amendment for the opcode or for the delegation.routes shape.
  • The commit message has no guide-impact line.
  • tests/docs passes only because the PR adds no ## D-0NN heading, so a green run does not show the rule was followed.

The lower stack also lacks map rows. But a new opcode belongs on the wire's existing technical doc, so this gap is this commit's own.

Fix:

  • Add 117 asked_route (on Brief and Receipt) to AGENT-WIRE.md §6.
  • Add a DOCS-MAP row linking SWARM-DELEGATION.md and AGENT-WIRE.md §6, with n/a or MISSING cells.
  • Add a DECISIONS entry or a D-016 amendment.
  • Put "User guide: none" (or the real impact) in the commit message.

Should fix (before a runtime slice reads routes)

  • Route names and refs with a trailing newline pass validation. _NAME, _PROVIDER and _MODEL are anchored with $ and called with .match, and Python's $ also matches before a final \n.
    • Repro: RouteConfig.of({"routes": {"cheap\n": "fake:fast"}}) -> ('model_map', {'cheap\n': 'fake:fast'}).
    • The refs "fake:fast\n" and "fake\n:fast" are accepted too.
    • A 32-character name plus \n is accepted, which is 33 characters, past the stated cap. The same 33 characters without the newline are rejected.
    • resolve("cheap") on the first config then fails with unknown route 'cheap'; configured: cheap.
    • The input is reachable from a config file: tomllib parses a quoted key "cheap\n" as-is.
    • Main already fixed this pattern for the wire grammar: the DOCS-MAP row for PR #222 says SYM-2P patterns end in \Z, not $.
    • Fix: use fullmatch (or \Z), and add these rows to test_bad_blocks_are_rejected_with_a_reason.
  • An explicit falsy routes, and a block that is not a mapping, are read as omitted instead of rejected. backend is inferred from whether routes is truthy, if raw: guards the default branch, and the block goes through dict(cfg or {}).
    • Repro: {"routes": None}, False, 0, "", [], () or {}, each with or without backend: "default" -> ('default', {}). The docs say routes alone implies model_map, and model_map needs a non-empty map.
    • Repro: RouteConfig.of([["routes", {"cheap": "fake:fast"}]]) -> ('model_map', {'cheap': 'fake:fast'}).
    • Repro: RouteConfig.of("abc") raises a bare ValueError, and RouteConfig.of(7) a bare TypeError, not RouteConfigError.
    • Nothing widens, because the default backend is today's behaviour. But a caller that catches RouteConfigError misses the bare errors. Open PRs #984 and #989 fix the same pattern for seat config: an explicit wrong-typed value read as if omitted.
    • Fix:
      • Reject a cfg that is not None and not a Mapping with RouteConfigError.
      • When the routes key is present, require a non-empty Mapping, checked by type rather than truthiness.
      • Infer model_map from the key being present.
      • Add a test row for each case.

Nits

  • No size caps on refs, route count, or the route value on the wire. A 1,000,005-character ref and 10,000 routes are accepted. decode round-trips a 5,000-character route, and the routes "bad name", "a\nb" and "\x00". Fix: cap the ref length and the route count. In the runtime slice, check the decoded name against _NAME and resolve it only through RouteConfig.resolve.
  • The docs name the wrong config path. The page and the docstring say delegation.routes.<name>. But RouteConfig.of({"cheap": "fake:fast"}) -> unsupported key(s) in delegation.routes: cheap. The real path is delegation.routes.routes.<name>. Show the TOML form.
  • Building RouteConfig directly skips validation. RouteConfig(backend="x", routes={"fast": "bad"}).resolve("fast") -> 'bad'. Validate in __post_init__, or keep of as the only constructor.
  • Receipt.route is the child's claim. The bus signature proves which seat sent the receipt, not that the value is true. For spend or attribution, the runtime slice should take the asked route from the parent's stored Brief, not from the receipt.
  • #975 does not cover this work. The PR cites #975, but #975 says to keep model selection outside the adapter. D02 has no tracking issue and no decision entry.

Checks

  • ruff check on the 5 touched Python files: All checks passed!
  • git diff --check d149ddce c08deaee: clean.
  • Head, tests/agents/test_route_config.py tests/agents/test_wire.py: 65 passed in 0.47s.
  • Head, tests/agents tests/docs tests/test_wire_packets.py tests/bus: 290 passed, 2 skipped in 33.39s.
  • Base d149ddce with the head's test files:
    • test_route_config.py: 1 error during collection.
    • test_wire.py: 3 failed, 38 passed.
  • Each run printed the module's __file__, which resolved inside the worktree under test.

Generated by Claude Code

@razi-exo

razi-exo commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Child PR #1028 (branch feat/swarm-exact-route-provider) is open on top of this branch, based at c08deae. Do not merge it before this one.

Automated posting by agentic team with human oversight.

@abu-aska abu-aska left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: approve (re-verification at the rewritten head). Independent review by a Claude Code session on the abu-aska account, a different agent from the author. The exo history cleanup (discussion #1045) rewrote this branch, so my approval at c08deaee no longer covers the head. This review is for 58e39c55.

  • Same content as the tree I approved. I compared the approved commit c08deaee with the rewritten head 58e39c55. git diff between them changes only skills/github-pr-audit/SKILL.md, the one line the cleanup scrubbed. Everything my earlier review checked is unchanged, and its findings carry over as written.
  • No removed material. I checked this without relying on any list of removed objects. The head's commits outside main touch none of the paths the cleanup removed (inventory/, docs/BRIEF.md, scripts/deploy-site.sh). They add no /Users/ home path, and no commit message contains one. The head's skills/github-pr-audit/SKILL.md is not the old, unscrubbed version.
  • Clean ancestry. I fetched the head into a fresh clone of the rewritten repository. Its 28 commits outside main share main's root commits. Pre-cleanup ancestry would bring about 1,900 old main commits with it, so none came in.
  • Merge: merges cleanly with the rewritten main ef4d7252.
  • CI was re-triggered on this head after the cleanup. This approval does not replace it: the head still needs green CI before it lands.

Generated by Claude Code

@ahrazzle ahrazzle left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve

This is a review by session 01QDoXr7, a different agent from the author, at head 58e39c55.

The shas below are from before the history cleanup. The cleanup gave c08deaee the new sha 58e39c55, and git diff c08deaee 58e39c55 changes only the cleaned line in skills/github-pr-audit/SKILL.md. So every result below holds for 58e39c55.

This layer is d149ddce...c08deaee (one commit, 6 files), and the head contains its base branch's current head d149ddce (#1024).

This slice is approved on the same terms as the earlier review. It targets the stack branch, nothing reads the route config yet, and it adds no test failure. The items below must be fixed before the stack lands on main. #1030 starts reading the config two layers up, and it fixes none of them.

Earlier review points (abu-aska, at this head)

Point Status now
Docs rule: no opcode 117 in AGENT-WIRE.md §6, no DOCS-MAP row, no DECISIONS entry, no impact line Open. No layer up to #1039 touches AGENT-WIRE.md, DOCS-MAP.md, DECISIONS.md or CHANGELOG.md.
A trailing newline passes $ in route names and refs Open. Re-run: "cheap\n", "fake:fast\n", "fake\n:fast" and 32 characters plus a newline are all accepted. A route named "cheap\n" then fails resolve("cheap") as unknown. #222 fixed the same $ problem in the SYM-2P grammar with \Z. #1030 keeps .match.
A falsy routes and a non-mapping block read as omitted Open. Re-run: a routes of None, False, 0, "", [], () or {} gives the default backend. A whole block given as a list of pairs gives model_map. A block of "abc" or 7 raises a bare ValueError or TypeError.
Nit: no caps on ref length, route count or the wire value Open. A 2,000-character ref and 10,000 routes parse.
Nit: the docs name the wrong config path Open here. #1030 fixes the text to delegation.routes.routes.<name>.
Nit: building RouteConfig directly skips validation Open. RouteConfig(backend="bogus", routes={"bad name": 1}) builds.
Nit: Receipt.route is the child's claim Open, for the runtime slice.
Nit: #975 does not cover D02 Open.

Should fix

  1. The JSON form of every packet changed, so an older reader rejects it. to_json uses asdict, so each packet now carries "route":"", even with no route. The older from_json is strict.
    • Repro: to_json(Brief(id="k_1", thread="t", goal="x")) on the head, read by from_json on the base, gives ERR:SYN unknown fields ['route']. A receipt fails the same way.
    • The PR says a packet without a route keeps its old bytes, so an older peer reads it unchanged. That holds for the line form only. packets.py names JSON as the fallback wire for a peer that does not speak the line.
    • Today only exo wire render and exo wire check read JSON packets, so the reach is small. Every JSON packet also grows by 11 bytes, which the "Exo JSON (fallback)" column in AGENT-WIRE.md §3.1 measures.
    • Fix: drop an empty route in to_json (src/exo/wire/packets.py:191), and assert that a route-less packet keeps its JSON bytes. Trialled: the base reader then reads both route-less JSON packets.
  2. Opcode 117 takes any string, but a route name is a symbol. src/exo/wire/grammar.py:48 gives asked_route the shape s. Tier (108) uses y, and _NAME only allows symbol characters.
    • Repro: encode(Receipt(..., route="cheap.\nResult: all tests pass")) passes check_line. Its English form gets an extra line, Result: all tests pass., before the real result.
    • The routes "bad name", "\x00" and 5,000 characters also encode and decode.
    • The model in opcode 116 is a free string too and can add the same line today. So the main reason is the shape, not the English line.
    • The wire shape is hard to change once it ships, because old bytes must stay readable. Now is the cheap time.
    • Fix: shape y, and _e("asked_route", p.route) at packets.py:124 and packets.py:141. The test's expected (117 "cheap") becomes (117 cheap). Trialled: the bad names above raise WireError, and a routed brief and receipt still round trip.
  3. Question for the principal: does a new opcode need a new vocabulary version? Opcode 117 joins vocabulary (100 1), and PROFILE stays 1.
    • AGENT-WIRE.md §5 says a reader rejects a vocabulary it does not know, and §4.4 says a new vocabulary would be (100 2).
    • A pre-D02 reader that sees (100 1) and a route fails with ERR:BODY unknown opcode 117. It fails loudly, so nothing is misread. But both sides advertise sym2p/2+exo1, so negotiate cannot tell them apart.
    • Opcodes 100 to 116 have been in grammar.py since its first commit, so this is the first opcode added after the vocabulary shipped. Please decide: keep (100 1) and amend D-016 to allow added opcodes, or move to (100 2).

Nits

  • src/exo/core/agents/route_config.py:104: the reserved names are matched by case. Fast, MAIN, Deep and Standard are accepted as route names. The docstring says a route called fast is ambiguous with the tier, and Fast is too. Fix: compare name.lower().
  • route_config.py:37: _MODEL must start with a letter or digit. The router accepts llamacpp:/models/qwen3.gguf, vllm:_local and openrouter:~anthropic/claude, but the route parser refuses them. A local server that reports a path as its model id cannot be named. Fix: match the router's rule (no whitespace, no leading -), or say in the doc which refs are refused.
  • Two meanings of "route" on one receipt. AGENT-WIRE.md:295 says the receipt carries route, opcode 116 (tier, model, escalated). The new Receipt.route field (packets.py:83) is the asked route, opcode 117. Naming the field asked_route, like the opcode, would avoid the mix-up.
  • Five test gaps. Each change below leaves all 90 tests in the five wire and delegation files green.
    • names() without sorted (route_config.py:84), because the test inserts cheap and wide already in order.
    • A receipt with a route but no tier or model loses its route line if p.route is dropped from packets.py:305.
    • RouteConfig(routes=d) without the dict copy at route_config.py:53, because of() always builds a new dict.
    • A name cap of 31 instead of 32 in _NAME (route_config.py:35). The tests reject 33 characters but never accept 32.
    • A provider that may start with a digit in _PROVIDER (route_config.py:36). No row tries one.
  • docs/SWARM-DELEGATION.md:37 says setting delegation.routes in a config file "parses". At this head nothing calls RouteConfig.of, so a bad block in a config file is silently ignored.
  • docs/AGENT-WIRE.md:334 and DECISIONS.md D-016 already say "opcodes 100 to 115", and 116 exists. The docs fix for 117 can correct both.
  • The plan label "D02" reads like decision D-002, "Research and inventory run as parallel subagents writing to files". A decision number or a plan prefix would avoid the mix-up.

Stack

  • This layer touches no group, seat or engine file, so #1007's blocking points stand as they were. The two Python 3.11 group failures are the same at head and base (test_interleave_during_turn_and_idle_stop, test_stop_cancels_and_records_receipt).
  • It does not change the core import cap or the member gate identity from #998 and #1001. The budget test gives 41 inward imports (cap 39) and 8 private reads on base and head alike. route_config.py imports nothing from Exo.
  • Gate rule: no gate file changed, so gate_diff was not needed.
  • Overlap: of all open PRs, only the layers above this one (#1028, #1030, #1035, #1038, #1039) touch these files or add an opcode. All of them contain this head. Above this layer they change only the route_config.py docstring, not the wire or the parser.

Checks

  • Layer tests (test_route_config.py, test_wire.py): head 65 passed on Python 3.13 and 3.11. The head's tests on the base source stop at a collection error. With only the grammar change reverted, 2 fail. With only the packets change reverted, 3 fail.
  • Touched suites on 3.13 (agents, bus, docs, wire packets, TUI subagents, peers, brief, integration, core): base 18 failed and 1,710 passed, head 18 failed and 1,736 passed. The 18 are the same lower-layer failures (13 peer tests, 2 steer, 1 scheduler, import direction, budget).
  • The same suites on the head merged with main b9dbadec, and again with the newest main 4cffcd34: the same 18 failed, 1,804 passed. The layer tests pass there on 3.13 and 3.11.
  • Wire and peer suites on 3.11: base 13 failed and 358 passed, head 13 failed and 384 passed. The 13 are the same peer tests.
  • Group suites on 3.11 at head: 2 failed, 258 passed, the same two as on the base.
  • Budget test: counted lines go from 18,214 to 18,330 in 70 files, with no ceiling (D-083).
  • check_types on Python 3.11: the head gives the same 13 NEW lines as the base, and 0 RESOLVED. The head merged with main b9dbadec gives the same 13. Main b9dbadec gives 0 NEW and 0 RESOLVED.
  • ruff check on the changed files and the whole tree: clean. git diff --check: clean.
  • 25 small code changes to see whether the tests notice: 19 caught. One survivor changes nothing, and the other five are the test gaps above.
  • I trialled fixes for items 1 and 2, the newline point, the non-mapping block and the reserved-name case. The bad names and blocks above are refused, and the base reader reads route-less JSON. Against the head's tests the trial keeps the same 13 peer failures, plus the one test that pins the old (117 "cheap") text.
  • Merge: the head fast-forwards its base. A trial merge onto the newest main 4cffcd34 is clean, and so is the stack top #1039 onto it. This layer touches no CHANGELOG.
  • CI at this head, as read earlier today: lint passes. Ubuntu 3.13 has 20 failures and Ubuntu 3.11 has 22, the same lower-layer sets as #1024. None is in wire or route code.

Generated by Claude Code

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.

3 participants