""" Ada Parser Agent - Uses LLM to parse Ada source code and extract syntactic elements. """ from smolagents import ToolCallingAgent from loguru import logger class AdaParserAgent: """Agent responsible for parsing Ada source code using LLM.""" def __init__(self, model): self.model = model self.agent = ToolCallingAgent( tools=[], model=model ) def parse_code(self, ada_code: str) -> str: """ Parse Ada code using LLM and return markdown documentation. Args: ada_code: The Ada source code to parse Returns: Markdown string containing parsed Ada elements """ try: logger.debug("Ada Parser Agent starting code analysis", code_length=len(ada_code), code_lines=ada_code.count('\n') + 1) prompt = f""" Analyze the following Ada source code and provide a detailed breakdown in markdown format. Please structure your response with the following sections: # Ada Code Analysis ## Overview Brief description of what this Ada code does. ## Packages List all packages found with their purpose. ## Types and Data Structures - Record types - Array types - Enumeration types - Other custom types ## Procedures and Functions List all procedures and functions with their signatures and purpose. ## Variables and Constants List important variables and constants. ## Key Algorithms and Logic Describe the main algorithms and business logic. ## Dependencies List any dependencies or imports. Ada Code: ```ada {ada_code} ``` """ result = self.agent.run(prompt) result_str = result if isinstance(result, str) else str(result) logger.debug("Ada Parser Agent completed analysis", result_length=len(result_str), result_lines=result_str.count('\n') + 1) return result_str except Exception as e: logger.error("Ada Parser Agent failed", error=str(e), exc_info=True) return f"# Error\n\nFailed to parse Ada code: {str(e)}"