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 ¶
CandidateProbeTally ¶
Bases: BaseModel
Encapsulate empirical probe counts and derived routing metrics for a candidate.
Source code in src/reach/optimize.py
167 168 169 170 171 172 173 174 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 | |
misroute_rate
property
¶
Compute empirical misroute rate across executed probes.
trajectory_recall
property
¶
Compute empirical trajectory recall across positive queries.
paired_delta_recall ¶
paired_delta_recall(
*,
baseline_recall: float,
baseline_hits_by_id: dict[str, bool] | None,
queries_to_run: Sequence[Query],
target_name: str,
) -> float
Compute paired delta recall against baseline hits on the same positive query subset.
Source code in src/reach/optimize.py
paired_delta_trajectory_recall ¶
paired_delta_trajectory_recall(
*,
baseline_trajectory_recall: float,
baseline_traj_hits_by_id: dict[str, bool] | None,
queries_to_run: Sequence[Query],
target_name: str,
) -> float
Compute paired delta trajectory recall against baseline trajectory hits.
Source code in src/reach/optimize.py
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
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 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 | |
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,
trajectory_recall: float | None = None,
) -> 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,
delta_trajectory_recall: float = 0.0,
) -> 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, positive delta trajectory recall, or strictly lower misroute rate at equal recall.
Source code in src/reach/optimize.py
ReciprocalHandoff ¶
Bases: BaseModel
Represent reciprocal Layer-2 SKILL.md body routing notes for target and rival.
Source code in src/reach/optimize.py
apply_optimization_candidate ¶
apply_optimization_candidate(
report: OptimizationReport,
candidate: OptimizationCandidate,
) -> bool
Apply candidate description and optional reciprocal Layer-2 handoffs atomically to disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
report
|
OptimizationReport
|
Optimization report containing target manifest path and staged handoff metadata. |
required |
candidate
|
OptimizationCandidate
|
Candidate proposed for disk application. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if all target and rival file updates succeeded cleanly, or False otherwise. |
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: Mapping[str, Any] | None = None,
config: Path | None = None,
global_scope: bool = False,
settings: OptimizeSettings | None = None,
candidate_index: int = 1,
force: bool = False,
*,
with_handoff: bool | None = None,
workers: int | None = None,
progress_callback: Callable[[str], None] | None = None,
) -> OptimizationReport
Orchestrate closed-loop skill description optimization and candidate evaluation.
Source code in src/reach/optimize.py
2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 | |