File size: 1,278 Bytes
734b5b4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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 []