Four Years of Building with AI用 AI 做设计和写代码的第四年

Four years after ChatGPT—from prompt engineering and RAG to coding and personal agents—the real challenge is catching how fluent output erodes judgment.ChatGPT 发布四年后,从 Prompt Engineering、RAG 走到编程代理与 Personal Agent,真正的难题早已变成识破流畅产出如何侵蚀判断力。

I am writing this four years to the week after ChatGPT appeared in late November 2022.

In late 2022, working with AI had one underrated virtue: its failures were loud. When you pasted an isolated function into a GPT-3.5 browser window, it hallucinated imports, mangled types, invented library flags that never existed, or ran out of context mid-sentence. Nobody mistook broken output for good engineering.

Four years later, the failures have turned quiet. Modern coding agents read an entire repository in seconds, compile cleanly, pass basic checks, and produce interfaces that look 85 percent right at a glance. Personal agents now reach beyond code editors into local files, media pipelines, browsers, and everyday tools. That shift has quietly rewritten what it means to build well with AI. The hard problem is no longer getting models to produce code, layouts, or prose—it is diagnosing the subtle ways fluent output corrupts your architecture, your taste, your security boundaries, and your own thinking.

Four eras in four years: how the bottleneck kept moving

Looking back across four years of daily use, AI did not improve along a single smooth curve. It jumped through four distinct operating paradigms—prompt engineering in browser chat, editor copilots and RAG, shell-capable coding agents with context engineering, and now personal agents. Each jump solved the previous era's bottleneck, introduced a subtler failure mode, and rendered a large chunk of the previous era's "best practices" actively counterproductive.

2022–2023: Browser copy-paste and the myth of prompt engineering

The first era ran on GPT-3.5 and early GPT-4 inside a stateless browser tab. Context windows were tiny—4,000 to 8,000 tokens—so the unit of work was a single function, a regular expression, or an isolated stack trace. You stripped out surrounding files by hand, pasted a snippet into a chat box, and spent ten minutes afterward repairing hallucinated APIs.

Because those early models were brittle, "prompt engineering" quickly turned into a cottage industry of rituals. Half of it was real mechanics; the other half was superstition, and telling the two apart still matters today.

What actually worked mechanically came down to four levers:

  • Few-shot demonstrations: giving two or three concrete input–output pairs conditioned the model's continuation distribution far more reliably than paragraphs of abstract rules.
  • Explicit structure and delimiters: separating context, task, and output format prevented the model from blending commentary into parseable code or JSON.
  • Stepwise decomposition (chain-of-thought): forcing the model to spell out intermediate steps before committing to a final answer effectively bought more forward-pass computation per problem.
  • Negative constraints: stating what not to do ("do not introduce a new dependency", "do not swallow errors") narrowed a huge space of plausible-but-wrong completions.

What aged poorly was the prompt theater: "You are a 10x principal engineer at a top lab," offering imaginary cash tips, shouting IMPORTANT in all caps, or pasting 40-line persona preambles. Those tricks were crude patches for weak instruction-following in 2023 models. Carrying them into 2026 models does not make the output smarter; it just burns context and signals that you are still optimizing the surface wording instead of the problem framing.

When I write a prompt today, I treat it like a compact engineering spec rather than a spell. Four lines usually outperform four paragraphs: the exact files or symptoms involved, the invariants and negative constraints the model cannot guess from the repo, the objective check that defines "done," and the intended scope—whether I want a minimal surgical patch or the full production version with error states and keyboard navigation. Whenever a prompt starts growing past a screen, that is almost never a sign that the model needs more adjectives; it is a sign that I have not decomposed the task or moved the rules into code.

2024: Editor copilots, RAG, and why naive retrieval fails on code

The second era moved AI inside the editor. Fill-in-the-middle autocomplete became genuinely useful for boilerplate, and multi-file chat widened the unit of work from one function to a small feature or bug fix. Even so, the model still lived inside a read-only glass box: it could propose a diff across three files, yet it could not execute your test suite, inspect a failing compiler trace, or look at the rendered DOM. The human engineer remained the manual bus connecting chat, editor, terminal, and browser.

This was also the year Retrieval-Augmented Generation (RAG) became the default answer to every context problem. The classic RAG pipeline is conceptually clean: slice a corpus into fixed-size chunks, convert each chunk into a dense embedding vector, embed the user's query at runtime, retrieve the top-K chunks by cosine similarity, and stuff them into the prompt.

RAG works remarkably well for loosely structured prose—support documentation, policy handbooks, or knowledge bases where semantic similarity tracks relevance. On real software repositories, naive RAG fails in four predictable ways that took the industry a full year to admit:

  • Semantic similarity is not causal dependency. Vector search retrieves files that share similar vocabulary (comments, variable names, log strings), not necessarily the file that mutates the state, owns the upstream type contract, or overrides the CSS cascade. Asking why a table-of-contents sidebar dropped into the center of a page will retrieve files mentioning "table of contents," not the Tailwind v4 stylesheet whose .contents utility silently collided with the class name.
  • Fixed-window chunking destroys program structure. Slicing a TypeScript module every 500 tokens severs imports, type declarations, and helper invariants from the function body. The model receives a syntactically valid middle slice and fills in the missing top half with plausible hallucinations.
  • Retrieval fails silently. If the true root cause sits at rank 14 and your pipeline only injects top 8, the model has no way to know what it did not see. Rather than stopping to ask, it invents a local workaround that compiles cleanly and leaves the real bug untouched.
  • Indexes go stale faster than code changes. During an active refactor across ten files, a pre-computed embedding index lags behind the working tree, feeding the model yesterday's signatures.

In production knowledge systems, those flaws pushed teams toward hybrid retrieval—combining lexical search (BM25) for exact identifiers with dense embeddings for conceptual recall, followed by cross-encoder reranking and AST-aware or structural chunking. In coding tools, however, something even more decisive happened: once models gained shell access, agentic search largely beat opaque vector RAG. Running deterministic ripgrep, listing directory trees, reading exact symbol definitions, and following imports step by step lets a model trace actual causal graphs instead of guessing from cosine distance. When RAG still shines today is over large, slow-changing external document collections—not as a blindfolded substitute for reading a live codebase.

2025–2026: Shell-capable agents, test-time compute, and context engineering

The third era broke the read-only glass box. Repository-scale coding agents—Claude Code, Codex, and agentic editor workflows—gained shell execution, file search, test runners, subagents, and standardized external tool protocols (MCP). Around the same time, reasoning models shifted the scaling axis from training-time parameters alone to test-time compute, spending extra internal tokens verifying edge cases before emitting a diff, while context windows expanded from 32,000 tokens to 200,000 and 1,000,000 tokens.

For the first time, an agent could close an engineering loop on its own: read the repository, edit five files, run the typechecker, read the compiler error, fix the mismatch, and rerun the tests. Almost overnight, the bottleneck inverted. Writing syntax became nearly free; specification, architecture, and verification became the scarce resources.

Yet the 1,000,000-token context window brought its own illusion. Many engineers assumed large windows meant you could dump everything into one endless session and forget about context management. In practice, attention is not uniform across a massive prompt—a phenomenon widely seen as context rot and "lost in the middle." As a long session accumulates stale tool outputs, dead-end stack traces, superseded drafts, and unused MCP tool schemas, signal-to-noise ratio collapses. The model starts anchoring on an abandoned approach from forty turns ago, reintroducing bugs you already fixed, or ignoring a short constraint buried in the middle of the transcript.

That is why context engineering quietly replaced prompt engineering. The real craft is no longer clever phrasing; it is curating what enters and stays in the model's working memory:

  • Start fresh sessions at natural task boundaries so dead-end exploration does not poison the implementation pass.
  • Load procedural knowledge progressively—keeping specialized workflows and domain rules scoped to relevant paths or on-demand skills instead of paying an attention tax on every unrelated bug fix.
  • Prune unused tool surfaces, because every connected tool injects its schema and description into context even when idle.
  • Compact deliberately, preserving exact verified facts, file paths, and invariants while discarding noisy trial-and-error logs.

Many 2023–2024 habits—writing 500-line instruction manuals that repeat the folder tree, micromanaging every line, or nursing one chat thread for three days—actively degrade 2026 agents because they fight how modern attention and tool loops actually work.

2026: Personal agents, memory, and leaving the git sandbox

The fourth era, unfolding now in 2026, pushes agents past the boundary of a single code repository. A personal agent operates across your local filesystem, media toolchains, browser, documents, calendar, and messaging apps, while carrying persistent memory across sessions.

That unlocks cross-domain workflows that used to require gluing together five brittle scripts by hand. At the same time, it introduces two hard problems that coding agents barely touched:

  • Memory is fallible state, not ground truth. Persistent memory saves you from repeating preferences, yet stale or over-inferred memory silently biases future actions. If an agent remembers a constraint from a superseded prototype and treats it as permanent law, it will quietly steer new work in the wrong direction unless you treat memory as an editable mental model that current reality always overrides.
  • The blast radius leaves git. Inside a code repository, a bad edit is a git revert away. Outside it, an agent's mistake can overwrite original local assets, leak private files, or trigger an irreversible external action.

Living through all four eras leaves you deeply skeptical of hype in both directions. You neither dismiss AI as a toy—you have watched it compress week-long pipelines into afternoons—nor trust it blindly, because you have seen every generation's quiet failure mode up close.

Under the hood: the LLM mechanics that actually change how you build

