You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The weaver-spec defines RoutingDecision as contextweaver's primary output — the structured result of the routing phase, containing a list of ChoiceCards and optional selection metadata. contextweaver currently outputs a RouteResult dataclass that has a fundamentally different shape:
RouteResult is a flat list of scored candidates. RoutingDecision is a structured decision record with grouped ChoiceCards and selection tracking. Without a RoutingDecision type, contextweaver's output is not spec-compliant, and the contract adapter (#143) has no internal type to map from.
Spec invariant I-03 — "Routing presents bounded choices, not full schema catalogs." RoutingDecision embeds grouped ChoiceCards, enforcing this invariant structurally.
Cross-repo interop — ChainWeaver and agent-kernel both consume RoutingDecision. Without one, contextweaver can't participate in the ecosystem contract chain.
Acceptance Criteria
RoutingDecision dataclass in src/contextweaver/envelope.py (or types.py) with fields matching the spec contract shape:
id: str — unique decision identifier
choice_cards: list[ChoiceCard] — the bounded choices presented
timestamp: datetime
selected_item_id: str | None — which item was ultimately selected
selected_card_id: str | None — from which card
context_summary: str | None — optional rendering of the decision context
metadata: dict[str, Any]
to_dict() / from_dict() methods on RoutingDecision (per conventions)
Router.route() returns or can produce a RoutingDecision (in addition to or replacing RouteResult)
RouteResult preserved for backward compatibility (or deprecated with migration path)
Unit tests for construction, serialization round-trip, and integration with Router
Exported from __init__.py
Implementation Notes
Option A (preferred):Router.route() returns RoutingDecision which embeds the RouteResult data in a spec-compliant envelope. RouteResult becomes an internal detail or is deprecated.
Option B: Add a Router.decide() method that returns RoutingDecision, keeping route() unchanged for backward compatibility.
Files likely touched:
src/contextweaver/envelope.py — new RoutingDecision dataclass
src/contextweaver/routing/router.py — produce RoutingDecision
src/contextweaver/__init__.py — export
tests/test_envelope.py or tests/test_router.py — tests
Context
The weaver-spec defines
RoutingDecisionas contextweaver's primary output — the structured result of the routing phase, containing a list ofChoiceCards and optional selection metadata. contextweaver currently outputs aRouteResultdataclass that has a fundamentally different shape:RouteResultis a flat list of scored candidates.RoutingDecisionis a structured decision record with grouped ChoiceCards and selection tracking. Without aRoutingDecisiontype, contextweaver's output is not spec-compliant, and the contract adapter (#143) has no internal type to map from.Why it matters
RoutingDecisionequivalent to implementto_weaver()/from_weaver()round-trip mapping.RoutingDecisionembeds groupedChoiceCards, enforcing this invariant structurally.RoutingDecision. Without one, contextweaver can't participate in the ecosystem contract chain.Acceptance Criteria
RoutingDecisiondataclass insrc/contextweaver/envelope.py(ortypes.py) with fields matching the spec contract shape:id: str— unique decision identifierchoice_cards: list[ChoiceCard]— the bounded choices presentedtimestamp: datetimeselected_item_id: str | None— which item was ultimately selectedselected_card_id: str | None— from which cardcontext_summary: str | None— optional rendering of the decision contextmetadata: dict[str, Any]to_dict()/from_dict()methods onRoutingDecision(per conventions)Router.route()returns or can produce aRoutingDecision(in addition to or replacingRouteResult)RouteResultpreserved for backward compatibility (or deprecated with migration path)__init__.pyImplementation Notes
Option A (preferred):
Router.route()returnsRoutingDecisionwhich embeds theRouteResultdata in a spec-compliant envelope.RouteResultbecomes an internal detail or is deprecated.Option B: Add a
Router.decide()method that returnsRoutingDecision, keepingroute()unchanged for backward compatibility.Files likely touched:
src/contextweaver/envelope.py— newRoutingDecisiondataclasssrc/contextweaver/routing/router.py— produceRoutingDecisionsrc/contextweaver/__init__.py— exporttests/test_envelope.pyortests/test_router.py— testsDependencies
choice_cardsfield here depends on the ChoiceCard shape)contracts/python/src/weaver_contracts/core.pyReferences