#23The Orchestrator feedback loopMediumAgentic AI
The Orchestrator feedback loop
Background
The Orchestrator owns the retry loop: plan → execute → synthesize → critique. On FAIL with gaps, it re-executes only the gaps, accumulates findings, and re-critiques — up to max_retries extra attempts.
Problem statement
Implement orchestrate(query, plan, execute, synthesize, critique, max_retries=2).
Input
query— the research question.plan— callablequery -> list[str]of sub-questions.execute— callablelist[str] -> dict[str, str](findings for those sub-questions).synthesize— callable(query, all_findings) -> str(the answer).critique— callable(query, all_findings, answer) -> (passed: bool, gaps: list[str]).max_retries— extra attempts after the first.
Output
Returns (answer, passed, attempts). Per attempt (max_retries + 1 total):
- run
execute(sub_questions)and merge intoall_findings, answer = synthesize(query, all_findings),passed, gaps = critique(query, all_findings, answer),- if
passedorgapsis empty → return(answer, passed, attempt + 1), - else set
sub_questions = gapsand loop.
If the loop ends, return (answer, passed, max_retries + 1).
Examples
Example 1 — fail then pass on a targeted retry
plan -> ["a", "b", "c"]
execute -> {sq: f"F-{sq}" for sq in sub_questions}
critique -> attempt 1: (False, ["c"]); attempt 2: (True, [])
orchestrate(...) -> (answer, True, 2) # only ["c"] re-executed on attempt 2
Constraints
- First attempt executes all planned sub-questions; retries execute only
gaps. - Accumulate findings across attempts (don't discard prior results).
- Stop and return when
passedor nogaps, or aftermax_retries + 1attempts. attemptsis the number of attempts run.
Notes
- Re-searching only the gaps is the cost win: the Critic named exactly what failed, so the retry is small.
Python
Loading...
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •Reference example: passes on the first attempt
- •Sample: retries only the gap sub-question
- •Reference: findings accumulate across attempts