# Best Practices for Working with AI Agents: A Verification-Driven Approach

<span style="white-space: pre-wrap;">Working effectively with AI agents requires a fundamental shift in how we approach development. While AI can generate vast amounts of code instantly, the primary challenge is no longer authorship, but </span>**verification**<span style="white-space: pre-wrap;">. Modern software engineering with AI is less about crafting the "perfect prompt" and more about maintaining a </span>**disciplined, step-by-step process**.

Here is a comprehensive guide on how to optimally interact with AI agents, supported by real-world examples.

### 1. The Mindset Shift: Engineering Over Prompting

<span style="white-space: pre-wrap;">In the AI era, your core value shifts from typing speed to three essential competencies: </span>**Problem Definition, Decomposition, and Verification**.

- **You are the Architect, AI is the Typist:**<span style="white-space: pre-wrap;"> You are entirely responsible for the logic, security, and data flow.</span>
- **Avoid the "One-Shot Trap":**<span style="white-space: pre-wrap;"> A common beginner mistake is the "5-second high"—asking the AI to generate a complete application from a single sentence. This creates a massive </span>**technical debt of understanding**. If you cannot verify the output, you do not own the code, making it a liability rather than an asset.

### 2. Precise vs. Imprecise: The Power of Constraints

<span style="white-space: pre-wrap;">Your prompts must be </span>**highly precise when it comes to rules, constraints, and edge cases**. Ambiguity is the enemy of secure AI-generated code.

- **Example: The Server-Side Cart Calculator**<span style="white-space: pre-wrap;"> If you simply ask an AI to "build a shopping cart," you risk getting vulnerable client-side logic where a user could manipulate prices. Instead, you must define a strict trust boundary where the server is the single source of truth. A precise prompt establishes rigid constraints:</span>
    - **Ignore Client Prices:**<span style="white-space: pre-wrap;"> Explicitly state to never accept a price sent from the browser.</span>
    - **Validation Constraints:**<span style="white-space: pre-wrap;"> Define mathematical rules, such as $Quantity \\ge 1$ and $Tax/Discount \\ge 0$.</span>
    - **Order of Operations:**<span style="white-space: pre-wrap;"> Mandate that discounts must be applied </span>**before**<span style="white-space: pre-wrap;"> calculating tax.</span>
    - **Precision:**<span style="white-space: pre-wrap;"> Require the system to round money to 2 decimal places (or use integers/cents to avoid floating-point errors).</span>

### 3. Short vs. Long Prompts: The Iterative Workflow

<span style="white-space: pre-wrap;">Instead of writing one massive prompt, the most effective strategy is </span>**iterative prompting**. Start with a structured, medium-length prompt to define the goal and constraints, then transition to short, highly focused commands to build and refine the output incrementally.

- **Example: Rapid UI Iteration via Short Prompts**<span style="white-space: pre-wrap;"> During the development of a real-time events dashboard, a developer used extremely short prompts to polish the UI once the foundational context was established by the AI.</span>
    - <span style="white-space: pre-wrap;">The developer prompted: </span>**"make the bar chart smaller and horizontal. different colors for channels. randomly assigned."**.
    - Because the AI already understood the established architecture, this short prompt was enough for the agent to formulate a highly detailed implementation plan—creating a compact horizontal layout and using a deterministic hash-to-color function so that channels kept a stable pseudo-random color across page reloads.
    - <span style="white-space: pre-wrap;">The developer then followed up with rapid micro-prompts like </span>**"increase font contrast of labels of bar chart"**<span style="white-space: pre-wrap;"> and </span>**"the colors of the background and the overlays do not match the dark"**. The AI executed these perfectly by tuning CSS overlay tokens and applying theme-aware colors.

### 4. The 7-Step Verification Loop: Trust but Verify

<span style="white-space: pre-wrap;">Never assume the agent's first output is flawless. You must </span>**treat AI-generated code like code from a stranger—useful, but untrusted until proven by tests**. Fundamentals matter more than ever: security, data flow, and edge-case thinking are your primary tools.

<span style="white-space: pre-wrap;">To ensure quality and maintain control, adopt this repeatable </span>**7-Step Iterative Loop**:

1. **Define the Goal:**<span style="white-space: pre-wrap;"> State the objective in one clear sentence.</span>
2. **Establish Rules:**<span style="white-space: pre-wrap;"> List the non-negotiable technical constraints (what </span>**must**<span style="white-space: pre-wrap;"> be true).</span>
3. **Provide Examples:**<span style="white-space: pre-wrap;"> Define the exact expected Input $\\rightarrow$ Output mappings.</span>
4. **Identify Edge Cases:**<span style="white-space: pre-wrap;"> List "weird" or bad situations the system needs to handle.</span>
5. **Request a "Small Piece":**<span style="white-space: pre-wrap;"> Ask for a specific function or logic gate, not the whole system.</span>
6. **Demand Tests:**<span style="white-space: pre-wrap;"> Require the AI to provide runnable assertions to prove its logic.</span>
7. **Iterate:**<span style="white-space: pre-wrap;"> Treat failing tests as data. Use them as a "flashlight" to refine your next prompt and fix ambiguities in your rules.</span>

- **Example: Actively Verifying System Logic**<span style="white-space: pre-wrap;"> Verification isn't just about automated tests; it's also about actively questioning the AI's architectural decisions. When the AI added data filters to a dashboard's charts, the developer didn't just accept the code. They verified the logic by asking: </span>**"how do the filters work? do they filter visible data or data on the server?"**<span style="white-space: pre-wrap;">. Only after the AI confirmed that the filters were applied securely on the server side via SQL query parameters, did the developer instruct the AI to solidify this architecture: </span>**"document the changes do you?"**, ensuring the verified logic was permanently recorded in the project's README.