reach.optimize¶
Closed-loop skill description optimization using candidate synthesis and empirical probes.
Closed-loop skill description optimization using diagnostic findings and empirical probes.
CandidateOrigin ¶
IterationRecord ¶
Bases: BaseModel
Record candidate outcomes and probe scores for a single optimization round.
Source code in src/reach/optimize.py
OptimizationCandidate ¶
Bases: BaseModel
Represent a generated description rewrite and its empirical performance.
Source code in src/reach/optimize.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |
from_cached_test ¶
from_cached_test(
cached: OptimizationCandidate,
) -> OptimizationCandidate
Return a copy adopting cached holdout test metrics from a prior evaluation.
Source code in src/reach/optimize.py
from_cached_train ¶
from_cached_train(
cached: OptimizationCandidate,
) -> OptimizationCandidate
Return a copy adopting cached training metrics from a prior evaluation.
Source code in src/reach/optimize.py
mark_filtered ¶
mark_filtered(reason: str = '') -> OptimizationCandidate
Return a copy marked as filtered out by static lint rules.
unfiltered ¶
unfiltered() -> OptimizationCandidate
Return a copy marked as passing static lint rules.
with_baseline_metrics ¶
with_baseline_metrics(
*, recall: float, accuracy: float, misroute_rate: float
) -> OptimizationCandidate
Return a copy populated with baseline scores when description matches baseline.
Source code in src/reach/optimize.py
with_test_metrics ¶
with_test_metrics(
tally: _CandidateProbeTally,
) -> OptimizationCandidate
Return a copy populated with holdout test probe metrics from a _CandidateProbeTally.
Source code in src/reach/optimize.py
with_train_metrics ¶
with_train_metrics(
tally: _CandidateProbeTally, *, delta_recall: float
) -> OptimizationCandidate
Return a copy populated with training probe metrics from a _CandidateProbeTally.
Source code in src/reach/optimize.py
OptimizationReport ¶
Bases: BaseModel
Represent the full results of closed-loop skill description optimization.
Source code in src/reach/optimize.py
best_candidate
property
¶
best_candidate: OptimizationCandidate | None
Return top-ranked candidate if any candidates exist.
has_improvement
property
¶
Indicate whether the top-ranked candidate improves over baseline.
candidate_has_improvement ¶
candidate_has_improvement(
candidate: OptimizationCandidate | None,
) -> bool
Determine whether the specified candidate improves over baseline.
Returns True if there are no empirical probes (heuristic mode), or if the candidate achieves positive delta recall or strictly lower misroute rate at equal recall.
Source code in src/reach/optimize.py
build_optimization_prompt ¶
build_optimization_prompt(
target: Skill,
rivals: Sequence[Skill],
ceded_terms: Sequence[str] = (),
unclaimed_terms: Sequence[str] = (),
count: int = 3,
min_length: int | None = None,
max_length: int | None = None,
config: LintSettings | Path | None = None,
failed_triggers: Sequence[str] = (),
false_triggers: Sequence[str] = (),
previous_description: str | None = None,
iteration: int = 1,
) -> str
Construct an LLM prompt to synthesize differentiated skill description candidates.
Source code in src/reach/optimize.py
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 | |
evaluate_candidate ¶
evaluate_candidate(
candidate: OptimizationCandidate,
target: Skill,
rivals: Sequence[Skill],
queries: Sequence[Query],
agent: str | None = None,
baseline_recall: float = 0.0,
baseline_accuracy: float = 0.0,
budget: int = 20,
config: Path | None = None,
is_test: bool = False,
skills_corpus: Sequence[Skill] | None = None,
baseline_hits_by_id: dict[str, bool] | None = None,
) -> OptimizationCandidate
Empirically evaluate a candidate description against queries within a probe budget.
Source code in src/reach/optimize.py
filter_candidates ¶
filter_candidates(
candidates: Sequence[OptimizationCandidate],
skill_name: str,
config: LintSettings | None = None,
known_skills: Sequence[str]
| set[str]
| frozenset[str]
| None = None,
) -> list[OptimizationCandidate]
Validate candidates with static linter rules, marking non-compliant candidates.
Source code in src/reach/optimize.py
optimize_skill ¶
optimize_skill(
skill_name: str,
skills_path: Path | str | None = None,
queries_path: Path | str | None = None,
agent: str | None = None,
candidates_count: int = 3,
budget: int | None = None,
auto_apply: bool = False,
runtime_options: dict[str, Any] | None = None,
config: Path | None = None,
global_scope: bool = False,
settings: OptimizeSettings | None = None,
candidate_index: int = 1,
force: bool = False,
) -> OptimizationReport
Orchestrate closed-loop skill description optimization and candidate evaluation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skill_name
|
str
|
Target skill identifier to optimize. |
required |
skills_path
|
Path | str | None
|
Directory path containing the skill catalog. |
None
|
queries_path
|
Path | str | None
|
Optional path to labeled queries JSON file. |
None
|
agent
|
str | None
|
Agent runtime identifier (e.g. "claude-code", "antigravity-cli"). |
None
|
candidates_count
|
int
|
Number of description rewrite candidates to synthesize. |
3
|
budget
|
int | None
|
Optional probe budget override across candidate evaluations. |
None
|
auto_apply
|
bool
|
If True, automatically overwrite SKILL.md with the top candidate. |
False
|
runtime_options
|
dict[str, Any] | None
|
Additional key-value configuration options passed to runtime. |
None
|
config
|
Path | None
|
Optional path to custom reach.toml configuration file. |
None
|
global_scope
|
bool
|
If True, discovers skills from user global configuration (~/). |
False
|
settings
|
OptimizeSettings | None
|
Optional typed OptimizeSettings model containing iterations, holdout, review, auto_queries, positive_count, and adversarial_count. |
None
|
candidate_index
|
int
|
Index of candidate rewrite to apply when auto_apply is True. |
1
|
force
|
bool
|
If True, overwrite SKILL.md even if recall or accuracy did not improve. |
False
|
Returns:
| Type | Description |
|---|---|
OptimizationReport
|
An OptimizationReport recording baseline scores, evaluated candidates, and rewrite diffs. |
Source code in src/reach/optimize.py
1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 | |
split_query_set ¶
split_query_set(
queries: Sequence[Query],
target_skill: str,
holdout: float = DEFAULT_HOLDOUT,
seed: int = DEFAULT_SEED,
) -> tuple[list[Query], list[Query]]
Split query set into train and test sets, stratified by target_skill expectation.
Source code in src/reach/optimize.py
synthesize_candidates ¶
synthesize_candidates(
target: Skill,
rivals: Sequence[Skill],
ceded_terms: Sequence[str] = (),
unclaimed_terms: Sequence[str] = (),
count: int = 3,
driver: TextGenerator | None = None,
config: LintSettings | Path | None = None,
failed_triggers: Sequence[str] = (),
false_triggers: Sequence[str] = (),
previous_description: str | None = None,
iteration: int = 1,
) -> list[OptimizationCandidate]
Synthesize candidate descriptions using LLM generation or vocabulary heuristics.
Source code in src/reach/optimize.py
update_skill_description ¶
Update the description field in SKILL.md frontmatter while preserving file contents.