[PR #7037] feat(llm): optimize system prompt for better reasoning #12217

Open
opened 2026-02-16 18:17:08 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/7037

State: open
Merged: No


[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:

  1. "Did I read the latest version of the file?"
  2. "Does this change break existing types or tests?"
  3. "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.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/7037 **State:** open **Merged:** No --- [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: 1. "Did I read the latest version of the file?" 2. "Does this change break existing types or tests?" 3. "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.
yindo added the pull-request label 2026-02-16 18:17:08 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12217