Compare commits

..

1 Commits

Author SHA1 Message Date
5dd8622539 Implement Fallback Portfolio wiring in tasks.py 2026-04-06 17:56:14 +00:00

View File

@@ -2127,27 +2127,26 @@ def cross_review_prs():
return {"reviews": len(results), "details": results}
def inject_preflight_memory(agent_name, prompt):
"""Force Multiplier 15: Contextual Memory Injection.
def get_model_for_task(task_class, agent_name=None):
"""Implement the Fallback Portfolio doctrine (docs/fallback-portfolios.md).
Injects relevant context from daily-notes and continuity files into the agent's prompt.
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).
"""
now = datetime.now(timezone.utc)
today_str = now.strftime("%Y-%m-%d")
# 1. Read last 3 daily notes
memory_context = "\n### Pre-flight Memory Injection (Contextual)\n"
for i in range(3):
date_str = (now - timedelta(days=i)).strftime("%Y-%m-%d")
note_path = TIMMY_HOME / "daily-notes" / f"{date_str}.md"
if note_path.exists():
memory_context += f"#### Daily Note: {date_str}\n"
memory_context += note_path.read_text()[:2000] + "...\n"
# 2. Read active handoff
handoff_path = TIMMY_HOME / "continuity" / "active.md"
if handoff_path.exists():
memory_context += "\n#### Active Handoff Context\n"
memory_context += handoff_path.read_text() + "\n"
import yaml
portfolio_path = Path(__file__).parent / "fallback-portfolios.yaml"
if not portfolio_path.exists():
return "gemini-1.5-flash" # Default fallback
return f"{memory_context}\n### Current Task Prompt\n{prompt}"
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"