Below is my improved version of the prompt you provided. As an expert prompt engineer, I focused on making the prompt more precise, structured, and effective for an AI agent. Here's how I enhanced it:
- Clarified structure: I organized the prompt into clear sections (e.g., objectives, steps, priorities, and constraints) to make it easier for the AI agent to parse and execute without ambiguity.
- Added specificity without assumptions: I avoided assuming details about the code's functionality, domain, or dependencies, sticking strictly to the information you provided. However, I made the language more actionable and explicit to guide the agent effectively.
- Improved flow and readability: Used bullet points, numbered lists, and concise phrasing to reduce cognitive load on the agent, ensuring it's "top-notch" in guiding complex tasks.
- Incorporated best practices for prompts: Included explicit instructions for error handling (e.g., not breaking the project), verification steps, and outcome expectations to increase reliability and success rate.
- Maintained neutrality: Ensured the prompt doesn't impose unnecessary assumptions about the tasks, focusing only on refactoring as described.
Improved Prompt
Task Overview:
You are an expert software engineer tasked with refactoring a codebase to centralize all backend communication logic into a single controller file. Create a new Git branch named "refacto" and perform the specified refactorings. Your primary goal is to improve the controller logic without introducing any bugs or breaking existing functionality. Ensure the project remains fully operational after your changes.
Step-by-Step Instructions:
-
Prepare the Environment:
- Switch to a new Git branch called "refacto". If it already exists, create a new one based on the current branch to avoid conflicts.
- Thoroughly read and analyze the entire codebase and repository structure to gain a comprehensive understanding of the current implementation, including file dependencies, logic flows, and any potential edge cases.
-
Refactor the Controller Logic (Primary Priority):
- Make
simple_adapter.py the sole controller responsible for all requests to the backend service. This means:
- Move all backend request logic (e.g., HTTP requests) from other files into
simple_adapter.py.
- Specifically:
- Remove or integrate the functionality of
model_server.py into simple_adapter.py, as it is no longer needed. If integration is not feasible, delete model_server.py after ensuring its responsibilities are fully handled elsewhere.
- Identify and relocate all POST requests from
front_init_repo.py to simple_adapter.py.
- Identify and relocate all POST requests from
init_repo.py to simple_adapter.py.
- Ensure that
simple_adapter.py becomes the centralized point for all communications, including interactions with the frontend and backend services. No other files should initiate or handle these communications directly.
-
Additional Refactorings (Optional and Conditional):
- If you identify other areas for improvement (e.g., code duplication, outdated patterns, or better organization), perform those refactorings only if they:
- Do not alter the core functionality of the project.
- Maintain or enhance code readability, maintainability, and performance.
- Do not introduce new dependencies or remove existing ones without explicit justification in your commit messages.
- You are authorized to:
- Create new files or folders as needed (e.g., to organize related code).
- Rename files or folders for better clarity (e.g., if a file name conflicts with its new purpose).
- Update all dependencies and imports across the codebase to reflect these changes, ensuring that the project builds and runs successfully.
-
Quality and Verification Steps:
- Before committing changes, manually verify that:
- All tests (if any exist) pass successfully.
- The application behaves as expected, with no regressions in functionality.
- There are no unused imports, dead code, or broken references.
- Document your changes in commit messages, explaining what was refactored and why (e.g., "Moved POST requests from front_init_repo.py to simple_adapter.py for centralized control").
- If any issues arise that prevent completing the task without breaking the project, stop and note them in a comment or a new file (e.g., "refacto_notes.md").
Constraints and Guidelines:
- Do not make assumptions about the nature of the tasks, code specifics, or external systems; base all changes solely on the provided instructions and the existing codebase.
- Prioritize safety: If a change risks breaking the project, skip it or suggest an alternative in your documentation.
- Ensure the final state of the codebase is clean, well-organized, and ready for merging back into the main branch.
Expected Outcome:
After completing this task, the repository should have:
- A new "refacto" branch with all specified refactorings applied.
- Improved controller logic in
simple_adapter.py as the single source for backend communications.
- No disruptions to the project's overall functionality.
This improved prompt is now more robust, guiding the AI agent to produce high-quality results while minimizing risks. If you'd like further refinements, let me know!