Step-by-step Master Guide for Building Features with AI Coding Agents
Here is your step-by-step master guide for building features with AI coding agents before you start a coding project or feature using AI assistance (like GitHub Copilot, Claude Code, or AWS Q Developer).
Phase 1: Structuring the Repository for Maximum AI Context
Before writing a single line of code, the AI agent needs a clean environment to "understand" your system architecture.
- 1. Establish an AI Rules File (
.cursorrulesorCLAUDE.md)- Place a context rule file in the root of the repository.
- Define architectural constraints, coding standards, language versions, and testing requirements.
- Example: Specify "Python 3.12, strict type hints, Pydantic v2 for schema validation, Pytest for unit tests, no raw SQL (use SQLAlchemy ORM)."
- 2. Implement a Modular, Clean-Architecture Folder Structure
- Keep directory structures predictable so the AI agent doesn't hallucinate paths or mix concerns:
/src/domain/(Data models, schemas, entities)/src/services/(Business logic, orchestration)/src/adapters/(Database, API clients, S3 connectors)/tests/(Unit and integration test suites)
- 3. Provide In-Repo Sample Patterns (Few-Shot Prompting via Code)
- AI agents copy existing styles. If you have one well-written adapter or service with clean error handling and docstrings, the agent will mirror that exact quality for new features.
Phase 2: Prompting Strategies That Produce Superior Code
When working with AI coding tools during an interview or production sprint, vague prompts yield poor code. Use these proven prompting patterns:
- Strategy 1: Spec-First / Test-Driven Prompting (TDD)
- Prompt Pattern: Do not ask the agent to write the feature code first. Prompt it to write the type definitions and unit tests based on your functional spec.
- Why it works: Once the AI generated tests pass or fail against defined types, it has a rigid boundary to implement the business logic correctly.
- Strategy 2: The "Chain-of-Thought with Architecture Constraints" Strategy
- Prompt Pattern: "Explain your technical approach in 3 bullet points before generating code. Ensure you address concurrency limits and input validation using Pydantic."
- Why it works: Forces the agent to reason about edge cases before committing to a code syntax tree.
- Strategy 3: Context-Slicing via File Tagging
- Avoid attaching the entire codebase to a prompt context window. Tag only the specific interface, database model, and relevant test file (e.g.,
@models.py @service.py).
Phase 3: Step-by-Step Scenario Walkthrough eg.
Scenario: When you start to use an AI Coding Agent to build a resilient, rate-limited telemetry ingestion module that writes valid metrics to an S3-compatible store and handles bad payloads via a Dead Letter Queue (DLQ).
Step 1: Define the Blueprint (Human Strategy & Spec)
- First, create the input contract using Pydantic, define an abstract interface for storage, write unit tests for valid and malformed payloads, and then prompt the AI agent to implement the service logic.
Step 2: Prompt for Type Schemas & Contracts
- Prompt to AI:"Generate a Pydantic v2 model named
TelemetryMetriccontainingdevice_id(str),timestamp(float),metric_name(str), andvalue(float). Add validation ensuringvalueis non-negative anddevice_idmatches regex^[a-zA-Z0-9-]+$." - Human Review: Verify the generated model. Ensure types match expectations.
Step 3: Prompt for Test-Driven Development (TDD)
- Prompt to AI:"Write a Pytest suite for a class
TelemetryIngestor. Write test cases for: 1) Valid payload processing, 2) Malformed JSON/schema validation failure sending payload to DLQ, and 3) Duplicate timestamp deduplication." - Human Review: Check if the unit tests cover edge cases (e.g., boundary values, network exceptions).
Step 4: Implement Service Logic via Iterative AI Prompting
- Prompt to AI:"Implement
TelemetryIngestorusing theTelemetryMetricschema. Implement an in-memory batching mechanism that triggers a flush every 5 items or 10 seconds. Use Python structured logging. Refer to test constraints." - Execution: Run the tests using the terminal tool. If tests fail, feed the stack trace back to the AI agent: "Tests failed with error X. Fix the bug in
TelemetryIngestor.flush()."
Step 5: Refactor for Security, Resilience, and AWS Best Practices
- Prompt to AI:"Refactor
TelemetryIngestorto handle thread-safe batch flushing and ensure no sensitive API tokens are logged in plain text."
Phase 4: Where Human Judgment Still Matters
AI agents excel at syntax generation, boilerplate, unit tests, and local refactoring. However, as a programmer, you must demonstrate where Human Judgment supersedes the AI:
- Architecture & System Boundaries:
- AI limitation: An AI agent will write whatever code you ask for, even if a monolith/microservice pattern is wrong for the use case.
- Human role: Deciding where compute should run (e.g., Lambda vs. EKS), how data flows, and defining state boundaries.
- Security & Zero Trust:
- AI limitation: Agents frequently hardcode fallback secrets, disable SSL verification to pass tests quickly, or over-privilege IAM roles.
- Human role: Enforcing least-privilege access, auditing KMS encryption configurations, and preventing data leakage.
- Cost Optimization (Frugality) & Performance Trade-offs:
- AI limitation: An agent might suggest an expensive polling algorithm or inefficient database query that works locally but fails or burns budget at scale.
- Human role: Evaluating trade-offs like eventual consistency vs. strong consistency, caching layers (ElastiCache/Redis), and batching strategies.
- Edge-Case Analysis & Real-World Failure Modes:
- AI limitation: Agents struggle with complex failure modes like network partitions, thundering herd problems, or distributed lock contention.
- Human role: Designing idempotency keys, circuit breakers, and backpressure mechanisms.
Summary Checklist for Live Coding with AI Assist
| Phase | Human Action | AI Agent Action |
| 1. Setup | Set folder structure, define .cursorrules / architecture constraints. | Context ingestion. |
| 2. Spec | Define Pydantic models, API contracts, and edge-case boundaries. | Generate data models & schemas. |
| 3. Tests | Review test scenarios for completeness. | Generate Pytest/JUnit test cases. |
| 4. Code | Review code for security flaws, memory leaks, and architectural fit. | Generate service logic to pass tests. |
| 5. Audit | Perform security audit, IAM check, cost review, and edge-case check. | Execute refactoring commands based on human feedback. |
and https://cursorrules.org/