Skip to content

feat(bundle): add routing field for bundle-declared matrix defaults - #301

Open
Sam Schillace (ramparte) wants to merge 1 commit into
mainfrom
pr/bundle-routing-field
Open

feat(bundle): add routing field for bundle-declared matrix defaults#301
Sam Schillace (ramparte) wants to merge 1 commit into
mainfrom
pr/bundle-routing-field

Conversation

@ramparte

@ramparte Sam Schillace (ramparte) commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Problem

An Amplifier bundle and the active routing matrix are independent settings with no linkage, so they silently disagree. Real incident: a stale project-level .amplifier/settings.local.yaml pinned routing: matrix: anthropic while the session ran on OpenAI. Every model_role delegation resolved to zero candidates — model_role 'fast' resolved to no candidates — with no error, no attribution, and no hint that a one-line file three directories away was the cause.

What this does

Adds an opaque routing: dict[str, Any] field to the Bundle dataclass so a bundle can declare routing:\n matrix: openai. Foundation stores and merges it and interprets nothing (same posture as spawn); the host app decides what it means. Read in from_dict with non-dict values coerced to {}; deep-merged in compose() beside the existing spawn merge so later/overlay wins and an overlay declaring only overrides: keeps the base's matrix:. Typed as a dict rather than a narrow routing_matrix: str | None so it mirrors the settings routing: shape and the app layer uses one merge path. Deliberately NOT added to to_mount_plan() — the mount plan is the kernel-facing surface and routing is app-layer policy; a comment marks this so nobody "fixes" it later.

Precedence

Bundle value is the WEAKEST source. Precedence, weakest to strongest:

  • built-in default
  • bundle-declared routing.matrix
  • user ~/.amplifier/settings.yaml
  • project .amplifier/settings.yaml
  • project .amplifier/settings.local.yaml

A bundle with no routing: key behaves exactly as today.

Backward compatibility

Purely additive; no routing: key means byte-identical behavior, pinned by test_to_mount_plan_omits_routing and the default-empty-dict tests.

Testing

1558 -> 1565 passing, zero regressions, 7 new tests, pyright clean.

Note: tests/test_grpc_adapter_main.py::TestVerifyModuleType::test_non_isinstance_object_with_mount_passes fails on this branch AND on unmodified origin/main — a pre-existing @runtime_checkable issue unrelated to this change.

Non-goals

  • No --matrix CLI flag
  • No profile system
  • No provider/matrix compatibility validation (that ships separately as a session:start hook)

Companion PR

microsoft/amplifier-app-cli#262

Adds a `routing: dict[str, Any]` field to the Bundle dataclass so a
bundle can declare a default routing matrix (e.g. {matrix, overrides}).
Foundation treats it as opaque passthrough -- it stores and deep-merges
the dict during compose() but interprets nothing about its contents.
A separate app-cli PR consumes it, applying user/project settings'
routing: block as the higher-priority override.

Changes in amplifier_foundation/bundle/_dataclass.py:
- New `routing` field on Bundle, defaulting to {} via default_factory
- __post_init__ None-guard, matching existing collection field pattern
- from_dict() reads routing, coercing non-dict values to {} rather than
  raising -- foundation does not validate routing semantics
- compose() carries routing into the result and deep-merges it in the
  merge loop, so an overlay declaring only `overrides` preserves the
  base's `matrix`
- to_mount_plan() deliberately does NOT include routing -- it's app-layer
  policy, not a kernel-facing mount-plan concern. Added a comment so a
  future reader doesn't "fix" this omission.

Purely additive: a bundle with no `routing:` key behaves byte-identically
to today (routing == {}, absent from mount plan).

Tests: tests/test_bundle_routing_field.py covers from_dict (absent key,
present key, malformed value) and compose (overlay wins, deep merge
preserves base matrix, base survives overlay without routing) and
to_mount_plan omission.

Docs: docs/BUNDLE_GUIDE.md frontmatter reference and merge-rules list
now document routing: as a default that user/project settings override.

🤖 Generated with [Amplifier](https://github.com/microsoft/amplifier)

Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
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