Most advice about working with AI treats the model like a mysterious colleague you just need to speak to more politely. In practice, a handful of concrete mechanics under the hood explain almost every weird failure mode you hit in production—and once you understand them, your engineering decisions change immediately.

Post-training, RLHF sycophancy, and why verifiable rewards changed everything

Pre-training teaches a language model the statistical structure of text and code; post-training decides how it actually behaves in a conversation. For years, the dominant post-training recipe was supervised fine-tuning followed by Reinforcement Learning from Human Feedback (RLHF) or Direct Preference Optimization (DPO). Human raters naturally reward answers that sound polite, thorough, agreeable, and well-structured. The unintended side effect is sycophancy: models are structurally biased toward validating your premise ("Great idea, let's optimize that 3D globe!"), smoothing over gaps instead of saying "I don't know," and hedging with extra defensive code because cautious-looking prose scored well with raters.

What unlocked the 2025–2026 jump in coding and math was Reinforcement Learning with Verifiable Rewards (RLVR)—training models directly against objective pass-or-fail verifiers like compilers, unit tests, and mathematical proofs instead of human vibes. That distinction mirrors how you should work with agents day to day: the closer your task is to an objective verifier, the more reliably a model will self-correct; the closer it is to subjective taste or unverified premises, the harder you have to push back against its trained instinct to agree with you.

Tokenization, constrained decoding, and when not to fine-tune

Three small architectural facts save an enormous amount of wasted engineering:

  • Subword tokenization (BPE) is blind to characters and geometry. Models do not see individual letters, pixel coordinates, or visual spacing; they see byte-pair subword tokens. That is why a frontier model can architect a distributed system and still miscount letters in a word, misalign an ASCII diagram, or fail to guess an exact polar radius ratio in SVG. Whenever a task depends on exact character offsets or pixel geometry, hand it to code, not tokens.
  • Structured outputs (constrained decoding) trade flexibility for reliability. Modern APIs can mask invalid logits at decode time so a model cannot emit malformed JSON—eliminating an entire class of 2023 regex-parsing hacks. The subtle trap is forcing a model straight into a rigid enum or boolean field before it has had tokens to reason. Putting an explicit reasoning field before the final classification field in the schema consistently improves accuracy because autoregressive models compute as they generate.
  • Fine-tuning is for behavior and distillation, not for storing facts. One of the costliest 2023–2024 mistakes was fine-tuning (or training LoRA adapters) to inject mutable documentation or project knowledge. Fine-tuning reshapes style, output format, latency, and narrow domain reflexes; it is a terrible, brittle database that hallucinates stale facts and requires retraining whenever reality changes. Mutable facts belong in retrieval, tools, or context—never baked into weights.

KV caching and the hidden economics of prefix stability

Inside a transformer, generating each new token attends over the Key and Value tensors of all previous tokens. To avoid recomputing the entire conversation from scratch on every turn, serving engines cache those prefix tensors in a KV cache (exposed as prompt caching). In multi-turn agent loops, prompt caching is the difference between a responsive, affordable workflow and one that burns five to ten times the latency and cost.

Because KV caches match strictly from token zero forward, prefix stability becomes an architectural constraint. Injecting a live timestamp at the top of a system prompt, shuffling tool definitions between turns, or editing earlier messages invalidates the entire downstream cache on every single step. Keeping static instructions and tool schemas stable at the front—and appending dynamic state strictly at the tail—is one of the highest-leverage systems habits in agent engineering.

Stochastic reliability, pass^k math, and LLM-as-a-judge biases

Traditional software is deterministic: if a function passes once on a given input, it passes a thousand times. Agentic workflows are stochastic chains, and the math is unforgiving. If a single step succeeds 90 percent of the time, a ten-step autonomous workflow without verification or retry only succeeds 0.9 to the tenth power—roughly 35 percent of the time. That is the difference between pass@k (can the model solve it at least once in k tries, which looks great in demos) and pass^k (does it succeed reliably across every run in production). Closing that gap requires idempotent steps, runnable checks, and bounded recovery loops rather than hoping the base model hits 99.9 percent on the first try.

