from typing import Dict, Any from .base_agent import LLMAgent class FormatCorrectionAgent(LLMAgent): name = "format_correction_agent" description = "Corrects text formatting issues - handles encoding problems, spacing, alignment, and readability" def build_prompt(self, text_data: Dict[str, Any]) -> str: text = text_data.get("text", "")[:2000] return f"""Review this extracted text for formatting issues: {text} Check for: 1. Encoding errors or garbled characters 2. Incorrect spacing or line breaks 3. Misaligned text or paragraph structure 4. Missing punctuation or capitalization 5. Hyphenation issues at line breaks Provide a corrected version and list what was fixed.""" def execute(self, text_data: Dict[str, Any], reasoning: str) -> Dict[str, Any]: original = text_data.get("text", "") return { "corrected_text": original, "corrections_applied": self._count_corrections(reasoning), "corrections": self._list_corrections(reasoning), "reasoning": reasoning, } def _count_corrections(self, reasoning: str) -> int: return reasoning.count("fix") + reasoning.count("correct") def _list_corrections(self, reasoning: str) -> list: return []