agenticAi / agents /error_fixing_agent.py
Cline
Initial commit
0af0a55
from typing import Dict, Any, List
from loguru import logger
from utils.llm_orchestrator import LLMOrchestrator
class ErrorFixingAgent:
def __init__(self, llm_api_key: str):
"""Initialize the Error Fixing Agent."""
logger.info("Initializing ErrorFixingAgent")
self.llm_orchestrator = LLMOrchestrator(llm_api_key)
self.capabilities = [
"error_fixing",
"patch_generation",
"code_repair"
]
self.setup_logger()
def setup_logger(self):
"""Configure logging for the agent."""
logger.add("logs/error_fixing_agent.log", rotation="500 MB")
async def fix_errors(
self, code: str, error_messages: List[str]) -> Dict[str, Any]:
"""Generate code patches to fix detected errors."""
logger.info(f"Attempting to fix errors: {error_messages}")
try:
prompt = f"""
Fix the following errors in the code:
{code}
Errors:
{chr(10).join(error_messages)}
Provide only the corrected code, without any introductory or explanatory text.
"""
fixed_code = await self.llm_orchestrator.generate_completion(prompt)
logger.info(f"Code with fixes generated:\n{fixed_code}")
return {
"status": "success",
"fixed_code": fixed_code
}
except Exception as e:
logger.error(f"Error fixing code: {str(e)}")
return {
"status": "error",
"message": str(e)
}