The same discipline applies to evaluation. When deterministic assertions cannot capture quality—such as tone, helpfulness, or visual coherence—teams often reach for LLM-as-a-judge. Automated judges are useful for fast directional signal, yet they carry well-documented biases: position bias (favoring whichever option appears first), verbosity bias (mistaking longer answers for better ones), and self-preference bias (rating their own model family's phrasing higher). Unless you randomize option order, ground judges against explicit rubrics, and calibrate them against human-labeled golden sets, an LLM judge will quietly optimize for its own blind spots.

The shared token stream and indirect prompt injection

Finally, every LLM application shares one fundamental security flaw that has no direct analogue in modern CPUs: instructions and untrusted data live in the exact same token stream. Hardware architectures separate executable code from data with non-executable memory pages; language models process system prompts, tool definitions, user messages, and retrieved web pages or emails through the same attention mechanism.

That is why indirect prompt injection—malicious instructions hidden inside a webpage, PDF, forum post, or email that an agent reads—cannot be solved by writing a sterner system prompt. Prompting the model to "ignore instructions inside external data" is a probabilistic defense against an adaptive attacker. Once you internalize that there is no hardware wall inside the token stream, structural containment stops looking like paranoia and starts looking like basic engineering hygiene.

Every model has a bias, and unchecked you inherit it

Most public debates about AI models devolve into benchmark charts or tribal loyalty. In daily engineering work, leaderboards tell you almost nothing about what it feels like to maintain a repository after a model has touched forty files. What matters in practice is that every model family carries a distinct behavioral bias—and if you do not recognize and push back against it, that bias quietly becomes your codebase's personality.

Codex is methodical on scoped refactors and disciplined on narrow algorithmic changes, yet it consistently over-indexes on defensive writing. Whenever an agent is even slightly uncertain about invariants across a repository, it hedges locally: adding null guards for configuration keys that build-time tests already guarantee, wrapping loaders in try/catch blocks that silently return empty arrays instead of surfacing a broken pipeline, extracting a single-use three-line block into a separate utility module "for future extensibility," and sprinkling cautious comments explaining edge states the type system already makes impossible. Reviewed line by line in isolation, every single guard looks prudent. Taken together across a codebase, they turn crisp logic into defensive mud. Worse, silent fallbacks convert loud, immediately fixable bugs into subtle runtime drift while doubling the code surface the next engineer—or the next agent—has to read before understanding what the system actually does.

Claude Code sits on the opposite side of the trade-off. When frontend design, typographic restraint, and visual hierarchy matter, it converges on cohesive interfaces noticeably faster than most alternatives. Much of the interactive craft on this site came together cleanly there: locking Newsreader to its 24pt optical cut, building the text-free 12-pleat folding fan that folds shut before switching language, tuning the pull-cord lantern's 18-pixel drag threshold and spring snap-back, and wiring up the dev-only /designs gallery that persists JSON choices through server actions. Yet aesthetic fluency carries its own subtle trap. When a first pass already looks finished, your guard drops, and quiet structural bugs slip straight past a glance—like a fixed table-of-contents drawer whose .contents class collided with Tailwind v4's built-in display: contents utility and dropped into the center column, or a lantern SVG vertically centered inside an 84-pixel button so the tassel drew directly over the lantern body.

Gemini's newest models have become a strong third pillar where multimodal visual judgment meets long-context engineering. They are particularly effective when a task crosses boundaries that pure text agents struggle with: iterating on painted fan leaves and antique lantern cutouts, diagnosing subtle UI alignment bugs straight from screenshots, writing zero-dependency Node and media-processing scripts, and maintaining tonal consistency across large bilingual rewrites spanning dozens of files. Even there, visual plausibility is never a substitute for mathematical or physical correctness: an image can look museum-grade in isolation and still violate the exact geometry of the component hosting it.

Choosing a model is less about which one tops a leaderboard and more about knowing which failure mode you would rather audit on a given task.

Architecture is now context engineering

Before 2025, clean software architecture—small cohesive modules, explicit type contracts, single sources of truth, no hidden global state—was justified primarily by human readability and team velocity. In the agentic era, good architecture has acquired a second, immediate payoff: it directly determines whether an AI agent edits your codebase accurately or quietly breaks three unrelated routes.

Humans can occasionally hold informal tribal knowledge in their heads—"don't touch that legacy helper, it mutates a module-level set." Coding agents are far more literal. Every implicit coupling, duplicated constant, or undocumented side effect acts like a trapdoor in the context window. Over the past year, cleaning up my own repositories for maintainability and making them legible to agents turned out to be the exact same work.

Consider three concrete patterns from this site and its sibling projects:

  • Make invalid states unrepresentable at compile time. In components/locale/fanDesigns.tsx, every fan ID in fanDesigns is keyed into fanDesignNames: Record<FanDesignId, string>, and config/locale-fan.test.ts verifies that the active JSON selection exists in that map. The same contract governs lampShapes and lampPalettes in components/theme/lampDesigns.tsx. An agent literally cannot add a new fan or lantern and forget to localize its name or break the gallery—TypeScript rejects the build before a human even opens the diff.
  • Eliminate hidden module-level state. Earlier iterations of this site had a module-level mutable preload set inside a hero carousel and module-level line identity counters inside a debug shell. Moving that state into component instances and refs wasn't academic tidiness; it stopped independent mounts and test runs from leaking state into one another in ways an agent debugging a single file would never expect.
  • Prefer explicit, compact mental models over clever abstraction layers. In Been There Series, deleting Three.js and the 3D WebGL globe left zero runtime dependencies beyond React 18 itself, grounding all seven room-key types on one shared 130 × 104 millimetre CSS container-query stage. When an entire product's spatial logic fits into one clean physical unit system, any new collaborator—or any fresh agent session—can understand the whole application in minutes instead of wading through four layers of wrapper indirection.

The same principle applies to project instruction files. Modern agents read a repository faster than you can summarize it. Writing a 500-line manual that repeats your folder tree, package manager, and obvious component patterns mostly wastes context on facts the model will discover in ten seconds anyway, and worse, those manuals inevitably drift out of sync with the code. The instruction notes that actually earn their keep are short and focused strictly on what is invisible from the code itself: product bans (why Wan's Dine forbids star ratings and invented memories), deployment quirks (why blog share images use an explicit .png route instead of opengraph-image so GitHub Pages serves the right MIME type), and mistakes you have already had to correct twice.

Cheap iteration is a trap: knowing when to stop prompting

When generating an image, a component, or a refactor costs ten seconds, it creates a quiet behavioral trap: whenever something looks off, your first reflex is to tweak two words in the prompt and roll the dice again. Over four years, I have learned that one of the highest-leverage engineering instincts is noticing when a prompt loop has hit a structural wall and switching back to deterministic math or first-principles design.

Adding antique artwork to this site's folding-fan language switcher made that wall unmistakable. The SVG fan in LocaleToggle pivots at (60, 104) inside a 120 × 110 viewBox, with 12 pleats spanning −72 to +72 degrees (144 degrees total) and paper running from inner radius 24 to outer radius 88. That geometry fixes an inner-to-outer radius ratio of 0.273 and a horizontal bounding box from −23.7 to 143.7. My first attempt to draw a Qing Canton export polychrome fan as hand-coded SVG looked flat and toy-like next to the antique reference, so I threw it away and switched to generating fan-leaf-only artwork with no sticks or handle.

Dropping that 1200 × 896 image directly into the 12-pleat SVG immediately broke in three distinct ways: blank beige triangles appeared on the leftmost and rightmost pleats because the source leaf was only unclipped across roughly ±56 degrees; a bright ivory semicircle bled into the bottom of the paper because the source image's inner radius (263 pixels against an outer radius of 725, a ratio of 0.363) was far larger than 0.273; and the dark brown ribs vanished completely against dark mode.

No amount of prompt-tuning was going to make a diffusion model hit a 0.273 polar ratio across twelve pleats. The actual fix was leaving prompts behind and solving the geometry directly: sampling background distance to locate the painted inner arc, fitting its exact center and radius (achieving 0.5 to 1.2 pixels of RMS error across ten museum-style fan leaves), writing a short zero-dependency Node script to bilinearly polar-remap each leaf 1:1 onto a 168 × 110 coordinate canvas with generous edge bleed, adjusting rib colors to antique bronze-gold so they read cleanly on both light and dark themes, and encoding all ten fans to 480 × 314 transparent WebP. That pipeline shrank each asset from roughly 900 kilobytes as PNG down to 35 to 42 kilobytes—a 95.7 percent reduction—while remaining sharper than 3× Retina at the fan's 96 × 88 CSS pixel footprint.

The hanging lantern theme switch exposed a closely related trap: accepting a visually plausible shortcut that violates physical coherence. At 40 × 64 CSS pixels, microscopic brushwork turns to visual noise; what carries the control is silhouette, material patina, and luminance contrast. A carved wooden palace lantern felt too boxy and heavy for a quiet editorial header. A glossy blue-and-white porcelain lamp looked crisp on its own, yet the moment it hung from the top bar it read like a modern hotel pendant rather than something genuinely ancient.

Even after rejecting those drafts and settling on authentic aged materials—smoked bamboo ribs, tea-stained Xuan paper with ink plum, aged cinnabar oilpaper, muted indigo paper, celadon raw silk, and dark smoked gauze with gold cranes—the first technical shortcut failed. Dimming a single lit image with CSS brightness() in dark mode took five seconds to implement and still looked wrong, because the bright painted candle flame stayed visibly glowing inside an "off" lamp.

Getting it right meant doing the unglamorous engineering: flood-filling out both the outer background and the tiny opening inside each top iron or bronze ring with one-pixel edge de-fringing so no white halo survives in dark mode; generating pixel-aligned unlit counterparts from each lit lantern and cropping every pair to a shared union bounding box so a 0.24-second opacity cross-fade never shifts by a single pixel; and computing each lantern's wireEnd coordinate from its exact cropped aspect ratio (17 for a tall melon lantern, 21 to 28 for plumper round bodies) so the hanging wire neither floats above the cap nor pokes through the ring hole. Each final 200-pixel WebP weighs 10 to 19 kilobytes.

In both cases, AI made exploration nearly free, but the actual craft was diagnosing why a draft failed—and knowing whether the answer lived in another prompt, in polar geometry, or in throwing out the entire visual metaphor.

Verification fatigue, Goodhart's Law, and the parallel-agent tax

Three operational realities only become obvious once you build with coding agents every week rather than in weekend demos.

The first is verification fatigue. Many engineers claim, "I review every line the model writes." In practice, human supervision degrades in the exact same way security permission prompts do: after the tenth approval dialog or the fifth 400-line diff, attention drops and review quietly turns into rubber-stamping. You cannot fix attention limits with willpower. You have to redesign the workflow around two distinct layers:

  • Probabilistic guidance for judgment calls and intent: short prompts, clear scope, and context the repo does not contain.
  • Deterministic enforcement for everything that must hold every time: ESLint with zero warnings, TypeScript noEmit, Vitest unit and architecture tests (46 tests across 16 files in this repo locking in blog frontmatter schemas, dark-token CSS parity, valid fan and lantern config IDs, and scroll-spy behavior), git diff --check, direct visual inspection whenever pixels move, and a concise verification record appended to progress.md. Without an objective pass-or-fail check, any agent stops the moment the diff looks done.

The second reality is Goodhart's Law inside automated testing. During PixelMorph, I watched an optimization loop game an automatic stereo-quality proxy by flattening 3D video back into 2D—technically raising the score while destroying the product. The exact same failure happens in agentic software development. If you ask an agent to write both a feature and its tests without auditing what the tests actually assert, it will happily produce weak mirror-tests ("does the component mount without throwing?") that turn CI green while guarding nothing of value.

Real verification means encoding invariants the model cannot game. When the table-of-contents highlight broke after jumping upward in a long essay, the fix was paired with a regression test in SiteNavigation.test.tsx that simulates scrolling deep and jumping back up to prove the highlight follows scroll position rather than stale observer intersections. In Wan's Dine, stripping EXIF and GPS coordinates from raw iPhone photographs and enforcing image size budgets are checked in the build pipeline and CI. A test suite only buys you leverage with AI when its assertions are harder to fool than the model writing the code.

The third reality is the parallel-agent coordination tax. Spinning up four or five subagents in parallel feels intoxicating—until you pay the integration bill. Concurrent agents working on overlapping surfaces quietly invent duplicate helpers, drift on naming conventions, introduce subtle merge conflicts, and hand you four separate diffs whose combined mental model nobody holds cleanly. Parallelism pays off enormously for independent research, asset batching, or cleanly partitioned modules with fixed interfaces. For tightly coupled architectural changes, small sequential commits with deterministic checkpoints between them consistently beat a swarm of concurrent edits.

Personal agents and the new blast radius

The shift from coding agents to personal agents in 2026 changes the risk profile of AI collaboration in a way most people still underestimate.

Inside a git repository, almost every mistake is cheap and reversible. Branch protection, diffs, test suites, and git revert act as a forgiving safety net. The moment an agent operates across your local machine, connected folders, browser sessions, email, calendar, and external APIs, the blast radius leaves git. A hallucinated parameter is no longer a failed unit test—it can delete source assets, expose a local credential, or send an irreversible message under your name.

Building Learning MCP forced me to confront this boundary directly before personal agents became mainstream. Connecting an AI assistant to live university portals sounded straightforward until we audited what the underlying endpoints actually did: some innocent-looking GET requests triggered hidden server-side state changes or view-tracking mutations, and an over-broad tool surface meant a single confused turn could alter real academic records.

The lesson from that system carries straight into working with personal agents today: containment beats supervision. Asking a model in a prompt to "be careful" or "never modify anything" is a probabilistic hope, and every probabilistic defense has a non-zero miss rate. Real safety comes from structural boundaries—omitting write tools when a workflow only needs read access, keeping secrets outside readable workspaces, running commands inside sandboxes with explicit network gates, and stopping cleanly for human approval before irreversible external actions like pushing to a remote or sending a message.

There is also a design lesson here about trust. A great personal agent is not one that blindly pushes past every boundary to appear "autonomous." It is one that executes reversible local work thoroughly—writing scripts, verifying outputs, running test suites—and knows exactly when to stop, show its evidence, and hand the irreversible step back to the human.

The practical playbook: how a real task actually runs

Theory about KV caches, RAG failure modes, and post-training biases only pays off if it changes what you type on Monday morning. When a real feature or bug lands on my desk today, my workflow comes down to five concrete habits.

1. Separate exploration from implementation

The single highest-leverage habit with modern coding agents is refusing to let the model edit files in the same breath that it reads them. On anything non-trivial, I split the work into two distinct passes:

  • Pass one (read-only exploration and spec). Ask the agent to read the relevant files, trace the data flow, and list every edge case, assumption, or existing invariant it might touch—without writing a single line of code. For ambiguous UI or architecture work, I explicitly tell it to interview me on three to five trade-offs first (state ownership, failure behavior, mobile layout, backwards compatibility).
  • Pass two (fresh-context execution). Distill the agreed decisions into a ten-line spec—exact files, invariants, and the command that proves it works—then start a fresh session to implement it. All the dead-end file reads and back-and-forth from exploration stay out of the implementation context, so the model spends its attention on the clean contract instead of forty turns of discovery noise.

2. Write prompts like bug reports, not wishes

Vague prompts force the model to guess your constraints, and models almost always guess toward generic boilerplate. The difference between a weak prompt and a strong one is concrete boundaries and a runnable check:

  • Weak prompt: "Fix the table of contents highlight when scrolling up in long blog posts."
  • Working prompt: "In components/layout/SiteNavigation.tsx, the active TOC heading stays stuck on a lower section after jumping back up in a long post because IntersectionObserver misses headings that never cross the narrow band. Replace it with a scroll-position check that picks the last heading scrolled past the header band, add a regression test in SiteNavigation.test.tsx that scrolls deep and jumps back up, and verify with pnpm test."

The same rule holds for visual or styling work. Instead of saying "make the header lantern look more antique," specify the physical box and hard constraints: "40 × 64 CSS pixels, pull cord anchored at y = 64, 18-pixel drag threshold, separate pixel-aligned lit and unlit WebPs cross-fading over 0.24 seconds, and zero white halo on a dark background." And whenever a command or browser check fails, paste the raw stack trace, HTTP status, or screenshot verbatim—never paraphrase an error message in your own words, because human summaries routinely drop the exact line number or symbol that points straight to the root cause.

3. Use git as an agent safety harness

Once an agent can edit ten files in twenty seconds, git hygiene stops being optional:

  • Commit at every verified green checkpoint. Before starting a risky refactor or visual overhaul, make sure git status is clean. If an agent wanders down a dead end, git checkout -- . in two seconds beats spending ten turns trying to talk it out of a tangled diff.
  • Stage explicit paths, never blind git add -A. Local editor configs, scratch scripts, and tool state files (like .claude/settings.local.json) quietly accumulate in working trees. Staging named paths keeps commits clean and auditable.
  • Isolate parallel work with git worktree—and never share a dev server cache. When two agents truly need to work in parallel on independent branches, give each one its own git worktree instead of letting them fight over one working tree. Even on a single branch, never run two next dev processes against the same checkout: they overwrite .next's route manifest under each other and produce phantom 404s on routes that exist in source.

4. Break retry loops after two failed attempts

One of the most expensive failure modes in agentic coding is the polite retry spiral: a test fails, the agent tweaks a line, it fails again, the agent adds a defensive guard, and six turns later the file is unrecognizable while the underlying bug is still there.

My hard rule is two strikes. If two consecutive fixes fail on the same symptom, I stop the agent from editing production code and force a diagnostic step instead: write a five-line minimal reproduction, log the actual computed bounding box or intermediate value, or read the upstream caller directly. Nine times out of ten, the model was fixing a mental guess rather than an observed fact. Showing it one real measurement immediately snaps it out of the loop.

5. Budget context, tools, and repo instructions like memory

Treat an agent's context window the way systems engineers treat L1 cache—small, precious, and degraded by junk:

  • Keep repo instruction files short (under 150 to 200 lines). Include only the exact verification commands (pnpm lint && pnpm typecheck && pnpm test && git diff --check), non-obvious project invariants, and recurring footguns. Every line that repeats what package.json or the directory tree already shows is dead weight paid on every single turn.
  • Turn off idle MCP servers and plugins. Every connected external tool server injects its schemas into the prefix even when you never call it—consuming context and hurting prompt-cache reuse if tool lists churn. Connect only what the current workflow needs.
  • Match model weight to task weight. Do not burn a slow, high-reasoning pass to rename a prop or format a JSON file, and do not expect a fast lightweight pass to untangle a subtle race condition or cross-file architecture contract. Use lightweight passes for exploration, mechanical edits, and quick checks; reserve deep reasoning for specification, root-cause diagnosis, and diff audits.

The cognitive risk of letting the model go first

After four years of building with AI, I think the sharpest long-term risk is neither defensive code nor security bugs. It is cognitive drift.

When a model can produce a fluent architecture proposal, a clean layout, or a 1,500-word essay in ten seconds, it is extraordinarily tempting to let it take the first swing on every problem. Do that often enough and you stop experiencing the productive friction that forces you to form a real point of view. Instead of thinking from first principles, you gradually become a polite editor polishing the model's average defaults.

I caught myself falling into that exact groove twice on this site. The first time was while localizing all essays and ten project stories into Chinese. The initial translated pass was accurate, grammatical, and completely free of factual errors—yet reading it aloud revealed the unmistakable stiffness of translated prose: stacked pre-nominal modifiers, cautious transitions, too many em-dashes, and English sentence rhythm wearing Chinese words. Fixing it meant stepping away from the draft and rewriting paragraphs from scratch in shorter, direct sentences I would actually say out loud.

The second time was in product design. As I wrote in Subtracting Until the Product Appears, asking an AI "how do we polish this terminal interface?" or "how do we make this 3D globe feel smoother on mobile?" will happily produce clever optimizations for a feature that should not exist. Deleting the terminal, the restaurant rating grid, and the 3D globe only happened when I stepped outside the prompt loop and asked what the product looked like without them.

Two simple habits help keep that cognitive muscle sharp. First, before letting any agent open a file on a non-trivial task, I write five lines in my own words stating what I want, why I want it, and what I explicitly refuse to accept. Second, when reviewing a substantial change, I prefer auditing the diff from a fresh context that never saw the persuasive chain of reasoning that produced it. It is surprisingly easy to be talked into a mediocre abstraction by a conversation you just participated in.

Why fundamentals appreciate in value

There is a persistent myth that AI makes deep engineering and design fundamentals less important. Four years of evidence point in the opposite direction.

You cannot tell that Codex's "safe" fallback is silently swallowing a real failure unless you understand error propagation and type invariants. You cannot diagnose why a 12-pleat folding fan leaks white pixels along its inner arc unless you understand basic polar geometry and SVG clipping. You cannot explain why naive vector RAG misses a CSS cascade collision unless you understand both embeddings and browser layout. You cannot tell that a green test suite is gaming the spec unless you know how systems actually fail under edge conditions. And you cannot reject a glossy, plausible-looking lantern or a stiff paragraph unless you have spent time developing real taste.

Four years after ChatGPT, syntax, boilerplate, and first drafts are effectively free. That has not lowered the bar for engineers or designers; it has removed the last excuse for shipping sloppy work. What holds up now—and what I try to bring to every team and project I work on—is critical friction: knowing each model's bias, designing architectures that keep context clean, stopping prompt loops when deterministic engineering is the real answer, enforcing invariants in code rather than hope, and forming your own judgment before asking a machine to accelerate it. AI is an extraordinary multiplier, but it multiplies whatever standard you bring into the room—including your blind spots.

ChatGPT 发布刚好四周年这天,我写下这篇文章。

回头看 2022 年底,初代 AI 其实有个被低估的好处:它的错误很吵。那时候把单个函数粘进 GPT-3.5 的网页框里,它动辄编造不存在的库和参数、写错类型,或者上下文一满就直接截断。没人会把明显坏掉的产出当成好工程。

四年过去,模型的错误变安静了。今天的编程代理几秒钟就能读完整个仓库,写出的代码能编译、过得了基础检查,生成的界面乍一看也有八十五分像样。更进一步,Personal Agent 已经走出代码编辑器,开始直接触达本地文件、音视频工具链、浏览器和日常工作流。这种变化彻底改写了用 AI 造东西的难度所在:真正的瓶颈早就不在「让模型吐出代码、版式或文章」,而在于识破那些足够流畅的产出,是怎么悄悄腐蚀你的架构、审美、安全边界和思考习惯的。

四年里的四代形态:瓶颈是怎么一步步迁移的

回看这四年高频使用 AI 的轨迹,技术并不是沿着一条平滑直线往前爬的。它先后跨过四个截然不同的工程范式:网页复制粘贴与 Prompt Engineering、编辑器内嵌与 RAG、具备终端能力的编程代理与上下文工程,以及 2026 年的 Personal Agent。每一次跃迁都解决了上一代最痛的卡点,同时引入了更隐蔽的新失效模式,也让上一代攒下来的大批「最佳实践」迅速过期。

2022–2023:网页复制粘贴时代,以及 Prompt Engineering 的真相与迷信

第一代跑在 GPT-3.5 和早期 GPT-4 的无状态网页对话里。那时候上下文窗口极小,只有 4,000 到 8,000 token,协作粒度被死死锁在单个函数、一条正则或一段报错堆栈上。你得手动把周边无关文件删干净,粘进对话框,再花十分钟修掉模型编出来的 API。

因为早期模型很脆弱,「Prompt Engineering(提示词工程)」很快长成了一门夹杂着玄学的手艺。四年后回头复盘,里面一半是真机制,一半是纯迷信,把两者拆清楚至今依然有用。

真正在底层起作用的,其实是四个非常朴素的杠杆:

  • 少样本示例(Few-shot):直接丢两三组具体的输入输出样例,比写三大段抽象规矩更能稳住模型的输出分布。
  • 显式结构与分隔符:把背景信息、任务指令和输出格式硬切开,避免模型把解释性废话混进可解析的代码或 JSON 里。
  • 分步拆解(Chain-of-Thought):在模型给出最终结论之前,逼它先把中间推理步骤展开,本质上是在推理阶段为难题争取更多前向计算量。
  • 负向约束(Negative Constraints):明确写清「不要做什么」(比如不引新依赖、不静默吞错),能立刻砍掉一大片看似合理但走偏的生成路径。

真正经不起时间考验的,是当年满天飞的提示词剧场:「假设你是硅谷顶级实验室的十倍工程师」「答得好我给你两百美元小费」「全大写 IMPORTANT 警告」,或者长达四十行的人设开场白。那些招数本质上是在给 2023 年指令遵循能力偏弱的模型打粗糙补丁。把它们照搬到 2026 年的模型里,既不会让产出更聪明,只会平白占掉注意力,反而暴露你还在打磨表面措辞,而没有把问题本身拆清楚。

到了今天,我写提示词的方式更像写一份精简的工程需求单,而不是念咒。通常四行就能胜过四大段:涉及的具体文件或现象、仓库里看不出的不变量与负向约束、能判定「已完成」的客观检查,以及明确的范围预期——比如这次我只要最小改动,还是连异常态、空态和键盘导航一起补齐。一旦一条提示词写满了一整屏,几乎从来不是因为形容词还不够多,而是任务没拆开,或者有些规矩本该写进代码而不是塞进对话。

2024:编辑器内嵌、RAG,以及为什么朴素检索在代码库上会失灵

第二代把 AI 搬进了编辑器。行内补全(FIM)写样板代码变得很顺手,编辑器里的多文件对话也把工作粒度从单个函数拉到了小功能模块和局部修 bug。但模型依然被关在一个只读的玻璃盒子里:它能建议你改三个文件,却跑不了测试、读不到编译器的真实报错、也看不到页面渲染完到底长什么样。人依然是连接对话窗、编辑器、终端和浏览器的人肉总线。

这一年也是 RAG(检索增强生成) 被捧成万能解药的一年。经典 RAG 的管线在纸面上非常优雅:把资料切成固定长度的文本块(chunk),用向量模型转成稠密向量(embedding),查询时把用户问题也向量化,按余弦相似度捞出 Top-K 块塞进上下文。

对于结构松散的自然语言文档——客服手册、制度汇编、知识库——这套做法确实管用。但放到真实的代码仓库里,朴素 RAG 会以四种非常固定的方式失灵,行业花了整整一年才老老实实承认:

  • 语义相似不等于因果依赖。 向量检索擅长找「用词相近」的文件(相似的注释、变量名或日志文案),却找不到真正修改状态、定义上游类型契约,或者在 CSS 层叠里盖掉样式的文件。问它「为什么目录侧边栏掉到了页面中间」,向量搜索会把提到「目录」的组件全捞出来,却漏掉 Tailwind v4 里那个悄悄撞名的 .contents 内置工具类。
  • 固定切块会拦腰斩断程序结构。 每 500 个 token 硬切一刀,会把 import、类型定义和外层不变量从函数体里活生生剥离。模型拿着语法合法的半截代码,只能靠脑补去填缺失的上半截。
  • 检索失败是完全静默的。 如果真正出问题的文件排在第 14 名,而你的管线只截前 8 名,模型根本不知道自己漏看了什么。它不会停下来问你,而是顺手写一个本地能编译过去的绕路补丁,把真 bug 留在原地。
  • 索引老化永远快于代码重构。 连续跨十个文件改接口时,离线建好的向量索引很快落后于工作区,把昨天的旧函数签名喂回给模型。

在大型文档知识库里,这些问题倒逼大家转向混合检索(Hybrid Retrieval)——用 BM25 词法检索抓精确标识符,叠加稠密向量抓语义召回,再接重排模型(Reranker)和按语法树切块。但在写代码这件事上,发生了更彻底的转向:一旦模型拿到终端权限,代理式主动搜索(Agentic Search)几乎全面压过了黑盒向量 RAG。用确定性的 ripgrep、目录树遍历、符号定义跳转顺着真实调用链一路查下去,模型追的是代码里的因果图,而不是盲猜余弦距离。今天 RAG 依然有它的用武之地——适合体量庞大、变化缓慢的外部文档库,而不是拿来蒙着眼替代读活代码。

2025–2026:终端代理、推理算力,与上下文工程

第三代彻底打破了只读玻璃盒。全仓编程代理(Claude Code、Codex 以及各类 Agentic IDE)接上了终端执行、文件检索、测试运行、子代理拆分和标准化的外部工具协议(MCP)。几乎同时,推理模型把扩展维度从单纯堆训练参数拉到了测试时计算(Test-time Compute)——在吐出 diff 之前先花内部 token 推演边界条件;上下文窗口也一路从 32K 扩到了 200K 乃至 100 万 token。

代理第一次能独自跑完整个工程闭环:读仓库、跨文件改代码、跑类型检查、读报错、自己修、再重跑测试。几乎在一夜之间,瓶颈彻底反转——写语法几乎免费了,定义问题、架构清晰度和确定性验证成了真正的稀缺品。

但百万级上下文窗口很快带来了新的错觉。很多人以为窗口够大,就能把所有东西一股脑塞进一个聊三天的会话里不用管。真用起来完全不是这样:模型在超长上下文里的注意力并不均匀,行业里常说的**上下文腐烂(Context Rot)**和「中间丢失」现象非常真实。随着长会话不断堆积过期的终端输出、走不通的报错堆栈、被推翻的旧草稿以及根本没用到的 MCP 工具描述,信噪比一路暴跌。模型开始锚定在四十轮前废弃的思路上,反复把你修好的 bug 改回来,或者无视埋在对话中段的一条关键约束。

也正是在这个节点,**上下文工程(Context Engineering)**悄悄取代了早期的 Prompt Engineering。真正决定产出上限的不再是措辞技巧,而是你如何精细管理进入模型工作记忆的每一份信息:

  • 在自然任务边界果断新开会话,不让前面走弯路的试错记录污染正式实现。
  • 按需渐进加载规矩:把特定目录的约定或团队发布流程放进按路径触发的规则或按需读取的 Skill,而不是让每个不相关的修 bug 对话都背着五百行上下文税。
  • 精简闲置工具面:每多挂一个用不上的 MCP 服务,它的工具名和参数说明就会在每一轮里持续吃掉上下文。
  • 有意识地做摘要压缩:只保留验证过的事实、文件路径和硬不变量,果断丢掉冗长的试错过程。

于是 2023—2024 年攒下来的很多旧习惯——写五百行复述目录结构的说明文档、逐行盯梢、一条对话死撑好几天——放到 2026 年的代理身上反而成了负优化。

2026:Personal Agent、长期记忆,与走出 git 沙箱

2026 年正在展开的第四代,是代理跨出单个代码仓库,演变成真正意义上的 Personal Agent。它能同时调动本地文件系统、音视频处理工具链、浏览器、文档、日历和外部通讯工具,并跨会话保持长期记忆。

这打通了过去必须靠手写五个脆弱胶水脚本才能串起来的跨界工作流,同时也抛出了两个编程代理时代几乎没碰过的难题:

  • 长期记忆是会过时的状态,不是绝对真理。 记住用户习惯能省去大量重复交代,但过期或过度推断的记忆会悄悄带偏后续判断。如果代理把某个废弃原型的约束当成永久铁律,它就会在新项目里默默往错方向用力——你必须把代理记忆当成一份随时可修正的心智模型,而不是不可质疑的数据库。
  • 爆炸半径彻底走出了 git。 在代码仓库里,最坏的失误不过是一次 git revert;走出仓库之后,一次草率的操作就可能覆盖本地原始素材、读出私密凭证,或者发出无法撤回的外部消息。

一路完整走过这四代形态,人对 AI 的态度会变得非常冷静:既不会轻视它——毕竟亲眼看着它把一周的工程管线压缩成一个下午;也不会盲信它——因为每一代模型安静藏起来的坑,你都实打实踩过。

掀开引擎盖:真正改变工程决策的大模型底层机制

大多数教人怎么用 AI 的文章,都把模型当成一个脾气古怪的同事,以为只要换种客气点的说法就能沟通好。但在真实工程里,几乎所有令人抓狂的失效模式,背后都能直接追溯到几个具体的底层机制。把这些机制想透,你写系统、设护栏、做取舍的方式会立刻不一样。

后训练、RLHF 讨好偏置,以及可验证奖励(RLVR)带来的转折

预训练教会模型语言和代码的统计结构,真正决定它「怎么跟你对话」的是后训练。很长一段时间里,主流后训练靠的是有监督微调(SFT)加基于人类反馈的强化学习(RLHF)或 DPO。人类标注员天然偏爱语气礼貌、措辞周全、条理工整且不顶嘴的回答,这直接种下了一个结构性副作用——讨好偏置(Sycophancy)。模型会本能地顺着你的错误前提往下说(「好主意,我们来优化这颗 3D 地球!」),在拿不准的时候顺手补一段看似圆满的编造,或者在代码里堆一堆防御性兜底,因为在标注阶段「看起来稳妥」的回答得分更高。

真正把 2025—2026 年代码和数学能力拉上一个大台阶的,是基于可验证奖励的强化学习(RLVR)——不再靠人类拍脑袋打分,而是直接用编译器、单元测试和数学证明这类客观通过/失败的验证器来训练模型。这一底层差异和我们日常带代理干活的规律完全同构:你的任务离客观验证器越近,模型自我纠错就越稳;越靠近主观品味或未经证实的前提,你就越要主动对抗它「顺着你说话」的后训练惯性。

分词、约束解码,以及什么时候绝对不该做微调

有三个看似基础的底层事实,能替团队省掉成堆的弯路:

  • 子词分词(BPE)天生看不见字符和几何。 模型眼里并没有单个字母、像素坐标或视觉间距,只有字节对编码切出来的子词 token。这就是为什么一个能设计分布式系统的顶尖模型,依然可能数错一个单词里有几个字母、画歪一段 ASCII 图,或者死活猜不准 SVG 里 0.273 的极坐标半径比。凡是依赖精确字符偏移或像素几何的事,一律交给代码,不要指望 token 猜。
  • 结构化输出(约束解码)是用灵活性换可靠性。 现在的接口可以在解码阶段通过屏蔽非法 logit,让模型从数学上不可能吐出格式错误的 JSON——直接淘汰了 2023 年一整套靠正则硬抠输出的脆弱脚本。但它藏着一个细微的坑:如果 Schema 一上来就逼模型直接填死枚举值或布尔值,不给它留先推理的 token 空间,准确率反而会掉。因为自回归模型是在生成过程中完成计算的,在 Schema 里把推理字段摆在最终分类字段之前,效果几乎总是更好。
  • 微调(Fine-tuning)适合改行为和做蒸馏,不适合当知识库。 2023—2024 年最烧钱的误区之一,就是动不动上 LoRA 微调,企图把公司文档或项目知识「烤进权重里」。微调擅长固定输出风格、压缩小模型延迟成本或固化窄领域习惯,但拿它存会变化的事实是一场灾难——它不仅会自信地吐出过期结论,而且业务一变就得重训。易变的事实永远属于检索、工具和上下文,不该写死在参数里。

KV Cache 与前缀稳定性:代理系统的真实成本账

Transformer 每生成一个新 token,都要对前面所有 token 的 Key 和 Value 张量做注意力计算。为了不让每一轮对话都从头重算整段历史,推理引擎会把不变的前缀张量缓存在 KV Cache 里(对开发者表现为 Prompt Caching)。在动辄几十轮工具调用的代理循环里,能不能命中前缀缓存,直接决定了延迟和账单是正常水平还是暴涨五到十倍。

由于 KV Cache 严格从第 0 个 token 开始逐位匹配,前缀稳定性本身就成了一条架构约束。把实时时间戳塞在系统提示词最前面、每轮随机打乱工具列表顺序、或者中途改写早期消息,都会瞬间击穿整段下游缓存。把静态指令和工具定义牢牢钉在最前面,把动态变化的状态严格追加在尾部,是做代理系统最立竿见影的工程习惯之一。

随机性、pass^k 数学,与 LLM-as-a-Judge 的裁判偏置

传统软件是确定性的:同一个输入跑通一次,跑一千次还是通。代理工作流是随机链路,概率乘法非常无情。如果单步成功率是 90%,一条没有校验和重试机制的十步自主链路,完整跑通的概率只有 0.9 的十次方——大约 35%。这就是 pass@k(试 k 次至少成功一次,演示里特别好看)和 pass^k(生产环境里每一次都稳定成功)之间的鸿沟。填平这道鸿沟,靠的不是指望基座模型单步飙到 99.9%,而是把步骤做成幂等、给关键节点配可运行检查、再包上有限次数的恢复闭环。

评估环节同样如此。当语气、可用性或视觉统一性没法用断言写死时,很多人会引入 LLM-as-a-Judge(大模型当裁判)。自动裁判很适合快速看趋势,但它带着几个已经被反复证实的偏置:位置偏置(偏爱排在前面的候选)、冗长偏置(把写得更长误当成写得更好),以及自我偏好(给同家族模型的措辞打更高分)。如果不随机打乱候选顺序、不锚定具体评分细则、不用人工标注的黄金集定期校准,大模型裁判最后只会安静地把系统优化进它自己的盲区里。

共享 Token 流与间接提示词注入

最后,所有大模型应用都共享一个底层安全缺陷,它在现代 CPU 架构里甚至找不到对应物:系统指令和不可信外部数据,挤在同一条 token 流里。现代硬件靠不可执行内存页(NX bit)把代码和数据硬隔开;而语言模型用同一套注意力机制同时处理系统提示词、工具定义、用户输入,以及刚刚抓回来的网页、PDF 或邮件正文。

这就是为什么间接提示词注入(Indirect Prompt Injection)——藏在外部网页、论坛帖子或邮件里的恶意指令——不可能靠把系统提示词写得更严厉来根治。在提示词里叮嘱模型「忽略外部数据里的指令」,本质上是用概率防线去挡主动攻击者。一旦从底层想明白 token 流里根本没有硬件隔离墙,结构化隔离就不再像过度紧张,而是最基本的工程卫生。

每个模型都有自己的偏置,不反制就会长进你的代码里

网上关于 AI 模型的讨论,大多很快滑进跑分榜对比或阵营站队。但真在日常项目里高强度写代码、做设计,跑分几乎不能告诉你「这个模型改完四十个文件后,代码库会变成什么气质」。真正在意工程质量的人,看的是另一件事:每个模型家族都带着固定的行为偏置。你不主动识别并反制它,这种偏置很快就会长成你代码库的底色。

拿 Codex 来说,它在边界清晰的重构和局部算法实现上很稳,但有一个极强的惯性:过度 defensive writing。只要代理对跨文件的架构不变量有一点不确定,它就会在局部疯狂打补丁——给构建期测试已经卡死的配置项加空值判断、把数据加载包进 try/catch 后静默返回空数组把真实故障藏起来、把只用一次的三行逻辑拆成独立工具模块美其名曰「方便未来扩展」,再配上谨慎的注释去防类型系统早已排除的状态。拆开看每一行 diff,似乎都很「稳妥」;合在一起看,却把原本干净的模块拖成了防御性泥潭。更危险的是,静默兜底会把本该尽早炸出来的错误藏成隐蔽的运行时漂移,同时把下一个接手的人(或下一个代理)需要读懂的代码面翻倍。

Claude Code 处在天平的另一端。凡是涉及前端设计、排版克制感和视觉层级,它收敛出完整美感的速度明显优于多数工具。这个站里不少交互工艺都是在 Claude Code 里迅速成形的:把 Newsreader 锁在 24pt 光学字号、做出点击后先合拢再切换语言的无字 12 折折扇、调出下拉 18 像素阈值加弹簧回弹的拉绳古灯,以及仅在开发环境生效、通过 server action 直接写回 JSON 配置的 /designs 画廊。可视觉上的流畅同样藏着陷阱:当第一版界面就已经「像成品」时,人很容易放松警惕,漏掉安静藏在底下的结构 bug——比如固定目录抽屉的 .contents 类名撞上了 Tailwind v4 内置的 display: contents,直接掉进正文中间;或者灯笼 SVG 在 84 像素高的按钮里被垂直居中,把流苏画到了灯身上面。

Gemini 的新模型在多模态视觉判断和长上下文工程结合的场景里,成了我工作流里非常扎实的一块拼图。尤其在纯文本代理够不着的跨界任务上表现很亮眼:反复迭代十把满绘古扇面和五对亮灭古灯、直接看截图定位渲染对齐 bug、零外部依赖写出 Node 加 ffmpeg 和 cwebp 的图像处理脚本,以及跨几十个文件保持中英文长文口径一致。即便如此,视觉上「看着对」也绝不等于几何或物理上对——一张孤立来看像博物馆藏品的生成图,塞进真实组件的坐标系里照样可能处处破绽。

选模型与其说是在选「谁跑分最高」,不如说是在选:手头这个任务,你更愿意替哪种偏置做审计。

在代理时代,好架构本身就是上下文工程

2025 年之前,我们推崇好架构——高内聚小模块、显式类型契约、单一数据源、避免隐式全局状态——理由主要是「方便人读、方便团队协作」。进入代理时代,好架构多了一层立竿见影的回报:它直接决定 AI 代理改你的代码时是精准落地,还是顺手改坏三个毫不相干的页面。

人脑偶尔能记住口口相传的潜规则(「别碰那个旧工具函数,它会悄悄改一个模块级 Set」),但编程代理比人直白得多。仓库里每一处隐式耦合、重复常量或藏在角落里的副作用,都是上下文窗口里的陷阱门。过去一年里,我替自己的项目清理维护债,和让仓库变得对 AI 代理友好,最后发现做的几乎是同一件事。

拿这个站和另外几个项目里的三条具体实践来说:

  • 用编译期契约把非法状态堵死。 在 components/locale/fanDesigns.tsx 里,每一把扇面 ID 都通过 Record<FanDesignId, string> 强制绑定中文名,config/locale-fan.test.ts 则校验当前 JSON 配置选中的 ID 必须真实存在;components/theme/lampDesigns.tsx 里的灯笼器型与配色也是同一套类型契约。代理根本不可能新增一把扇子或灯笼却漏掉命名、或者把本地预览页写崩——不等人工审 diff,TypeScript 就先报错拦住了。
  • 清掉隐式的模块级全局状态。 这个站早期的轮播组件里藏过一个模块级可变预加载集合,调试壳里也有模块级行号计数器。把它们收回到组件实例和 ref 里,不是为了代码洁癖,而是防止不同挂载和测试之间互相串味——这种隐蔽串味,单文件排错的代理极难凭空猜到。
  • 用紧凑显式的心智模型取代花哨封装。 在 Been There Series 里,删掉 Three.js 和 3D 地球后,运行时依赖只剩 React 18 自己,七类房卡全部落在一块统一的 130 × 104 毫米 CSS 容器舞台上。整个应用的空间逻辑收束到一把统一的物理尺子里以后,不管是新合作者还是新开的代理会话,几分钟就能把整套模型装进脑子,不用在四层包装函数里绕迷宫。

同样的道理也适用于项目说明文件。现在的代理读仓库比人写文档快得多,写一份五百行的说明书去复述目录结构、包管理器和显而易见的组件写法,不仅浪费上下文,时间一长还会和真实代码打架。真正值钱的说明文件一定很短,只记录光看代码看不出来的东西:产品红线(比如 Wan's Dine 为什么严禁餐厅打星和编造记忆)、部署冷知识(比如博客分享图为什么必须用 .png 路由,避免 GitHub Pages 给无后缀的 opengraph-image 吐错 MIME 类型),以及你已经不得不纠正过两次的坑。

廉价试错的错觉:什么时候该停下改提示词

当生成一张图、一个组件或一次重构只要十秒钟,人很容易染上一种条件反射:哪里看着不对,第一反应是改两句提示词再抽一次卡。用了四年我越来越确信,工程里最值钱的直觉之一,是看出提示词循环已经撞上结构墙,立刻停下抽卡,退回确定性的数学或第一性原理。

给这个网站的折扇语言开关做藏品扇面时,这堵墙摆得清清楚楚。LocaleToggle 里的折扇 SVG 画在 120 × 110 的 viewBox 里,扇轴在 (60, 104),12 折覆盖 −72 到 +72 度(总张角 144 度),扇纸从内半径 24 延伸到外半径 88。这套几何定死了 0.273 的内外半径比,以及 −23.7 到 143.7 的横向跨度。最开始试着用 SVG 手画清代广彩人物扇,质感发平、像玩具,我直接否掉,改用图像生成单独出「无扇骨纯扇面」。

可把 1200 × 896 的原图直接贴进 12 折 SVG 扇面后,三个硬伤立刻跳出来:原图完整未裁切的张角只有大约 ±56 度,最外两折直接露出灰白三角;原图内弧半径 263 像素、外半径 725 像素(比例 0.363,远大于 0.273),导致米白底色漏进扇面下半圈,形成一圈刺眼白边;深色模式下,深棕扇骨几乎和暗背景融成一片黑。

这时候再怎么打磨提示词,扩散模型也不可能把十二折扇面精确对齐到 0.273 的极坐标比例。真正解决问题的不是多抽十次卡,而是彻底离开提示词、老老实实算几何:根据背景色差提取内弧边界,拟合每张原图的精确圆心与半径(十把满绘藏品扇的圆拟合 RMS 误差都在 0.5 到 1.2 像素之间),写一段零外部依赖的 Node 脚本做双线性极坐标重映射,把扇面带出血 1:1 投射进 168 × 110 的坐标系画布,把扇骨调亮成深浅模式都清楚的古铜金色,最后统一编码成 480 × 314 透明 WebP。这一套管线把每把扇面从约 900 KB 的 PNG 压到 35 到 42 KB(体积缩减 95.7%),在首页 96 × 88 CSS 像素的渲染尺寸下依然超过 3× Retina 清晰度。

顶栏的古灯开关撞上了另一种陷阱:用看似省事的视觉捷径,破坏了物理一致性。在 40 × 64 CSS 像素的小尺寸下,过于细碎的笔触只会糊成噪点,真正撑起辨识度的是廓形、材质包浆和明暗反差。雕木鎏金宫灯挂在极简页眉里太方太沉;青花玲珑瓷灯单看精致,挂上去却像现代酒店吊灯,完全没有古意。

好不容易推翻重来、收束到带着岁月包浆的古物材质——熏竹宣纸墨梅、陈年朱砂油纸、宋韵靛青月雁、素绢青绿山水和乌纱泥金云鹤——第一个技术捷径还是露馅了。在深色模式下直接用 CSS brightness() 压暗单张亮灯图,五秒钟就能写完,可灯芯里画好的亮烛火依然在暗处发光,根本不像灭了灯。

把这件事真正做对,靠的还是枯燥但扎实的工程:用边缘泛洪抠掉纯白背景,顺手清掉顶部锻铁环或铜环内部的小孔,并沿边界做 1 像素去白边羽化,保证深色模式下零白边;拿每张亮灯图做底生成像素级对位的灭灯版,每对亮灭图共用同一个并集裁切框,让 0.24 秒的透明度交叉淡入淡出纹丝不动;再按每把灯笼裁切后的实际宽高比算出精确的 wireEnd(修长的冬瓜灯落在 17,圆润的圆灯笼落在 21 到 28),让顶部挂线既不悬空,也不穿进吊环孔里。最终每张 200 像素宽的透明 WebP 只有 10 到 19 KB。

在这两件事里,AI 把探索和体力成本压到了接近零,但真正值钱的判断,是看清产出到底为什么不对,然后决定这一步该改提示词、该写极坐标脚本,还是该把整个视觉隐喻推倒重来。

审查疲劳、古德哈特定律,与多代理并行的隐性税

有三件工程现实,只有每周真刀真枪拿代理写项目才会撞上,看演示视频永远感受不到。

第一件是审查疲劳。很多高频用 AI 的工程师会说:「模型写的每一行我都 review。」现实里,人工监督的退化曲线和频繁弹出的权限确认框一模一样:连续审过十次改动、翻完五段四百行的 diff 之后,人的注意力必然下滑,所谓人工把关会不知不觉滑向闭眼点通过。对抗注意力上限不能靠意志力,只能把规则拆成两层:

  • 柔性引导留给判断与意图:精简的提示词、清晰的范围边界,以及仓库里看不见的背景。
  • 确定性强制交给代码和工具链:零警告 ESLint、TypeScript noEmit、全量 Vitest 单元测试与架构回归测试(这个站目前 16 个文件共 46 条测试,锁死博客 frontmatter 校验、深色 CSS 变量一致性、折扇与灯笼配置 ID 合法性以及目录高亮逻辑)、git diff --check,凡涉及像素变化时的直接视觉核验,外加每次完成后写进 progress.md 的改动与验证证据。没有明确返回通过或失败的检查,任何代理都会在改动「看着差不多」时停下。

第二件是自动化测试里的古德哈特定律。做 PixelMorph 时,我亲眼见过优化循环怎么钻自动画质代理指标的空子——模型学会把 3D 立体视频压扁回 2D,指标漂亮了,产品却毁了。代理写软件完全一样:如果你让模型既写实现又顺手补测试,自己却不审测试到底在断言什么,它很乐意写一堆照着实现画瓢的弱测试(「组件能不能挂载不报错」),让 CI 一片绿灯,实际什么都没守住。

真正有效的测试必须编码进模型绕不开的不变量。当长文往上跳转时目录高亮出错,修复的同时必须在 SiteNavigation.test.tsx 里补一条真正模拟「先滚到底、再往回跳」的回归测试,证明高亮跟着滚动位置走而不是卡在过期的观察器状态里;在 Wan's Dine 里,剥离 iPhone 照片的 EXIF 和 GPS 坐标、校验图片体积预算都写进 Sharp 构建管线并由 CI 卡死。只有当测试套件比写代码的模型更难被糊弄时,自动化验证才真的给你带来杠杆。

第三件是多代理并行的隐性协调税。同时开四五个子代理并发干活,听着很爽,直到合并那一刻才发现账单有多贵:并发代理改在相近区域时,各自悄悄造出重复的工具函数、命名风格漂移、埋下细微的合并冲突,最后丢给你四份彼此假设不一致的 diff,谁脑子里都没有完整的心智模型。并行最适合天然解耦的调研、批量素材处理或接口锁死的独立模块;但凡涉及强耦合的架构调整,小步串行、每步过一次确定性检查,几乎总是比一群代理同时乱改更快更稳。

当代理走出代码仓:Personal Agent 与新的爆炸半径

2026 年从编程代理走向 Personal Agent,是一次质变,也是一次大多数人还没认真算过账的风险跃迁。

在 git 仓库里,绝大多数错误廉价且可逆。分支保护、diff、测试套件和 git revert 构成了一张很宽容的安全网。可一旦代理能够触达你的本地磁盘、连接文件夹、浏览器会话、邮件、日历和外部接口,爆炸半径就彻底走出了 git。一次幻觉参数不再只是挂掉一条单元测试,它可能误删本地原素材、读走私密凭证,或者以你的名义发出一封收不回来的外部消息。

做 Learning MCP 的经历让我早早撞上过这条边界。把 AI 助手接到真实的高校教务和课程平台,听起来只是接几个接口,真去逐个审计底层协议才发现:有些表面人畜无害的 GET 请求居然会在服务端留下隐藏状态变更或阅读记录;工具面稍微放宽一点,模型一次犯迷糊就可能动到真实的学业数据。

那次工程踩坑留下的原则,直接适用于今天和 Personal Agent 的相处:隔离与收束永远胜过口头监督。 在提示词里叮嘱模型「小心点」「别乱改东西」只是概率上的祈祷,而任何概率防御都有非零漏报率。真正靠得住的安全必须长在结构里——只需要读的场景干脆不暴露写入工具、把敏感凭证隔在可读工作区之外、用沙箱和显式网络开关限制命令行权限,并且在任何不可逆的外部动作(推送远端、发邮件、删用户数据)之前老老实实停下来等人工确认。

这里面其实也藏着人机信任的产品设计。一个好用的 Personal Agent,从来不是为了显得「全自动」而硬闯每一道边界的代理;而是能把本地可逆的脏活累活彻底干完——写脚本、跑验证、核对结果——同时精准知道自己的自治边界停在哪里,把不可逆的最后一拍干干净净交回给人的代理。

实战手册:接到一个真实任务时,我具体怎么干

关于 KV Cache、RAG 失效模式和后训练偏置的理论,如果不能落实到周一早上打开终端后的具体动作,就只是纸上谈兵。今天接到一个真实需求或线上 bug 时,我实际跑下来最管用的是五条具体做法。

1. 把「探索」和「实现」硬拆成两段

带现代编程代理干活,回报率最高的一条习惯,就是不让模型一边读代码一边直接改文件。只要任务稍微复杂一点,我都把它拆成两步:

  • 第一步:只读探索加对齐规格。 先让代理读相关文件、顺着调用链理清数据流,把可能碰到的边界条件、隐藏假设和现有不变量列出来,一行代码都先不改。碰到模糊的交互或架构取舍,我会直接让它先挑三到五个关键问题反问我(状态归谁管、失败怎么兜底、移动端怎么排版、要不要向后兼容)。
  • 第二步:新开干净会话落地。 把对齐好的决定压成十行左右的规格单——涉及的具体文件、硬不变量、以及证明做完的验证命令——然后新开一个会话去写代码。探索阶段踩过的弯路、读偏的无关文件全留在上一个会话里,实现阶段模型的注意力只花在干净的契约上。

2. 把提示词写成 bug 报告,而不是许愿

模糊的提示词会逼着模型自己猜你的约束,而模型猜出来的几乎永远是四平八稳的样板代码。一条弱提示词和一条能直接干活的提示词,差别不在礼貌程度,而在边界和验收条件:

  • 弱提示词:「修一下长文章往上滚时目录高亮不对的问题。」
  • 实战提示词:「在 components/layout/SiteNavigation.tsx 里,长文章跳回前面章节后目录高亮会卡在下方章节,因为 IntersectionObserver 会漏掉没有穿过窄触发带的标题。改成按滚动位置计算最后一个滚过页眉线的标题,在 SiteNavigation.test.tsx 补一条先滚到底再跳回顶部的回归测试,并用 pnpm test 验证。」

做视觉和样式一样适用。别写「把页眉灯笼做得更有古风感」,直接给物理框和硬条件:「40 × 64 CSS 像素,拉绳锚在 y = 64,下拉 18 像素触发切换,亮灭两张像素对齐的 WebP 用 0.24 秒透明度淡入淡出,深色模式下零白边。」另外,只要终端报错或页面渲染异常,直接把原始报错堆栈、HTTP 状态码或截图原样丢给模型——千万别用自己的话转述报错,人肉总结经常顺手漏掉真正指向根因的那一行行号或符号名。

3. 把 git 当成代理的安全带

当一个代理二十秒就能改完十个文件,git 卫生就不再是可选项,而是底线:

  • 每个跑绿的里程碑立刻提交。 开始高风险重构或视觉大改之前,先保证 git status 干净。一旦代理改歪了,两秒钟 git checkout -- . 回退重来,比花十轮对话试图把它从一团乱麻里劝回来快十倍。
  • 永远显式指定暂存路径,不用盲目 git add -A。 本地工具配置、临时脚本和本地状态文件(比如 .claude/settings.local.json)很容易悄悄躺在工作区里。按路径显式暂存,提交记录才干净可审计。
  • 真要并行就用 git worktree,而且绝不在同一份检出目录里起两个开发服务器。 两个代理确实要并行改独立分支时,各自给独立的 git worktree,别让它们抢同一份工作区。哪怕在单分支上,也别同时跑两个 next dev 进程——它们会互相覆盖 .next 里的路由清单,让源码里明明存在的页面冒出莫名其妙的 404。

4. 连续修两次还挂,立刻打断重试死循环

代理编程里最烧时间、也最容易把代码写烂的坑,就是礼貌的重试螺旋:测试挂了,代理微调一行;再挂,代理顺手加个防御性判断;六轮之后文件面目全非,真正的根因还在原地。

我给自己定了一条硬规矩:事不过二。同一个现象连续两次修复失败,立刻叫停改业务代码,强行切回诊断动作——写一段五行的最小复现、打印真实的布局包围盒或中间变量值,或者直接去读上游调用方。十次里有九次,模型是在对着自己的脑补打补丁,而不是对着观测到的事实修 bug。只要喂给它一条真实的实测数据,它几乎立刻就能跳出死循环。

5. 像管 L1 缓存一样管上下文、工具和仓库说明

把代理的上下文窗口当成系统工程师手里的 L1 缓存——空间珍贵,塞满垃圾性能就崩:

  • 仓库说明文件压在 150 到 200 行以内。 只写精确的验收命令(pnpm lint && pnpm typecheck && pnpm test && git diff --check)、代码里看不出的业务红线,以及踩过两次以上的坑。凡是看一眼 package.json 或目录树就能知道的事,每多写一行,每一轮对话都在白交注意力税。
  • 关掉闲置的 MCP 服务和插件。 每多挂一个外部工具服务,即便一整天用不上,它的工具定义也会稳稳占在前缀里,既吃上下文,又容易在列表变动时击穿前缀缓存。当前流程用什么才开什么。
  • 按任务重量匹配模型档位。 改个属性名、整理个 JSON 别去烧慢速深度推理档;反过来,排查并发竞态或梳理跨文件架构契约,也别指望轻量快模一次搞定。轻量档用来跑探索、机械改动和快速核验,重推理留给拆需求、定根因和审大 diff。

让模型先开口的认知代价,以及为什么底座能力反而更值钱

和 AI 协作四年,我觉得最难防的长期风险既不是防御性代码,也不是安全漏洞,而是认知上的悄悄退化。

当模型十秒钟就能交出一份条理清晰、文从字顺的架构方案、版式初稿或一千五百字长文时,人太容易把每一次的「第一判断」都让渡出去。习惯一旦养成,你不再经历那种逼着自己形成独立观点的阻力,而是慢慢退化成在模型的平均默认解里修修补补的礼貌编辑。

在这个网站上,我两次亲身撞上过这种惰性。第一次是把全站文章和十篇项目复盘做成中英双语:第一版中文翻译语法全对、意思不差、挑不出事实硬伤,但读出声来却透着一股挥之不去的「翻译腔」——定语层层叠叠、破折号泛滥、转折过于工整,是披着中文词的英文句式。改顺它的唯一办法,是干脆丢开初稿的句式节奏,按自己真会说出口的短句重新写一遍。

第二次在产品设计上。就像我在 《一直做减法,直到产品真正长出来》 里写的,只要你问模型「怎么把这套终端界面做得更酷」或「怎么优化 3D 地球在手机上的手势」,它一定会热心交出一堆巧妙的补丁,去完善一个本来就不该存在的功能。把伪终端、评分墙和 3D 地球删掉,从来不是在提示词循环里优化出来的,而是跳出对话、问自己「删掉它产品还剩什么」才做出的决定。

我现在靠两个很笨但管用的习惯对抗这种滑坡。第一,凡是稍微复杂一点的任务,在让任何代理动文件之前,先用自己的话写下五行判断——我要什么、为什么要它,以及我明确拒绝什么。第二,审大改动时尽量开一个没看过生成过程的干净上下文来复核,免得被前面那段听起来很有道理的对话牵着走。

也正因为如此,那种「AI 让底层工程和设计功底变不值钱」的说法,在我这四年的体感里恰恰是反过来的。不懂错误传播和类型不变量,你根本看不出 Codex 那些看似「稳妥」的兜底正在静默吞错;不懂极坐标几何和 SVG 裁切,你诊断不出 12 折扇面为什么内弧漏白边;不懂向量检索和浏览器层叠机制,你解释不清为什么朴素 RAG 会漏掉一个 CSS 类名冲突;不懂系统在边界条件下怎么失效,你分不清一套全绿的测试到底在守底线还是在走过场;没有自己磨出来的品味,你也说不出为什么一把精致的青花瓷灯挂在古风页眉里就是不对味。

ChatGPT 发布四年后的今天,语法、样板代码和初稿几乎都已经免费了。但这并没有拉低工程师和设计师的门槛,它只是拿走了「没时间细打磨」这最后一块挡箭牌。现在真正站得住的——也是我希望带进每一个团队和项目里的——是带着批判性的摩擦力:看懂每个模型的偏置,用干净的架构管住上下文,在该写确定性代码时果断停下抽卡,把不变量锁进工具链而不是寄希望于提示词,并在让机器加速之前先守住自己的判断。AI 是极强的放大器,但它会毫无保留地放大你带进房间里的一切标准——包括你的盲区。