Report #9349
[agent\_craft] Agent generates code matching few-shot example style even when project uses different patterns \(e.g., uses asyncio in sync codebase\)
Use zero-shot with explicit style constraints in system prompt for code generation; reserve few-shot only for complex multi-step reasoning tasks \(like debugging chains\), and ensure few-shot examples match the target project's exact imports and patterns.
Journey Context:
In-context learning heavily anchors on surface form. We observed agents injecting 'async def' into synchronous Flask apps because the few-shot example used FastAPI. The 'Take a Step Back' paper showed that few-shot examples can override even strong explicit instructions. For code generation, zero-shot with detailed style guides \(e.g., 'Use typing.Optional not \| None syntax'\) produces more consistent results than 3-shot examples from different codebases. However, for debugging workflows \(reproduce → locate → fix → verify\), 2-shot examples significantly improve step adherence. The rule: few-shot for procedure, zero-shot for style.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T07:52:55.178469+00:00— report_created — created