Skip to content

feat: Add harness optimization experiment - #4069

Draft
sjrl wants to merge 6 commits into
mainfrom
feat/harness-optimization-experiment
Draft

sjrl wants to merge 6 commits into
mainfrom
feat/harness-optimization-experiment

Conversation

@sjrl

@sjrl sjrl commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Related Issues

  • part of deepset-ai/haystack-private#498

Proposed Changes:

Second part of the harness optimization work: the loop that runs the optimizer agent from #4037 over a labelled evaluation set.

  • HarnessOptimizationExperiment(reference, evaluator, eval_cases, prices, objectives, journal, optimizer_*, ...) builds its own optimizer agent from its evaluator and the loader that matches the reference.
  • run() measures the reference, then for up to max_iterations turns proposes a candidate, measures, prices and gates it. Each turn starts from the best candidate so far.
  • Returns an ExperimentResult: every CandidateEvaluation, the gate failures, the optimizer's own usage and cost, and an ExperimentRecommendation when a candidate beats the reference.
  • Every measurement is appended to an ExperimentJournal, and each run writes its YAML artifacts to its own directory. on_baseline and on_candidate report progress.
  • Example: retrieval_pipeline_optimization.py runs a full experiment on a retrieval pipeline.

How did you test it?

Unit tests in tests/optimization/test_experiment.py with scripted optimizer models. hatch run test:unit, hatch run test:types and hatch run fmt-check pass locally.

Ran the new example end to end on the MultiHopRAG corpus (needs OPENAI_API_KEY):

hatch run test:python examples/retrieval_pipeline_optimization.py

I'd recommend starting the review with examples/retrieval_pipeline_optimization.py. It shows how a reference pipeline, an evaluator, eval cases and objectives come together in HarnessOptimizationExperiment, and prints each candidate as it is measured.

Notes for the reviewer

Checklist

@sjrl
sjrl requested a review from a team as a code owner October 8, 2026 07:42
@sjrl
sjrl requested review from julian-risch and removed request for a team October 8, 2026 07:42
@github-actions github-actions Bot added integration:agent-pack type:documentation Improvements or additions to documentation labels Oct 8, 2026
@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report (agent_pack)

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  integrations/agent_pack/src/haystack_integrations/agent_pack/optimization
  agent.py
  dataclasses.py
  experiment.py 83-85, 185-186, 237-238, 242, 336, 527, 535
  tools.py
Project Total  

This report was generated by python-coverage-comment-action

@sjrl
sjrl marked this pull request as draft October 8, 2026 07:43
@sjrl
sjrl removed the request for review from julian-risch October 8, 2026 07:43
@sjrl

sjrl commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

@julian-risch sorry meant to be a draft PR

@sjrl sjrl self-assigned this Oct 8, 2026
Base automatically changed from feat/harness-optimizer-agent to main October 15, 2026 11:10
@sjrl
sjrl force-pushed the feat/harness-optimization-experiment branch from 9632d65 to 2aa3740 Compare October 15, 2026 12:42
@sjrl
sjrl force-pushed the feat/harness-optimization-experiment branch from 2aa3740 to 79533c2 Compare October 20, 2026 09:37
@sjrl
sjrl requested a review from julian-risch October 22, 2026 11:57

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration:agent-pack type:documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant