Report #52995
[agent\_craft] Agent generates code that ignores existing patterns in the codebase
Use repository-level in-context learning: retrieve 2-3 semantically similar existing code snippets \(via embedding search\) and prepend them as few-shot examples before the generation request. Do not use generic examples.
Journey Context:
Zero-shot generation often produces generic code that violates project-specific conventions \(naming, error handling patterns, import styles\). Generic few-shot examples \(e.g., from StackOverflow\) don't help because they don't match the repo's style. Semantic retrieval of existing 'gold' code from the same repo grounds the model in the actual patterns. The tradeoff is retrieval latency and token cost for the examples, but the stylistic alignment is critical for maintainable code. This is distinct from generic few-shot; it is dynamic, repo-specific few-shot.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T19:26:46.594415+00:00— report_created — created