From Vibe Coding to Agent Engineering: A Practical Guide to Reliable AI-Assisted Development

    Conversational coding with AI agents—often called Vibe Coding—gets prototypes off the ground fast, but it struggles once the goal grows from a single function to a full module or system. This article explains how to turn ad-hoc prompting into structured, reusable, and evolvable agent-engineering workflows. Organized into five progressive stages—beginner, proficient, mastery, extension, and practice—it covers writing structured requirements, managing context as a finite resource, decomposing large tasks, spec-driven development, and safe refactoring backed by tests. It also shows how to extend workflows with custom commands, hooks, sub-agents, and external tools connected through MCP, and closes with five end-to-end case studies spanning CLI tools, mobile apps, web apps, open-source contributions, and office automation. Readers will learn concrete engineering actions for making AI-assisted development stable, reviewable, and reliable.

    1. Introduction: The Rise of Conversational Coding and Its Limits

    Over the past two years, coding agents built around large language models have matured rapidly. Instead of writing code line by line, developers now describe their intent in natural language and let an agent read code, search documentation, modify files, and run commands on its own. “Conversational coding” has become an everyday workflow for many teams.

    This approach has a low barrier to entry and delivers quick results, which is why it is often called “Vibe Coding.” When you are validating an idea quickly, building a prototype, or handling boilerplate code, it dramatically shortens the path from idea to working result. But as the task grows from “write a function” to “deliver a module, or even a whole system,” its weaknesses start to show:

    • Vague requirements: A request like “help me optimize this API” specifies neither a goal nor acceptance criteria, so the output tends to stay at surface-level patching.
    • Context bloat: The longer the conversation, the more irrelevant information accumulates. The model gradually forgets earlier constraints and may drift away from the original plan.
    • Lack of engineering constraints: Output can look reasonable yet lack tests, documentation, and edge-case handling, so real defects surface all at once during integration or release.
    • Difficult collaboration: Experience from individual sessions is hard to capture; team members each use their own prompts, and quality varies widely.

    At the root, these problems come not from the model’s capability itself, but from treating the agent as a “one-off Q&A tool” rather than managing it as an “engineering system.” Using AI coding tools as the running example, this article discusses how to turn scattered conversational tricks into a structured, reusable, and evolvable agent-engineering workflow.

    The whole piece builds up through five stages: beginner (get conversational coding working), proficient (make the process stable and controllable), mastery (let judgment drive quality), extension (break past single-instance limits), and practice (complete an end-to-end delivery). Each stage maps to a set of concrete engineering actions.

    2. Five Mental Models That Run Through Everything

    Methodologies become outdated; mental models stay reusable. The following five points run through the entire practice and serve as the basic basis for deciding “should I do it this way.”

    1. The conversation is the development environment. Under the agent paradigm, requirement clarification, code search, solution discussion, code modification, and command execution all happen within the same conversation. The conversation itself is a development environment that needs to be designed, maintained, and reviewed—not a one-off question window.
    2. Context is a finite resource. A model’s context window has limited capacity, and more is not always better: irrelevant content dilutes attention, drives up cost, and amplifies hallucinations. Context must be actively managed, much like memory must be allocated sensibly.
    3. Decomposition is the new programming. An agent can complete a single, well-defined task but struggles to finish a vague, large goal on its own. Breaking big tasks into small tasks with clear boundaries that can be verified has become a core programming skill in the agent era.
    4. Tools are the nerve endings. A model only knows what is in its training data and knows nothing about the real state of your project. Only with tools—file read/write, command execution, version control, running tests—can it “see” and “act on” the real world and self-correct based on feedback.
    5. Humans judge, AI executes. Architecture choices, boundary trade-offs, security and compliance, and final acceptance must be owned by humans; execution work such as coding, boilerplate, bulk edits, and test writing should be delegated to the agent as much as possible. This division of labor is both a quality guarantee and a boundary of responsibility.

    These five models support one another: the conversation is the vehicle, context is the resource, decomposition is the method, tools are the channel, and judgment is the bottom line.

    3. Beginner: Get Conversational Coding Working

    3.1 Expressing Requirements in a Structured Way

    The first fundamental skill when working with an agent is turning a vague intent into a structured requirement. A high-quality instruction contains at least four elements:

    • Goal: What result you want and why;
    • Context: The files, modules, existing implementation, and business background involved;
    • Constraints: Tech stack, coding standards, performance requirements, prohibitions;
    • Acceptance: How to tell the task is done—for example, which tests pass and what conditions are met.
    1. # Goal
    2. Add unit tests for user-dimension filtering to the order query API.
    3. # Context
    4. - Code under test: src/order/service.py, core method query_orders()
    5. - Existing tests: tests/test_order.py, currently covers query by order ID
    6. # Constraints
    7. - Use the project's existing test framework and assertion style; do not add new dependencies
    8. - Cover: normal filtering, empty results, non-existent user (three scenarios)
    9. - Do not modify business code
    10. # Acceptance
    11. - All new tests pass
    12. - Changes limited to test files only

    The same capability, expressed as “write some tests for this API,” usually takes three or four rounds of back-and-forth to fix; expressed with the template above, you often get near-usable output in a single pass.

    3.2 Understanding the Agent Execution Flow

    When an AI coding tool receives an instruction, it typically goes through an “act—observe—correct” loop: read relevant files → propose or make changes → run commands to check results → keep adjusting based on feedback. Understanding this flow helps you anticipate its behavior:

    • Without a file location, it may blindly search through many files, which is both slow and prone to misjudgment;
    • Without a bounded modification scope, it may “optimize” unrelated code along the way and widen the change surface;
    • Without running any command after a change, it can only judge correctness by “imagination,” and errors are easily hidden.

    So even at the beginner stage, build three habits: give the file or module scope first, then request the change; require it to automatically run tests or build commands after modifying; and advance just one small goal per round.

    3.3 Choosing the Right Model

    Different models differ in reasoning depth, code style, long-context performance, and response cost, and there is no single choice that is best for every task:

    • For quick Q&A and boilerplate generation, pick a lightweight, fast-responding model;
    • For complex refactoring and architecture analysis, a model with stronger reasoning is a better fit;
    • For reviewing long documents and cross-file analysis, prioritize long-context capability.

    More importantly, keep the ability to switch. AI coding tools and their plugin ecosystems increasingly let you switch the underlying model to different cloud or local models, so teams can configure routing by task type and optimize cost. As one of the major cloud service providers, Baidu AI Cloud also offers enterprises a broad range of model services. Keep in mind that switching models can change how a prompt performs, so re-validate critical workflows when migrating.

    4. Proficient: Turn “It Works” into “It Works Reliably”

    4.1 Layered Context Management

    The core principle of context management is “show up when needed, step out when done”:

    • Long-term rules: Stable information such as coding standards and architecture conventions fits in a project-level rules file (such as CLAUDE.md), which the tool loads automatically in every session.
    • Task background: The current requirement and relevant module descriptions, explicitly referenced on demand via things like @file-path.
    • Execution results: Command output and test logs enter the context automatically through tools, with no manual pasting needed.
    • Long-conversation governance: When a conversation gets too long, first compress and summarize the history with a command like /compact, or start a new session carrying only the necessary conclusions and file references.

    Also watch out for a few high-cost behaviors: repeatedly reading the same large file, pasting whole files instead of precise references, and mixing several unrelated tasks in a single session.

    4.2 Using Project Memory to Capture Long-Term Knowledge

    A project rules file acts as the agent’s “long-term memory,” usually placed in the project root. It solves the problem of “having to repeat the same explanations in every conversation”: when kept concise, it stably constrains behavior; when bloated, it instead takes up a lot of context and interferes with judgment.

    1. # Project Overview
    2. This system is an e-commerce order backend using a layered architecture: API layer / business layer / data layer.
    3. # Tech Stack
    4. - Backend: Spring Boot 3.x, build tool Maven
    5. - Frontend: React + TypeScript
    6. - Database: MySQL 8.x
    7. # Directory Conventions
    8. - src/main/java/.../controller: API layer
    9. - src/main/java/.../service: business logic
    10. - src/test/java: unit tests
    11. # Coding Standards
    12. - Every new public method must include comments and unit tests
    13. - Business logic must not be written directly in the Controller
    14. - Database changes must be managed through migration scripts
    15. # Common Commands
    16. - Build: mvn clean package
    17. - Test: mvn test
    18. - Run locally: mvn spring-boot:run
    19. # Prohibited
    20. - Do not modify code under the generated directory
    21. - Do not output sensitive user information in code or logs

    A project rules file should be version-controlled like code, evolve with the project, and be maintained together during team reviews.

    4.3 Debugging and Course Correction

    It is normal for an agent to make mistakes; what matters is having an efficient way to correct course:

    1. Provide the full picture: Error messages, reproduction steps, and the difference between expected and actual results are far more useful than “it doesn’t work.”
    2. Ask for explanation before modification: Have the agent first analyze possible causes and propose a plan; confirm the approach is sound before acting. This avoids “changed a bunch but didn’t fix it.”
    3. Anchor on verified facts: Clearly state “A is confirmed working, the problem is in B” to prevent it from repeatedly trying in the wrong direction.
    4. Converge in time: If two or three consecutive fixes fail on the same issue, ask it to return to root-cause analysis, and compress the context or start a new session if needed—rather than piling on more changes along the wrong path.

    4.4 Coordinating with Version Control

    The faster an agent generates code, the more you need a reliable “safety net.” Before each time you let the agent modify code, make sure the working tree is clean, existing tests pass, and you have a baseline you can roll back to at any time. In practice, a small-step commit strategy is recommended:

    • Let the agent accomplish just one clear goal at a time, and review the diff immediately after the change;
    • Commit by feature with a good commit message, rather than piling up a large batch of changes and committing all at once;
    • Use branches to isolate experimental changes, and merge back to the main branch only after validation passes;
    • Periodically run the full test suite in a clean environment to prevent the “it runs on my machine” illusion.

    5. Mastery: Let Judgment Drive Delivery Quality

    5.1 Decomposing Large Tasks: The “New Programming” of the Agent Era

    For a task like “refactor the payment module,” handing it straight to an agent usually yields a lot of plausible-looking changes. The right approach is to do the decomposition first, by a human (or human and agent together):

    1. Goal: Refactor the payment module
    2. Task 1: Map the existing payment flow and produce a module dependency diagram
    3. Task 2: Add characterization tests for the current payment logic to lock in current behavior
    4. Task 3: Extract a payment channel adapter interface, keeping existing behavior unchanged
    5. Task 4: Split implementations by channel and connect each to the new adapter one by one
    6. Task 5: Add a new channel and verify all regression tests for existing channels pass
    7. Task 6: Remove deprecated code and update API documentation

    Decomposition should follow a few principles:

    • Verifiable tasks: Each task has a clear completion criterion, such as “all tests green” or “documentation updated”;
    • Appropriate granularity: Keep a single task within a range the agent can finish independently and a human can review quickly;
    • Clear dependencies: Tasks with sequential dependencies proceed in series; unrelated tasks can run in parallel or in batches;
    • Risk control: Refactoring tasks follow “small steps, fast pace,” keeping the system runnable and reversible at every step.

    5.2 Spec-Driven Development

    Spec-driven development requires “write the spec first, then the code”: a spec document describes “what to do,” an implementation document describes “how to do it,” and a plan document breaks down “in what order.” Its core value is to make the implicit assumptions in requirements explicit, so the agent and humans work from the same source of truth.

    A typical implementation plan looks like this:

    1. ## Requirements
    2. The user list must support combined filtering by department and employment status.
    3. ## Technical Decisions
    4. - Encapsulate filter conditions in a Query object to avoid Controller method parameter bloat
    5. - Push query logic down to the Service layer, keeping the Controller thin
    6. ## Task List
    7. 1. [ ] Define UserQuery and the paginated response structure
    8. 2. [ ] Implement combined filtering logic in the Service layer
    9. 3. [ ] Wire the new parameters into the Controller
    10. 4. [ ] Add unit tests and API documentation

    Spec documents have another easily overlooked benefit: when requirements change, you modify the spec first and then have the agent adjust the code accordingly. The scope of the change is immediately clear, avoiding a gradual drift between code and intent.

    5.3 Refactoring: Build the Guardrails First, Then Cut

    When you have an agent refactor code, the scenario most prone to problems is “behavior changing without anyone noticing.” Safe refactoring depends on three preconditions:

    • Tests as guardrails: Add tests for the code to be refactored first, locking down the input-output relationship;
    • Small steps: Do only one kind of refactor at a time (renaming, extracting a method, removing duplication), running tests after each step;
    • Reviewable changes: After refactoring, focus the review on the diff and confirm no functional changes were slipped in along the way.

    For legacy code without test coverage, you can first have the agent generate “characterization tests” to record the current behavior before starting the refactor.

    5.4 Tests and Documentation: Build Quality into the Process

    Tests and documentation should not be a “remedial action” before delivery; they should be embedded in the development process:

    • Tests first: For new features, have the agent generate test cases from the requirements first, then implement the code;
    • Documentation in sync: When API changes or new config items appear, ask the agent to update the documentation in sync;
    • Look beyond coverage: Focus on boundary conditions, exception paths, and concurrency scenarios, rather than blindly chasing a coverage number.

    6. Extension: Workflows Beyond a Single Instance

    The capability of a single session is always limited. The focus of this part is to use commands, automation hooks, external tools, and multi-agent collaboration to upgrade the workflow from a “one-off conversation” into a “reusable engineering system.”

    6.1 Custom Commands: Solidify High-Frequency Flows into Commands

    High-frequency actions like code review, generating commit messages, and writing documents from a template can all be solidified into custom commands, usually stored under the project’s .claude/commands/ directory, defined as prompt templates in Markdown files, and able to receive parameters via $ARGUMENTS. For example, create review.md in the project root:

    1. Review the uncommitted changes in the current working directory:
    2. 1. Correctness: boundary conditions, exception handling, concurrency safety
    3. 2. Security: input validation, sensitive data leakage, access control
    4. 3. Maintainability: naming, duplicate code, comments
    5. 4. Consistency: compliance with the coding standards in CLAUDE.md
    6. Output format:
    7. - Issue list (sorted by severity, with file and line numbers)
    8. - Suggested changes
    9. - Overall verdict: Pass / Needs revision

    Afterward, you just type /review to run a review with a consistent standard on every commit.

    6.2 Hooks: Make Standards Enforce Themselves

    A Hook is a script that triggers automatically before or after the agent uses a tool, configured in .claude/settings.json. It turns “reminding developers to follow standards” into “the system enforcing standards.” For example, automatically format code after each file edit:

    1. {
    2. "hooks": {
    3. "PostToolUse": [
    4. {
    5. "matcher": "Edit|Write",
    6. "hooks": [
    7. {
    8. "type": "command",
    9. "command": "mvn spotless:apply"
    10. }
    11. ]
    12. }
    13. ]
    14. }
    15. }

    Hooks can cover many automation scenarios: auto-format and lint after an edit, intercept dangerous commands before a tool call, generate a change summary when a session ends, and automatically run relevant tests after a command executes. It is worth stressing that a Hook is itself code: it should be version-controlled and reviewed regularly to avoid a script defect blocking normal development.

    6.3 Connecting External Tools: Linking to the Real World

    Through open protocols like the Model Context Protocol (MCP), AI coding tools can connect to external data sources and tool services in a standardized way—for example, an internal documentation knowledge base, a requirements management system, a monitoring platform, or a database. Once connected, the agent no longer relies solely on its training data; it can query real data directly to support its judgments.

    For example, when troubleshooting a production issue, the agent can query logs and monitoring services in turn, search the internal incident-handling handbook, and cross-reference the code to locate the root cause, forming a complete diagnostic chain. Three points to note in practice:

    • Follow the principle of least privilege, preferring read-only interfaces;
    • Validate the trustworthiness of external content to prevent malicious instructions in external data from causing “prompt injection”;
    • Keep a human approval step for sensitive systems.

    6.4 Skills and Sub-agents: Working Together

    When a task is too complex for a single session to handle, you need collaboration mechanisms:

    • Skill: Package the operating standards and processes of a specific domain into a reusable module, loaded on demand, avoiding stuffing all knowledge into the system prompt at once.
    • Sub-agent: A main agent dispatches independent tasks to multiple sub-agents, each maintaining its own context and running in parallel, with the main agent finally aggregating the results.

    Scenarios suited to sub-agents include cross-module codebase investigation, comparing multiple solution options, and large-scale repetitive changes. The value of sub-agents lies in “context isolation”: intermediate processes do not pollute the main session, and the main agent only receives distilled conclusions.

    For example, before a refactor, you can dispatch three sub-agents at once to analyze the call relationships of the API layer, business layer, and data layer respectively; the main agent aggregates them and then formulates a unified refactoring plan. When using sub-agents, also respect boundaries: when tasks are strongly dependent and need to exchange intermediate state frequently, splitting them instead adds coordination cost.

    7. Practice: Five End-to-End Cases

    The methodology of the first four parts must ultimately stand the test of real delivery. The following five cases cover typical scenarios from tool development to everyday office work.

    7.1 Command-Line Tools

    Scenario: Build a command-line tool for batch renaming and format conversion.

    Key points:

    • Use a spec document to define the command format, parameter definitions, and error exit codes first;
    • Have the agent implement parameter parsing, core processing, and output formatting in layers, decoupling each part for easier testing;
    • Use sub-agents to add test cases for each sub-command.

    Pitfalls to avoid: Avoid putting all logic into a single entry file; for a command-line tool, error messages and exit codes are themselves an “interface” and must be defined in the spec ahead of time.

    7.2 Mobile Apps

    Scenario: Build an iOS to-do app with SwiftUI.

    Key points:

    • First have the agent generate the project structure, clarifying the boundaries between the data model, view layer, and persistence layer;
    • Use the simulator preview provided by the system to quickly validate the UI;
    • Reference key view and model files via @file-path to keep context focused.

    Pitfalls to avoid: Agents tend to produce UIs that “compile but are laid out wrong.” Require it to follow platform design conventions (such as system margins and dynamic type), and check screen by screen with the preview tool.

    7.3 Web Apps

    Scenario: Develop a front-end/back-end separated task-management web app.

    Key points:

    • Define the API contract first, then have the agent implement the front end and back end separately;
    • Integrate type checking and front-end build commands into a Hook to guarantee commit quality;
    • Use sub-agents to handle the back-end APIs and front-end pages separately, with the main agent responsible for integration.

    Pitfalls to avoid: Mismatched API fields between front end and back end is a common problem. Generate API definitions from the spec document and have both sides work from the same definition to reduce integration rework.

    7.4 Contributing to Open Source

    Scenario: Submit a bug fix or feature contribution to an open-source project.

    Key points:

    • First use a sub-agent to map out the project structure, build process, and contribution guidelines;
    • Read existing similar implementations before making changes, and follow the project’s architecture style rather than introducing personal preferences;
    • After changes, run the project’s test suite and add corresponding tests.

    Pitfalls to avoid: The merge bar for open-source projects is usually higher than for internal projects. Strictly follow their coding standards and commit conventions, and avoid large-scale changes unrelated to the issue.

    7.5 Everyday Office Automation

    Scenario: Automate repetitive data-organizing and report-writing flows in non-technical work.

    Key points:

    • Use the agent’s file read/write and command execution abilities to write batch scripts that process spreadsheet data;
    • Connect to the internal document system via MCP so the agent can generate weekly-report drafts based on real material;
    • For files containing personal information, use a locally deployed model to safeguard data security.

    Pitfalls to avoid: Office data is often inconsistently formatted. Sample-check data quality first, and add validation and exception warnings in scripts, rather than blindly trusting automated results.

    8. From Personal Practice to Team Workflows

    Efficiency gains at the individual level are only the starting point. To make agent engineering deliver organizational value, teams also need supporting mechanisms:

    • Unified baseline configuration: Version-control project rules files, custom commands, and Hook scripts to ensure every member has a consistent working baseline.
    • Redraw collaboration boundaries: Define the “AI generates, human reviews” responsibility split across the team; agent-generated code follows the same review standards as human-written code.
    • Hold the security line: Never hand sensitive credentials like keys and tokens to the agent; keep a review step for commands the agent runs, and require human confirmation for high-risk operations; guard against prompt-injection risk when connecting external data.
    • Measure and retrospect continuously: Track metrics such as requirement delivery cycle, defect density, and code-review feedback rounds; periodically review which prompts, commands, and automation rules actually deliver value, and retire inefficient practices.

    9. Conclusion

    From Vibe Coding to agent engineering is, at its core, an upgrade in how we work: from “let AI write code for me” to “design an engineering system that lets humans and AI collaborate efficiently.” Throughout this process, the conversation is the development environment, context is a finite resource, decomposition is the new programming, tools are the nerve endings, and humans judge while AI executes. All five are indispensable.

    Models will keep iterating and tools will keep updating, but these principles will not go out of date. What truly determines delivery quality is not how powerful the model is, but whether developers can express requirements clearly, decompose tasks sensibly, and build solid quality guardrails. Starting today, pick a real task and run it once through the loop of “express requirements, manage context, decompose tasks, and verify results”—and you will already be standing at the starting line of agent engineering.