Agent Engineering in Practice: From Conversational Coding to Building Workflows

    This article explains why agent engineering is needed beyond conversational coding, and how to manage uncertainty introduced by natural-language intent and model reasoning. It covers a three-layer agent engineering structure, a four-part framework for expressing requirements, how to read the agent execution flow, context budgeting, long-term project memory files, debugging and correction practices, version control as a safety net, task decomposition, spec-driven development, refactoring and testing, custom commands and automation hooks, protocol-based external integrations, multi-agent collaboration, and a common delivery path across end-to-end scenarios. It also presents five mental models and a three-step adoption plan, with success measured by defect rate, rework, and delivery cycle time.

    1. Why Agent Engineering, Not Just Chatting

    Over the past two years, the capability boundary of AI coding tools has been pushed forward quickly: from completing a single line of code, to modifying code across files, to autonomously running commands, executing tests, and iterating on fixes. Many teams go through an initial “honeymoon period” when they first try these tools—describe a requirement in natural language, and the model returns a runnable skeleton in seconds. But once real project work begins, problems appear: fixing one thing breaks three others, changes drift further from the original intent, context becomes increasingly messy, and the same requirement produces different results each time.

    The root cause is not model capability but missing engineering methods. Traditional software engineering uses requirement documents, interface contracts, tests, and version control to constrain uncertainty. Agentic coding introduces a new source of uncertainty—natural-language intent and the model’s reasoning process. As a result, the “conversation” needs to be governed as a development environment, “context” needs to be managed as a finite asset, and “decomposition” needs to be treated as a new fundamental programming skill.

    Agent engineering can be understood as a three-layer structure: the bottom layer is model and tool execution capability, the middle layer is context and specification constraints, and the top layer is human judgment and acceptance criteria. If any of the three layers is missing, delivery quality becomes uncontrollable.

    2. Getting Started: State Requirements Clearly and Understand the Execution Flow

    2.1 Four Elements of Requirement Expression

    The most common failure in conversational coding is a requirement description that lacks verifiable information. A reusable expression framework has four parts:

    • Goal: the business or technical problem to solve, not the implementation approach;
    • Constraints: language version, dependency limits, performance and compatibility requirements;
    • Acceptance: what counts as done, ideally executable (tests, scripts, checklist items);
    • Boundaries: explicitly state which files must not be changed and which dependencies must not be introduced.

    Example (illustrative):

    1. Goal: Add batch import capability to a command-line tool
    2. Constraints: Use only the standard library; keep existing commands backward compatible
    3. Acceptance: Add unit tests covering three scenarios: empty file, very large file, and malformed format
    4. Boundaries: Do not modify the existing argument parsing structure

    2.2 Read the Conversation Execution Flow

    A typical agent task goes through: understand intent → retrieve context → make a plan → call tools (read files, write files, run commands) → observe results → revise the plan. Understanding this chain matters because when the result is wrong, you can locate whether the issue is a misunderstanding of intent, missing context, or insufficient tool feedback, instead of vaguely “trying again.”

    2.3 Model Replaceability and Cost Control

    Models differ significantly in reasoning, long-context handling, and code generation. Teams should maintain a “model-replaceable” architecture: decouple prompt templates, specification documents, and acceptance scripts from any specific model, so switching models does not require rewriting the workflow. In cost-sensitive scenarios, a tiered strategy can be used: lightweight models for simple tasks, and more capable models for complex refactoring and architecture decisions.

    3. Becoming Proficient: Context Is a Finite Asset

    3.1 Context Budget Awareness

    The context window is a scarce resource. An effective practice is layered loading: the global layer holds project conventions and the tech stack, the module layer holds interface definitions and data structures, and the task layer holds only the currently relevant files and error messages. Avoid stuffing the entire repository in at once; this wastes budget and also dilutes the weight of critical information.

    3.2 Long-Term Project Memory File

    Maintain a long-term memory document in the repository root (often called a project instruction file in the industry), recording build and test commands, directory responsibilities, coding conventions, prohibited practices, and common pitfalls. Its value is turning “content that has to be explained repeatedly each time” into a versionable asset that both new members and agents can share as the same context.

    Illustrative structure:

    1. # Project Conventions
    2. - Build: See the scripts directory; installing dependencies globally is prohibited
    3. - Test: Unit tests and static checks must be run before committing
    4. - Directories: domain holds business logic; infra holds external adapters
    5. - Prohibited: Do not write business branches in the controller layer

    3.3 Debugging and Correction

    The key to correction is providing “observable evidence”: the full error stack, reproduction steps, and the difference between expected and actual output. Avoid saying only “there is a problem here.” Also insist on small commits, where every step is rollback-able, so errors do not accumulate into composite failures that are hard to locate.

    3.4 Version Control as a Safety Net

    When agents modify code, follow a rhythm of “branch isolation + small-granularity commits + automated checks before commit.” Humans review the diff, focusing on interface contracts, boundary conditions, and error handling, rather than confirming style issues line by line.

    4. Mastery: Decomposition Is the New Programming

    4.1 How to Break Down Large Tasks

    For cross-module requirements, produce a plan before touching code. Recommended decomposition dimensions: by data flow (entry → domain → storage), by risk (build a validation prototype for the uncertain parts first), and by verifiable units (each subtask has independent acceptance). The plan should be written to a file and used as an anchor for subsequent conversations, preventing goal drift in long tasks.

    4.2 Spec-Driven Development

    The core of spec-driven development is writing “what to do” as a structured document: a glossary, use cases, interface contracts, exceptions and boundaries, and an acceptance checklist. The benefit of putting the spec first is auditability—both humans and agents work from the same document, and disputes are resolved at the document level rather than through repeated verbal clarification.

    Illustrative spec fragment:

    1. feature: batch_import
    2. input: file_path, delimiter
    3. rules:
    4. - Return a clear error code for an empty file
    5. - A single record failure does not block the whole process; output failure details
    6. acceptance:
    7. - Unit tests pass
    8. - Failure details can be consumed by downstream systems

    4.3 Refactoring, Testing, and Documentation

    Refactoring must keep “behavior unchanged,” so add characterization tests before changing structure, and change only one dimension at a time. Documentation and tests should be treated as part of the deliverable: update contract descriptions when interfaces change, and record the reasons and trade-offs for key decisions, so future maintainers do not have to rely on guesswork.

    5. Scaling Up: Breaking the Single-Instance Ceiling

    5.1 Custom Commands and Automation Hooks

    Turn high-frequency workflows into reusable command templates (such as “add an interface according to conventions” or “generate change notes”), and attach automation hooks at key points: run formatting and static checks before commit, and automatically sync the documentation index after writing. The goal of automation is to make conventions enforced by default, rather than relying on memory.

    5.2 Protocol-Based Connections to the Outside World

    Connecting to external systems through a standardized context protocol is key to moving agents from “writing code” to “getting things done.” Common integration targets include code hosting platforms, defect tracking systems, message queues, object storage, logging services, and monitoring and alerting—general cloud product categories. When integrating, follow three principles: least privilege, read-only first, and auditable operations.

    5.3 Skills and Sub-Agent Collaboration

    Complex tasks can use a “main agent plans + sub-agents execute in parallel” structure: the main agent handles decomposition and merging, while sub-agents each take on specialized work such as retrieval, testing, and documentation, with isolated contexts to avoid contamination. The key to collaboration is clear input/output contracts and a conflict-merging strategy.

    6. Practice: Common Methods Across Five End-to-End Scenarios

    Whether it is a command-line tool, a mobile app, a web app, contributing to an open-source project, or everyday office automation, the common path to successful delivery is highly consistent:

    1. Establish a long-term project memory and acceptance scripts;
    2. Use spec documents to lock down scope and boundaries;
    3. Implement and commit in small steps, keeping things rollback-able;
    4. Use automation hooks to ensure conventions are followed;
    5. Humans make the final judgment: architecture trade-offs, security boundaries, and user experience.

    7. Mental Models and Adoption Advice

    Five mental models run throughout: the conversation is the development environment, context is a finite asset, decomposition is the new programming, tools are the neural extensions, and humans are responsible for judgment while AI is responsible for execution. When introducing this, teams are advised to proceed in three steps: first pilot on low-risk modules and establish convention files; then automate acceptance and integrate it into the version control process; finally extend external connections and multi-agent collaboration. Metrics for measuring success should land on defect rate, number of reworks, and requirement delivery cycle time, rather than “how many lines of code were generated.”