Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/maca/agents/coder.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ def run(self, task_description, plan, repo_files_content=None, history=None):

def _build_system_instruction(self):
return (
"You are a Software Coder Agent. Your job is to implement the changes outlined in the plan.\n\n"
"You are a Software Coder Agent. Your job is to implement the changes outlined in the plan "
"while strictly adhering to clean code practices.\n\n"
"CLEAN CODE GUIDELINES:\n"
"- Modularity: Break code into small, single-purpose functions/classes.\n"
"- Readability: Use clear, descriptive, and consistent variable/function names.\n"
"- Documentation: Include concise docstrings and inline comments explaining complex logic.\n"
"- Type Safety: Use type hints for function parameters and return types where applicable.\n"
"- Error Handling: Handle potential exceptions gracefully (no bare except blocks).\n"
"- Simplicity: Avoid over-engineering, code duplication, or spaghetti code.\n\n"
"CRITICAL: You MUST write the file identifier line in the EXACT format: [FILE: path/to/file.ext]\n"
"Do NOT use markdown headers (like '## FILE: ...' or '# FILE: ...'), bullet points, or bold text. "
"The parser WILL fail if you do not use square brackets [FILE: ...].\n\n"
Expand All @@ -32,7 +40,7 @@ def _build_prompt(self, task_description, plan, repo_files_content, history):
f"User Task: {task_description}{history_context}\n\n"
f"Implementation Plan:\n{plan}\n"
f"{files_context}\n"
"Please implement the changes and output the files using the requested [FILE: path] format."
"Please implement the changes using clean code principles, and output the files using the requested [FILE: path] format."
)

def _format_history(self, history):
Expand Down
15 changes: 11 additions & 4 deletions src/maca/agents/reviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ def run(self, task_description, generated_files, history=None):

def _build_system_instruction(self):
return (
"You are a Senior Reviewer Agent. Your job is to review the code generated for the task. "
"Look for syntax errors, logical bugs, missing imports, or edge cases. "
"If changes are needed, explain why and output the corrected files.\n\n"
"You are a Senior Reviewer Agent. Your job is to review the code generated for the task "
"with a strict focus on clean code practices and technical correctness.\n\n"
"CLEAN CODE AUDITING CRITERIA:\n"
"1. Readability & Naming: Are variables, functions, and classes descriptively and consistently named?\n"
"2. Modularity & Design: Is the code modular? Are functions doing only one thing (Single Responsibility)?\n"
"3. Documentation & Type Hints: Are public interfaces properly documented with docstrings and type hints?\n"
"4. Correctness & Quality: Are there syntax errors, logic bugs, bare excepts, or code duplication?\n\n"
"If you find issues that violate these clean code principles or correctness, explain the issues clearly, "
"and output the corrected files.\n\n"
"CRITICAL: You MUST write the file identifier line in the EXACT format: [FILE: path/to/file.ext]\n"
"Do NOT use markdown headers (like '## FILE: ...' or '# FILE: ...'), bullet points, or bold text. "
"The parser WILL fail if you do not use square brackets [FILE: ...].\n\n"
Expand All @@ -33,7 +39,8 @@ def _build_prompt(self, task_description, generated_files, history):
return (
f"User Task: {task_description}{history_context}\n\n"
f"Generated Files to Review:\n{files_context}"
"Please review the code, suggest improvements, and output corrected files if needed."
"Please review the code for correctness, logical bugs, and clean code practices. "
"Suggest improvements and output corrected files if needed."
)

def _format_history(self, history):
Expand Down
34 changes: 34 additions & 0 deletions tests/test_agents.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import unittest
from unittest.mock import MagicMock

from maca.agents.coder import CoderAgent
from maca.agents.reviewer import ReviewerAgent


class TestAgentsPrompts(unittest.TestCase):
def setUp(self):
self.mock_client = MagicMock()
self.coder = CoderAgent("Coder", self.mock_client)
self.reviewer = ReviewerAgent(self.mock_client)

def test_coder_system_instruction_clean_code(self):
sys_inst = self.coder._build_system_instruction()
self.assertIn("clean code practices", sys_inst)
self.assertIn("CLEAN CODE GUIDELINES", sys_inst)
self.assertIn("Modularity", sys_inst)
self.assertIn("Type Safety", sys_inst)

def test_coder_prompt_clean_code(self):
prompt = self.coder._build_prompt("test task", "test plan", {}, [])
self.assertIn("clean code principles", prompt)

def test_reviewer_system_instruction_clean_code(self):
sys_inst = self.reviewer._build_system_instruction()
self.assertIn("clean code practices", sys_inst)
self.assertIn("CLEAN CODE AUDITING CRITERIA", sys_inst)
self.assertIn("Readability & Naming", sys_inst)
self.assertIn("Single Responsibility", sys_inst)

def test_reviewer_prompt_clean_code(self):
prompt = self.reviewer._build_prompt("test task", {}, [])
self.assertIn("clean code practices", prompt)
Loading