"""Load and cache prompt templates with LRU caching.""" from functools import lru_cache from pathlib import Path @lru_cache(maxsize=8) def _load_prompt(agent: str, prompt_type: str) -> str: """Load a prompt template from file with LRU caching. Args: agent: Agent name ('profiler', 'reproducer', 'analyzer') prompt_type: Prompt type ('system' or 'task') Returns: Prompt content as string Raises: FileNotFoundError: If prompt file doesn't exist """ prompt_path = ( Path(__file__).parent.parent / agent / "prompts" / f"{prompt_type}.txt" ) if not prompt_path.exists(): raise FileNotFoundError(f"Prompt file not found: {prompt_path}") return prompt_path.read_text() def get_profiler_system_prompt() -> str: """Get the Profiler system prompt.""" return _load_prompt("profiler", "system") def get_profiler_task_prompt( paper_content: str, token_limit: int, container_path: str = "/work/distilled_{token_limit}.txt", ) -> str: """Get the Profiler task prompt with template variables filled. Args: paper_content: The paper text to extract theorem from token_limit: Maximum tokens for distilled summary container_path: Path to the file in the container Returns: Formatted task prompt """ template = _load_prompt("profiler", "task") return template.format( paper_content=paper_content, token_limit=token_limit, container_path=container_path, ) def get_profiler_compress_prompt( summary: str, token_limit: int, feedback: str = "", container_path: str = "/work/distilled_{token_limit}.txt", ) -> str: """Get the Profiler compress prompt for cascaded compression. Args: summary: The summary text to compress further token_limit: Target tokens for compressed summary feedback: Optional feedback from previous attempt container_path: Path to the file in the container Returns: Formatted compression prompt """ template = _load_prompt("profiler", "compress") return template.format( paper_content=summary, token_limit=token_limit, feedback=feedback, container_path=container_path, ) def get_reproducer_system_prompt() -> str: """Get the Reproducer system prompt.""" return _load_prompt("reproducer", "system") def get_reproducer_task_prompt(distilled_summary: str) -> str: """Get the Reproducer task prompt with template variables filled. Args: distilled_summary: The distilled theorem summary Returns: Formatted task prompt """ template = _load_prompt("reproducer", "task") return template.format(distilled_summary=distilled_summary) def get_analyzer_system_prompt() -> str: """Get the Analyzer system prompt.""" return _load_prompt("analyzer", "system") def get_analyzer_task_prompt( original_theorem: str, derived_theorem: str, distilled_summary: str ) -> str: """Get the Analyzer task prompt with template variables filled. Args: original_theorem: The original theorem statement derived_theorem: The newly derived theorem and proof distilled_summary: The distilled summary for reference Returns: Formatted task prompt """ template = _load_prompt("analyzer", "task") return template.format( original_theorem=original_theorem, derived_theorem=derived_theorem, distilled_summary=distilled_summary, )