Guide
Prompt engineering for AI coding agents
A practical guide to prompt engineering for AI coding agents, including task scoping, context windows, review loops, and repeatable workflows.
Quick framework
- Scope tasks to a single, reviewable change.
- Provide the exact files and context the agent needs.
- Specify constraints: language version, style, test framework.
- Require the agent to run tests and report results.
- Review diffs before merging — never trust generated code blindly.
Prompt patterns that work
| Pattern | Example |
|---|---|
| Task + constraints | "Add a rate limiter to the API using token bucket. Use Redis for state. Include unit tests with pytest." |
| Refactor with tests | "Extract the auth logic from routes.py into auth.py. Run existing tests and add coverage for edge cases." |
| Bug fix with reproduction | "Fix the N+1 query in User.get_posts(). Here's the failing test. Keep the fix minimal." |
| Explain then edit | "First explain the current caching strategy, then propose and implement improvements." |