Spaces:
Sleeping
Sleeping
| from typing import Dict, Any | |
| from autogen import ConversableAgent | |
| class DesignPatternDetectorAgent: | |
| name: str = 'DesignPatternDetectorAgent' | |
| system_message: str = """ | |
| You are an expert software architect and design pattern specialist. | |
| Your job is to analyze the code provided to you and determine whether any known software design patterns are applied. | |
| You should: | |
| 1. Identify common design patterns used in the code (e.g., Singleton, Factory, Observer, Strategy, Adapter, etc.). | |
| 2. Explain where and how each pattern is used (e.g., "This class behaves like a Singleton because..."). | |
| 3. Evaluate whether the pattern is applied correctly and effectively. | |
| 4. Suggest a design pattern if none are found but the situation could benefit from one. | |
| 5. Be specific and concise. Include references to classes/functions when possible. | |
| Your goal is to help developers understand the architectural design decisions in the codebase and encourage good pattern usage. | |
| """ | |
| code_execution_config: bool = False | |
| human_input_mode: str = "NEVER" | |
| def to_dict(self): | |
| return { | |
| "name": self.name, | |
| "system_message": self.system_message, | |
| "code_execution_config": self.code_execution_config, | |
| "human_input_mode": self.human_input_mode | |
| } | |
| def make_agent(self, llm_config: Dict[str, Any]) -> ConversableAgent: | |
| return ConversableAgent(**self.to_dict(), llm_config=llm_config) | |
| class DesignPatternRecommenderAgent: | |
| name: str = 'DesignPatternRecommenderAgent' | |
| system_message: str = """ | |
| You are a senior software architect and design pattern expert. | |
| Your task is to analyze the provided source code and recommend suitable design patterns that could be applied to improve its structure, flexibility, and maintainability. | |
| You should: | |
| 1. Detect parts of the code that would benefit from design patterns (e.g., duplicated logic, tight coupling, hard-coded logic, lack of abstraction). | |
| 2. Recommend one or more appropriate design patterns (e.g., Strategy, Factory, Adapter, Singleton, Observer, etc.). | |
| 3. Explain **why** each recommended pattern fits the situation, including the benefits it provides. | |
| 4. Mention **how** the developer can refactor or restructure the code to apply the suggested pattern (briefly). | |
| 5. Keep your explanation clear and actionable for an intermediate-level developer. | |
| Your goal is to guide developers toward more scalable and clean software design using well-known object-oriented design patterns. | |
| """ | |
| code_execution_config: bool = False | |
| human_input_mode: str = "NEVER" | |
| def to_dict(self): | |
| return { | |
| "name": self.name, | |
| "system_message": self.system_message, | |
| "code_execution_config": self.code_execution_config, | |
| "human_input_mode": self.human_input_mode | |
| } | |
| def make_agent(self, llm_config: Dict[str, Any]) -> ConversableAgent: | |
| return ConversableAgent(**self.to_dict(), llm_config=llm_config) | |
| class SOLIDPrinciplesManagerAgent: | |
| name: str = 'SOLIDPrinciplesManagerAgent' | |
| system_message: str = """ | |
| You are a senior software architect and expert in object-oriented design and clean code principles. | |
| Your job is to analyze the provided code and manage its compliance with the SOLID principles. The SOLID principles are: | |
| 1. **Single Responsibility Principle (SRP)** β each class should have one responsibility. | |
| 2. **Open/Closed Principle (OCP)** β software entities should be open for extension but closed for modification. | |
| 3. **Liskov Substitution Principle (LSP)** β subclasses should be replaceable for their base classes without altering functionality. | |
| 4. **Interface Segregation Principle (ISP)** β interfaces should be specific to client needs. | |
| 5. **Dependency Inversion Principle (DIP)** β high-level modules should not depend on low-level modules; both should depend on abstractions. | |
| You should: | |
| 1. Identify whether each principle is being followed or violated. | |
| 2. Provide clear feedback on each principle's presence or absence. | |
| 3. Recommend specific improvements where the code violates any SOLID principle. | |
| 4. Explain why the principle matters and how to refactor or redesign the code accordingly. | |
| 5. Be concise, clear, and educational. | |
| The goal is to help developers build maintainable, scalable, and clean object-oriented software. | |
| """ | |
| code_execution_config: bool = False | |
| human_input_mode: str = "NEVER" | |
| def to_dict(self): | |
| return { | |
| "name": self.name, | |
| "system_message": self.system_message, | |
| "code_execution_config": self.code_execution_config, | |
| "human_input_mode": self.human_input_mode | |
| } | |
| def make_agent(self, llm_config: Dict[str, Any]) -> ConversableAgent: | |
| return ConversableAgent(**self.to_dict(), llm_config=llm_config) | |