refactor(delegation): simplifications across strategies#207
Merged
Conversation
- Add Candidate.metadata (Mapping[str, Any]) mirroring RoutingDecision.metadata.
WeightedStrategy now records per-strategy component scores in
Candidate.metadata['components'] instead of stuffing them into a formatted
string in reason. reason is now display-only ('weighted blend').
- Drop CapabilityStrategy.metadata['match_count'] — redundant with
len(decision.candidates).
- RoundRobinStrategy reset check now compares object-identity tuples instead
of running list equality; docstring notes the cycle effectively resets when
used inside a combinator that passes freshly-built sub-pools.
- CostAwareStrategy collapses five sample_*_tokens kwargs into a single
sample: CostContext | None = None. The model field is overwritten per
agent via dataclasses.replace. Default sample is 1000 input / 500 output.
- ChainStrategy returns dataclasses.replace(last_decision, ...) instead of
rebuilding RoutingDecision by hand.
2 tasks
ancongui
pushed a commit
that referenced
this pull request
May 31, 2026
…plifications refactor(delegation): simplifications across strategies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Cluster of small simplifications across
delegation.py:Candidate.metadata. MirrorsRoutingDecision.metadata.WeightedStrategynow records per-strategy component scores inCandidate.metadata['components']instead of formatting them into thereasonstring.reasonis now display-only ('weighted blend').CapabilityStrategy.metadata['match_count']dropped — redundant withlen(decision.candidates).RoundRobinStrategyreset check now compares object-identity tuples (tuple(id(a) for a in agents)) instead of running list equality. Cheaper per element and avoids any reliance on agent__eq__. Docstring notes the cycle effectively resets when used inside a combinator that passes freshly-built sub-pools.CostAwareStrategy.__init__collapses fivesample_*_tokenskwargs into a singlesample: CostContext | None = None. Themodelfield is overwritten per agent viadataclasses.replace. Default sample is 1000 input / 500 output, matching the previous defaults.ChainStrategyreturnsdataclasses.replace(last_decision, ...)instead of rebuilding theRoutingDecisionby hand.Breaking changes
CostAwareStrategy(sample_input_tokens=..., sample_output_tokens=..., ...)no longer accepts the individualsample_*_tokenskwargs. Callers that tuned them must passsample=CostContext(...)instead. Default behaviour unchanged.Candidate(...)gained an optionalmetadatafield. Positional construction (Candidate(agent, score, reason)) still works;replace(c, metadata={...})etc. now possible.Test plan
pytest tests/unit -q— 1410 passed.ruff format --check— clean.