Report #64281
[agent\_craft] Agent produces inconsistent code style or fails to follow project conventions despite explicit instructions
Use 'retrieval-based few-shot' rather than static examples: Dynamically retrieve 2-3 relevant code snippets from the existing codebase that are semantically similar to the task \(using embeddings\), prepend them as few-shot examples, and append the instruction 'Follow the patterns and style shown above. Do not deviate from the conventions in these examples.' Use zero-shot only when the codebase is empty or conventions are unknown.
Journey Context:
Static few-shot examples in system prompts become stale and may conflict with the target codebase's conventions \(e.g., using snake\_case when the project uses camelCase\). Zero-shot often misses implicit patterns \(naming conventions, error handling patterns, import ordering\). Retrieval-based few-shot grounds the agent in the actual project's reality. The tradeoff is latency \(embedding lookup\) vs accuracy. Studies show 2-3 examples is the sweet spot; more causes overfitting to the examples rather than the task. This is superior to simple 'follow conventions' instructions which are too vague to operationalize.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T14:22:57.872169+00:00— report_created — created