From Prompt Engineering to an Agent Operating System: Rethinking Legacy System Refactoring
This article examines how enterprise development teams are moving from prompt-driven coding and basic RAG toward agent-centered workflows. Based on a single benchmark involving a 28,000-line Java microservice system, it compares integrated IDE agents, terminal-based reasoning agents, and traditional code-completion tools, then outlines the project configuration, repository structure, least-privilege tooling, and feedback loops needed to operate coding agents safely.
Introduction: Coding Agents Enter the Deep End
Recently, some organizations have adjusted the authorization scope of their internal AI coding tools, suspending certain third-party terminal agents while promoting internally developed command-line coding assistants. At the same time, several developer-focused coding applications have accelerated their release cycles. This article does not evaluate any specific vendor. Instead, it examines what this trend means for enterprise software development.
In our team, code-related tasks account for more than 60% of daily engineering work. Over the past six months, our focus has shifted from heavy reliance on prompts and basic retrieval-augmented generation (RAG) to an architecture centered on agent workflows. To assess the practical capabilities of existing tools, we conducted a benchmark test.
Test Scenario: Refactoring a Typical Legacy System
The test subject was a legacy Java microservice system containing approximately 28,000 lines of code. It consisted of six independent services and relied on an outdated ORM framework along with a hand-written caching mechanism.
The refactoring had three objectives:
- Introduce a payment abstraction layer that encapsulates specific payment protocols, allowing the agent to call only a unified interface.
- Add temporal memory to critical business workflows.
- Implement guardrails to restrict the scope of changes the agent could make.
The task also required complete test coverage results and a system migration report. This type of work tests more than code generation. It also requires the agent to understand the system architecture and maintain context across multiple modules.
Observed Results: Comparing Three Types of Tools
The benchmark was run only once. Each category of tool processed the same repository and configuration file. The figures below are single-observation results, not statistically validated measurements.
The original test did not preserve complete records of model versions, dependency versions, parallelism settings, or token-counting methodology. The results should therefore be treated as qualitative reference points rather than a direct ranking of the tools.
Integrated IDE Agents
Observed behavior: Parallel multi-agent mode was enabled, and the task reached approximately 70% completion.
Measurements: Interactive execution took approximately 45 minutes and consumed more than 1.2 million tokens. Manual repair then required another 2.5 hours. During the test, foundation models of different sizes were used, but the original records did not indicate whether waiting and retry time were included in the elapsed time or whether cached tokens were included in the total token count.
Why it struggled: The tool hard-coded a specific payment protocol into the business abstraction layer. The guardrail mechanism also conflicted with the core business logic, while observability metrics were insufficient. When maintaining consistency across services, the agent tended to optimize locally and required continuous human prompting to correct its direction.
Recommendation: Parallel execution is appropriate for clearly bounded and independent subtasks. For changes spanning multiple services, teams should define and stabilize interface contracts first, then allow agents to modify components in parallel.
Terminal-Based Deep-Reasoning Agents
Observed behavior: The agent first created a global plan. Before executing each subtask, it actively paused to review code patterns and potential defects.
Measurements: Effective interaction time was approximately 18 minutes, with total token consumption of about 42,000. Human verification of edge cases required approximately 40 minutes.
Results: For the business abstraction, the agent adopted a factory pattern. The guardrails and temporal memory were implemented relatively cleanly, and the observability metrics were more complete.
In this single test, the self-review stage reduced the amount of manual rework. This conclusion requires validation through repeated experiments, since the results may change with different task sizes and model selections.
Traditional Code-Completion Plugins
Inline completion and small-scale refactoring remained the smoothest use cases. For complex, cross-service tasks, developers had to switch manually between multiple conversation windows, making context management entirely dependent on human intervention.
This category is included only as a reference for inline completion and limited-scope refactoring. It was not included in the evaluation of cross-service refactoring.
The Core Shift: From Prompt Engineering to an Agent Operating System
Prompts remained useful in this test, but their scope of influence became narrower. For complex tasks involving multiple services, long contexts, and multiple tool calls, prompts alone could not maintain stable results. Human engineers had to repeatedly correct the agent’s direction.
This does not apply to every scenario. Simple completion and small-scale refactoring still benefit from carefully written prompts and human review.
The broader lesson is that teams need to place constraints in a more stable location: the agent’s runtime environment. We view this environment as consisting of four elements.
Project-Level Configuration Files
These files define architectural boundaries, business rules, and prohibited operations. Example fields may specify protected paths, permitted dependencies, and the interface definition for the payment abstraction layer.
Configuration files should be version-controlled and reviewed alongside the code.
A Well-Defined Repository Structure
Each service should have clear interface definitions and dependency declarations. This allows the agent to read relationships between modules instead of inferring them through guesswork.
Least-Privilege Tool Exposure
Agents should have access only to necessary commands, such as compilation, unit testing, and static analysis. They should not be allowed to operate directly on production databases.
The narrower the tool surface, the smaller the potential impact of an incorrect operation.
A Feedback Loop
Code quality and architectural consistency should be checked automatically between subtasks. Acceptance metrics may include:
- Compilation success rate
- Changes in unit test coverage
- Number of guardrail violations
- Results of cross-service interface consistency checks
Five Questions for Selecting an Agentic Coding Tool
- Does the tool support project-level configuration that can be version-controlled with the code?
- Can the commands available to the tool be restricted according to the principle of least privilege?
- Does the tool record token consumption, execution time, and retry counts for later analysis?
- Can the tool pause between subtasks and produce results that humans can review?
- Can it run in an isolated branch or sandbox while preserving a rollback path?
Three common selection mistakes are especially important to avoid:
- Treating the result of a single test as sufficient evidence for tool selection.
- Allowing an agent to perform large-scale rewrites directly on the main branch.
- Asking an agent to evaluate its own output without defining clear acceptance criteria.
Operational Risk: Backups and Gradual Migration
Before refactoring, back up both the database and the source code. Perform the migration in batches, with a rollback point for every batch.
Test coverage reports and migration reports generated by an agent should be sampled and reviewed by humans. They must not be treated as final acceptance results without verification.
Outlook: From Static Knowledge Bases to Dynamic Knowledge Systems
Knowledge bases are also changing. In the future, a knowledge base may no longer consist only of static documents. It could become a dynamic system that continuously compiles information, detects logical contradictions, and generates relationships between data.
When an agent discovers inconsistent interface definitions in a codebase, such a system could first issue an alert and then provide repair suggestions based on the global context.
Combined with an Agent operating system, this type of dynamic knowledge graph could become important infrastructure for improving enterprise engineering efficiency. However, the technology remains at an early stage.
Teams can begin with small pilots, such as interface consistency checks, and expand the scope gradually after validating the results.
