From Prompt Engineering to Agent Engineering: AI Coding Agents in Legacy-System Refactoring
This article examines the shift from prompt engineering to agent engineering in AI-assisted software development through a real-world refactoring test on a 28,000-line Java legacy system. It compares three interaction paradigms—editor-centric parallel agents, planning-first command-line agents with reflection, and traditional inline completion—across completion quality, token consumption, manual repair effort, and suitability for cross-service tasks. The findings highlight the growing importance of AGENTS.md, repository structure, tool exposure, feedback loops, and automated validation, and offer practical recommendations for teams adopting agentic coding workflows.
Industry Background: AI Coding Agents Enter a Platform Competition Phase
Competition in the AI coding space has clearly intensified. Media reports note that a large software vendor began adjusting internal developer authorization for third-party agentic coding tools and guiding teams to migrate to an in-house command-line coding assistant. Around the same time, several leading AI companies launched or upgraded their own agentic coding products. The rivalry among tool vendors reflects a broader trend: code completion alone is no longer enough, and the industry is competing for the entry point to agentic development workflows.
For developers, the more useful question is not which vendor’s tool to choose, but how the underlying technical paradigm is shifting: from an assistance model in which humans write prompts and AI completes code, to a collaboration model in which humans define goals and constraints while agents plan and execute autonomously. To validate the impact of this trend on real engineering work, our enterprise agent implementation team selected a genuinely difficult project for a side-by-side test.
Test Task Design: Refactoring a 28,000-Line Legacy System
The test target was a typical hotspot of technical debt: about 28,000 lines of Java code based on Spring Boot, spanning six microservices, using an old JPA configuration for persistence and a handwritten cache implementation. The refactoring requirements were:
- Introduce an abstraction layer supporting multiple payment channels (provider pattern) to replace a hardcoded single payment channel;
- Add temporal memory across task execution to ensure state continuity for long-cycle tasks;
- Add complete guardrails to constrain the agent’s modification boundaries;
- Fill in observability metrics and produce full test coverage and migration reports.
We used a unified repository guide file, AGENTS.md, to describe project conventions, module boundaries, and acceptance criteria, ensuring identical inputs across the three test rounds and eliminating variable interference.
Side-by-Side Comparison of Three Interaction Paradigms
Round 1: Editor-Centric Parallel Agent Mode
The full repository and guide file were input together, and parallel agent mode was enabled. The overall interaction took about 45 minutes, and code completion reached 70%, but typical local-optimum problems emerged:
- The payment abstraction layer still contained hardcoded logic, and multi-channel decoupling was not truly completed;
- Guardrail rules conflicted with business logic, and the agent oscillated between the two;
- Observability lacked core path metrics;
- Cross-service consistency was easily broken, requiring continuous manual corrective prompts.
Total token consumption was about 1.2 million, and post-hoc manual repair took 2.5 hours. The conclusion from this round was: editor-based agents are good at local modifications, but in cross-service, long-chain semantic tasks, much of the context-management cost is shifted to humans.
Round 2: Planning-First Command-Line Agent Mode
With the same repository and guide file, we switched to a plan-first, execute-later agent paradigm and enabled a reflection mechanism in which the agent automatically pauses between subtasks and reviews its own work. The difference was significant:
- Effective interaction time dropped to 18 minutes;
- The payment abstraction layer correctly adopted the provider factory pattern;
- Guardrails and temporal memory had clear implementation boundaries with no rule conflicts;
- Observability metrics were completed in one pass;
- Total token consumption was only about 42,000, and manual work was limited to 40 minutes of edge-case validation.
Round 3: Traditional Inline Completion Mode
For inline completion and small refactoring scenarios, the traditional mode remained the smoothest. But for cross-service agentic tasks with semantic constraints, it was clearly strained: developers had to switch among multiple sessions, and context depended entirely on the developer to maintain.
Core Conclusion: From Prompt Engineering to Agent Engineering
All three rounds point to the same judgment: prompt engineering is rapidly depreciating in the true agentic coding era. In the past, 80% of effort went into polishing a “perfect prompt.” Today, the more important task is to build an “operating system” for agents. Its core elements include:
1. AGENTS.md — project constitution: module boundaries, coding standards, acceptance criteria2. Repository structure — navigable by agents: clear directory semantics, single responsibilities3. Tool exposure — tests, builds, and static checks all scripted and callable by agents4. Feedback loop — failures detectable and rollbackable, agents can self-correct from errors
The engineering significance of the reflection mechanism deserves particular emphasis: rather than relying on humans to anticipate every pitfall in a prompt, it is better to let the agent automatically stop at subtask boundaries, review its own output, and look for patterns and potential defects. This effectively internalizes “manual correction” as an inherent part of the agent workflow, and it is also the key reason why the second round achieved both high token efficiency and high quality.
Practical Recommendations for Teams
- Write AGENTS.md before talking about efficiency: A high-quality project guide file often improves agent output more than any prompt technique.
- Automate validation: Unit tests, interface contract checks, and lint rules should be triggerable by the agent with a single command, forming a closed loop.
- Choose the interaction paradigm by task shape: Use inline completion for small changes, editor agents for medium refactoring, and planning-plus-reflection command-line agents for cross-service long-chain tasks.
- Pay attention to compliance and migration costs: Changes in the tool supply chain, such as vendor authorization adjustments, can happen at any time. Teams should keep workflows portable—repository structure, guide files, and automation scripts are assets that do not depend on a specific tool.
In the future, as major platforms continue to invest in agentic development, knowledge bases will no longer be static documents but “living systems” that can self-compile, detect contradictions, and generate associations. Teams that complete their agent engineering infrastructure early will gain a clear advantage in the next phase of efficiency competition.
