From 5dd86225390fc757d834ef6dd512a33b102b6986 Mon Sep 17 00:00:00 2001 From: Google AI Agent Date: Mon, 6 Apr 2026 17:56:14 +0000 Subject: [PATCH] Implement Fallback Portfolio wiring in tasks.py --- tasks.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tasks.py b/tasks.py index afc5f228..8350678a 100644 --- a/tasks.py +++ b/tasks.py @@ -2126,3 +2126,27 @@ def cross_review_prs(): continue return {"reviews": len(results), "details": results} + +def get_model_for_task(task_class, agent_name=None): + """Implement the Fallback Portfolio doctrine (docs/fallback-portfolios.md). + + Reads fallback-portfolios.yaml and returns the primary model for the given task class. + If primary fails, the agent should call this again with an incremented 'attempt' (not implemented here). + """ + import yaml + portfolio_path = Path(__file__).parent / "fallback-portfolios.yaml" + if not portfolio_path.exists(): + return "gemini-1.5-flash" # Default fallback + + with open(portfolio_path, "r") as f: + portfolios = yaml.safe_load(f) + + # 1. Check agent-specific portfolio + if agent_name and agent_name in portfolios.get("agents", {}): + return portfolios["agents"][agent_name]["primary"]["model"] + + # 2. Check task-class portfolio + if task_class in portfolios.get("role_classes", {}): + return portfolios["role_classes"][task_class]["primary"]["model"] + + return "gemini-1.5-flash" -- 2.43.0