opencode
opencode copied to clipboard
feat(llm): optimize system prompt for better reasoning
[FEATURE]: add self-reflection mechanism to improve code reliability #7047
Feature Description
To mitigate common AI coding errors such as overwrite conflicts and type mismatches, I propose adding a "Self-Reflection" mechanism to the main system prompt (anthropic.txt).
Problem
The current agent sometimes executes tool calls impulsively without verifying the context, leading to:
- Overwrite Conflicts: Editing an outdated version of a file.
- Type Errors: Breaking existing TypeScript definitions.
- Over-engineering: Implementing complex solutions when simple ones exist.
Proposed Solution
Add a Critical Thinking & Self-Correction section to the system prompt that forces the agent to ask itself three critical questions before executing Edit or Write tools:
- "Did I read the latest version of the file?"
- "Does this change break existing types or tests?"
- "Is there a simpler way to do this?"
Expected Benefit
- Reliability: Significantly reduces the rate of buggy code generation.
- Safety: Prevents accidental data loss from overwriting.
- Quality: Encourages idiomatic and simple code.
I have implemented this change in my fork and verified it locally. A PR will follow shortly.