LevelUpWith

Explore / AI Coder: Claude Code & Coding Agents / Lesson 1

Lesson 1: Mental Models of AI-Assisted Engineering

Understand how coding agents think, where context windows break down, and how to shift from manual coding to specification-driven development.

Free to read, no account needed. Part of AI Coder: Claude Code & Coding Agents.

By the end of this level you'll be able to

  • Contrast inline autocomplete with autonomous agent workflows
  • Identify context window degradation pitfalls in large codebases
  • Formulate precise, testable specifications for LLM consumption

Level 1: Mental Models of AI-Assisted Engineering

Welcome to modern AI-assisted software engineering. To get real leverage out of coding agents, you need to discard the idea that AI is just a faster typist or a magical senior developer. Instead, think of an AI coding agent as a brilliant, hyper-fast junior engineer with near-zero long-term memory who needs precise system boundaries and clear verification steps.

Let's break down how AI coding tools actually work, where their mental models fail, and how you should structure work for them.


1. Autocomplete vs. Autonomous Agent Workflows

Software engineering with AI generally falls into two distinct operational modes:

Mode A: Inline Autocomplete (Predictive Text)

Inline autocomplete operates directly at your cursor. It looks at the current file (and a small slice of recently opened tabs) and asks the language model: "Given these prior 2,000 tokens, what are the next 50 tokens the developer will type?"

# You type:
def calculate_monthly_churn(active_users_start, churned_users):
    # Model suggests:
    if active_users_start == 0:
        return 0.0
    return (churned_users / active_users_start) * 100.0

Autocomplete is passive. It stops generating as soon as a single statement or block finishes. You drive the architecture, the directory structure, and the debugging.

Mode B: Autonomous Coding Agents (Loop Execution)

An agent does not just emit text into an open editor. An agent operates inside a ReAct loop (Reasoning + Acting) with access to system tools:

  1. Inspect: Read workspace files, run git status, or list directories.
  2. Plan: Formulate steps to achieve a high-level goal.
  3. Act: Write/modify files or run shell commands (e.g., npm test, pytest).
  4. Observe: Read terminal output or compiler errors from its own actions.
  5. Iterate: Self-correct until the goal or test passes.
User Prompt: "Add a rate-limiter middleware to the checkout API"
      │
      ▼
┌────────────── Agent Execution Loop ──────────────┐
│  1. Tool Call: grep "/api/checkout" routes/      │
│  2. Tool Call: read_file("routes/checkout.py")   │
│  3. LLM Reasoning: Plan Redis token bucket logic │
│  4. Tool Call: patch_file("routes/checkout.py")  │
│  5. Tool Call: run_command("pytest tests/")      │
│  6. Error observed: 429 status code misconfigured│
│  7. Tool Call: patch_file("routes/checkout.py")  │
│  8. Tool Call: run_command("pytest tests/") -> PASS
└──────────────────────────────────────────────────┘
      │
      ▼
 Agent: "Rate limiter added and verified against test suite."

2. Context Window Degradation & Pitfalls

Large Language Models (LLMs) have finite context windows (e.g., 128k to 200k tokens). Even when context windows are enormous, performance degrades as context fills up. Understanding these failure modes saves hours of debugging:

The "Lost in the Middle" Effect

LLMs pay the most attention to tokens at the very beginning (system prompt) and the very end (immediate user prompt) of their context window. Critical functions, types, or constraints stuffed in the middle of 80,000 tokens of dumped repo context are frequently overlooked.

Context Poisoning & Compounding Errors

If an agent attempts a fix that fails, and that failure generates a 500-line stack trace in the context, the model now has buggy code and error logs polluting its working memory. In the next turn, it may treat its own broken assumptions as ground truth.

Stale State Hallucinations

If you modify a file locally while an agent is running, or if the agent does not refresh its tool read, it will reason over obsolete code. Always ensure your agent inspects current disk state before editing.


