Stop Fighting Your LLM: Software Engineering Principles for Agentic Coding
TL;DR: Effective AI-assisted coding requires moving beyond “vibe coding” and applying core engineering principles: smart task sizing, active context control, and systematic planning. By treating the LLM as a collaborative agent with specific constraints, developers can maintain high-quality codebases and avoid the “mega-prompt” death spiral.
We’ve all seen the “vibe coding” demos: a developer asks an LLM to “build me a Twitter clone,” and a few minutes later, a buggy, unmaintainable mess appears. It’s impressive for five minutes, but it breaks the second you need to change a database schema or fix a subtle race condition.
The reality of 2026 is that AI agents like Antigravity, Claude Code, and GitHub Copilot are standard tools. But if you treat them like magic wands, you’re going to get hit by the “stochastic brick wall.” To actually ship production software with AI, you need to stop chatting and start engineering.
What is AI Stack Engineering?
AI Stack Engineering is the practice of applying traditional software engineering constraints—modularity, planning, and state management—to the interaction between human developers and AI coding agents.
It is the middle ground between “manual coding” and “fully autonomous black boxes.” You aren’t just writing code; you’re managing the information flow and task decomposition for an agent that is brilliant at syntax but prone to losing the plot if the context gets too heavy.
Task Sizing: The End of the Mega-Prompt
The biggest mistake developers make with LLMs is asking for too much at once. We call this the “Mega-Prompt Trap.” When you ask an LLM to “Refactor the entire auth system and add a new dashboard,” you are practically begging for hallucinations.
In engineering terms, this is a violation of the Single Responsibility Principle.
The Fix: Small, Atomic Tasks. Break your requirements down into chunks that fit within the agent’s optimal reasoning window. If a task takes more than 50 lines of code to explain, it’s probably too big.
- Wrong: “Implement the entire billing flow.”
- Right: “1. Create the Stripe customer schema. 2. Implement the webhook handler for successful payments. 3. Update the user profile UI to show the ‘Premium’ badge.”
Context Control: Managing the Agent’s “Working Memory”
An LLM is only as good as the context it currently holds. If you feed it 50 files it doesn’t need, you’re adding noise that dilutes its “attention.” Conversely, if you don’t give it the schema.ts file when it’s writing a database query, it’s going to hallucinate field names.
The Fix: Strategic File Selection. You must be the curator of the agent’s context.
- Use tools like
view_fileonly on relevant files. - Clear out old context between major tasks.
- Provide “Anchor Files” (like a
DESIGN.mdorARCHITECTURE.md) that give the agent a high-level map of the system without overwhelming it with implementation details.
Systematic Planning: Why Design Concepts Matter
Most AI failures happen because the agent starts writing code before it understands the intent.
The Fix: The “Plan First” Workflow. Before the agent touches a single .ts file, force it to generate an implementation plan. This serves two purposes:
- Verification: You can catch design flaws before the agent writes 500 lines of bad code.
- Alignment: It ensures the agent has “reasoned through” the dependencies (e.g., “I need to update the API before I update the frontend”).
If your agent isn’t outputting a TODO list before it starts typing, you’re just vibe-coding.
Comparison: Vibe Coding vs. Engineering-Driven AI
| Feature | Vibe Coding | Engineering-Driven AI |
|---|---|---|
| Input | Vague, large requests (“Make it work”) | Atomic, specific tasks (“Update X to do Y”) |
| Context | Everything or nothing | Curated, relevant files only |
| Planning | Direct implementation | Implementation Plan -> Review -> Task List |
| Result | “Looks okay” (Fragile) | Technically sound, documented, and testable |
FAQ: Mastering the Agentic Workflow
Q: Does this mean I have to do more work? A: Initially, yes. Planning takes time. But it saves hours of debugging “hallucinated bugs” that arise from oversized prompts and messy context.
Q: Can’t the AI just figure out the plan itself? A: It can generate a draft, but you must review it. You are the Architect; the AI is the Senior Engineer. Never skip the Architect’s review.
Q: What is the best “Task Size” for an LLM? A: Aim for tasks that can be completed in 5-15 minutes of human coding time. If you can’t describe the task in 3 sentences, split it.
Q: How do I manage context for large repos? A: Use a map.md or agents.md file that describes the directory structure and main logic points. Point the agent to this file first.
Q: Why does my AI keep repeating the same mistake? A: This is usually a context pollution issue. The mistake is in the “history.” Clear the session or explicitly correct the agent and have it update its internal plan.
Stop chatting, start shipping. #AIEngineering #SoftwareEngineering #AgenticWorkflow #MattPocock #Antigravity