"""04 CONDUCTOR (meta-prompting, Suzgun & Kalai style). One model, as conductor, decides which fresh "expert" instances of itself to consult, writes each expert's instructions, then synthesizes and verifies. Fresh eyes catch what tired eyes confirm: each expert call starts with zero shared context. Claude Code subagents are this pattern, in production. Paper: Suzgun & Kalai 2024, arxiv.org/abs/2401.12954. ES: Un director, muchos expertos frescos. Cada experto arranca sin contexto compartido. Run: python 04_conductor.py "should our startup charge for our metaprompting workshop series?" Needs: Claude Code installed (the `claude` CLI on your PATH). No API keys. """ import json, os, re, shutil, subprocess, sys MODEL = os.environ.get("METAPROMPT_MODEL", "haiku") def llm(prompt: str) -> str: exe = shutil.which("claude") if not exe: sys.exit("claude CLI not found. Install Claude Code first: https://claude.com/claude-code") r = subprocess.run([exe, "-p", prompt, "--model", MODEL], capture_output=True, text=True, encoding="utf-8") return (r.stdout or "").strip() def main(): task = sys.argv[1] if len(sys.argv) > 1 else "should we open-source our internal prompt library?" # Round 1 - the conductor writes the experts' prompts. This is the metaprompt. plan_raw = llm( "You are a conductor managing expert consultants. For the task below, choose 2 or 3 " "experts with DIFFERENT specialties and write each one a specific, self-contained " "instruction. The experts cannot see the task, this conversation, or each other; " "their instruction is all they get.\n\n" f"TASK: {task}\n\n" 'Reply ONLY with JSON: [{"name": "...", "instruction": "..."}]' ) m = re.search(r"\[.*\]", plan_raw, re.S) experts = json.loads(m.group(0)) print("== CONDUCTOR'S PLAN ==") for e in experts: print(f" {e['name']}: {e['instruction'][:90]}") # Round 2 - each expert runs as a FRESH call. No shared context. That is the point. answers = [] for e in experts: print(f"\n== {e['name'].upper()} (fresh instance) ==") a = llm(e["instruction"] + "\nBe concrete. Max 5 sentences.") answers.append((e["name"], a)) print(a) # Round 3 - the conductor synthesizes and verifies. print("\n== CONDUCTOR'S SYNTHESIS ==") print(llm( f"You are the conductor. Original task: {task}\n\n" + "\n\n".join(f"[{n}]\n{a}" for n, a in answers) + "\n\nSynthesize the expert reports into one recommendation. Flag any point where " "experts contradict each other. Max 6 sentences." )) if __name__ == "__main__": main()