3. Specification-Driven Development

When collaborating with an agent, vague instructions produce generic, brittle code. The shift to Specification-Driven Development means defining inputs, schemas, constraints, and testable acceptance criteria before asking for implementation.

The Anti-Pattern: Vague Prompting

"Build an auth endpoint for my app that handles logins and tokens."

Result: The model invents arbitrary JWT expiry times, skips password hashing parameters, picks random database drivers, and writes zero tests.

The Pattern: Structured Specification

Instead, provide structured requirements with unambiguous boundaries:

### Task: Implement User Login Endpoint

#### Context & Boundaries
- File: `src/api/auth.py`
- Framework: FastAPI + SQLAlchemy
- Do NOT modify `src/models/user.py` schema.

#### Requirements
1. Accept `POST /api/v1/auth/login` with JSON payload `{ "email": str, "password": str }`.
2. Verify password against `user.hashed_password` using `passlib.context.CryptContext` (argon2).
3. On success, return HTTP 200 with `{ "access_token": str, "token_type": "bearer" }` (JWT valid for 15 minutes).
4. On failure (unknown user or wrong password), return HTTP 401 with `{ "detail": "Invalid credentials" }`. Do not reveal if the email exists.

#### Verification
- Run `pytest tests/test_auth.py` to confirm all 4 test cases pass.

By anchoring the agent with explicit constraints, existing imports, and a runnable verification command, you reduce hallucinations and ensure the agent can self-correct without your intervention.


Key Takeaways

  1. Autocomplete predicts the next token; agents run tool-assisted feedback loops (inspect $\to$ plan $\to$ act $\to$ observe).
  2. Context degradation is real: Large context windows suffer from "lost in the middle" and error poisoning. Keep context lean and relevant.
  3. Agents thrive on verification loops: Never ask an agent to build without giving it a way to test its work (pytest, npm test, typecheckers).
  4. Specifications beat conversational chatting: Specify inputs, output shapes, constraints, and success criteria up front.

A 6-question knowledge check follows this lesson in the app, free and without an account.

More like this

  • Finding and Fixing Vulnerabilities with Claude

    Scan a practice repository with Claude's security layers, verify and triage what they report, and land patches safely on a branch. You will leave with a repeat…

    Course · Claude · IT Support, Networking & Security · Capable · 18 levels · 4 free · Professionally curated by levelupwith.com

  • 10x Developer: Claude Code & LLM Selection Mastery

    Master Claude Code CLI, advanced context management, tool integration, and optimal LLM model selection to multiply your software engineering throughput.

    Beyond the Obvious · AI & Agents · Expert · 29 levels · 4 free · Professionally curated by levelupwith.com

  • Claude at Work: No-Code Skills for Knowledge Workers

    Learn to brief Claude clearly, check what it gives you, and set up Projects, Artifacts, Skills, memory, connectors and Research for real work in sales, marketi…

    Course · Claude · AI & Agents · Capable · 18 levels · 4 free · Professionally curated by levelupwith.com

  • Delegating Real Work to Claude: Tasks, Files and Apps

    Learn to hand Claude multi-step work on your real files, browser and Office apps, with clear briefs, firm limits and approval gates, then review the results so…

    Course · Claude · AI & Agents · Capable · 18 levels · 4 free · Professionally curated by levelupwith.com

  • Prompting Claude: Instructions, Context and Testing

    Write prompts that Claude follows reliably, manage what goes into its context window, and test and improve your prompts with evidence instead of guesswork. Eac…

    Course · Claude · AI & Agents · Capable · 20 levels · 4 free · Professionally curated by levelupwith.com

  • Finished Work with Claude Artifacts, No Code

    Brief, refine, brand, check, share and export finished designs, decks, documents, dashboards and motion pieces in Claude without writing code. Every level ends…

    Course · Claude · AI & Agents · Capable · 18 levels · 4 free · Professionally curated by levelupwith.com