Reconstructing Legacy Systems with Long Context and Multi-Agent Systems
This article explores how long context, multimodal analysis, and multi-agent collaboration can be leveraged for legacy system reconstruction and maintenance. It emphasizes moving beyond superficial model demonstrations to establish verifiable engineering workflows. Key topics include defining authorization boundaries, managing layered contexts, recovering system behavior through evidence-driven hypotheses, utilizing multi-agent division of labor, controlling engineering costs, and building a credible evaluation system to transform exploratory reconstruction into maintainable engineering practices.
1. From Model Experience to Engineering Capability Assessment
Evaluating next-generation large language models (LLMs) often falls into two traps: equating “the ability to read extensive materials” with “the ability to correctly understand a system,” and treating a single impressive demonstration as stable engineering capability. For legacy system maintenance, historical software migration, and decommissioned service reconstruction, these judgments are unreliable.
Such tasks usually lack complete design documentation. Developers must recover system behavior from clients, historical logs, public descriptions, operation videos, and scattered configurations. The real metric to evaluate is not whether the model can rapidly generate massive amounts of code, but whether it can complete a verifiable workflow:
Organize materials → Extract facts → Formulate hypotheses → Design experiments → Implement features → Verify results → Correct deviations.
Features involved in the user experience—such as long context, public data retrieval, video understanding, task allocation, and token consumption—all fit into this workflow. They respectively solve information capacity, evidence completion, behavior observation, execution organization, and resource management. However, no single capability can replace final verification.
Therefore, professional evaluation should revolve around four dimensions: Is the evidence reliable? Is the inference explainable? Is the implementation verifiable? Is the cost sustainable?
2. Define Authorization Scope and Reconstruction Goals First
2.1 System Reconstruction Does Not Mean Bypassing Restrictions
Before analyzing legacy software, the authorization boundaries for the software, data, and runtime environment must be clearly defined. Appropriate activities include proprietary system migration, authorized compatibility research, historical data recovery, and functional reconstruction within controlled environments.
Publicly visible materials do not inherently grant permission for unlimited copying, distribution, or commercial use. Client resources, video content, and historical data may involve copyright, personal information, or other rights. When dealing with server-side interactions, system research must not be extended into unauthorized access, credential harvesting, or bypassing protection mechanisms.
A more secure principle is: only analyze authorized materials, conduct experiments in isolated environments, avoid contact with unrelated real user data, and retain input sources, processing logs, and experiment records.
2.2 Distinguish Between “Behavioral Compatibility” and “Original Implementation Recovery”
Relying solely on the client usually cannot uniquely determine the entire server-side implementation. Different database structures, scheduling strategies, and business code can produce identical external behaviors.
Therefore, reconstruction goals should be divided into three tiers:
- Observable behavior compatibility: Given the same input and state, the system produces responses matching known evidence.
- Business rule reproduction: Recovering state transitions, data constraints, and key business processes.
- Internal implementation restoration: Restoring the original architecture and implementation details as much as possible, which requires more direct evidence.
Most legacy system projects should prioritize the first two tiers. For internal implementations lacking evidence, a reasonable new alternative can be chosen, but it must be labeled as an alternative implementation rather than claiming to have recovered the original logic.
3. The Value of Long Context Lies in Correlating Evidence, Not Hoarding Materials
3.1 Carrying More Information Does Not Mean Stable Use of All Information
Long context helps analyze multiple configurations, modules, and cross-file dependencies simultaneously, reducing information loss caused by frequent context switching. However, the longer the input, the more likely the model is to encounter factual conflicts, attention dispersion, and omission of key details.
For example, a historical document might describe an early version, while an operation video showcases later behavior. Without time and version annotations, the model might synthesize them into a system that never actually existed.
Therefore, before materials enter the analysis pipeline, a basic index should be established:
| Field | Purpose |
|---|---|
| Material ID | Supports reference and tracking |
| Source Type | Distinguishes code, config, docs, and video |
| Time & Version | Avoids mixing behaviors from different stages |
| Related Modules | Facilitates material selection by task |
| Credibility | Distinguishes direct evidence from second-hand descriptions |
| Authorization Status | Confirms allowed usage scope |
This organizational approach is more reliable than submitting all materials at once and makes model conclusions easier to review.
3.2 Adopt Layered Context Management
In practice, context can be divided into three layers:
The first layer is global constraints, including target scope, architecture overview, security boundaries, and glossary.
The second layer is current task evidence, containing only the configurations, code snippets, behavior records, and test results needed for the current round of analysis.
The third layer is the external evidence repository, storing complete raw materials, retrieved on demand, without continuously occupying the current task context.
Additionally, each stage should generate a structured handover record, separately listing confirmed facts, unverified hypotheses, and next steps. Summaries cannot fully replace raw materials; key conclusions must retain traceable evidence locations.
4. How to Recover System Behavior from Clients and Historical Materials
4.1 Establish an Evidence-Driven Analysis Checklist
Clients may contain field definitions, UI states, resource references, error prompts, and partial business logic, but this information is not necessarily complete and may contain deprecated logic.
During analysis, record item by item:
- Which fields the client actually sends or consumes;
- Which validations occur locally versus which require server confirmation;
- When state changes occur following operations;
- Whether retries, timeouts, duplicate submissions, or recovery flows exist;
- Whether configurations change across versions;
- Which conclusions are drawn from direct observation versus inference.
For example, discovering a numeric field only proves it participates in the interaction; it does not directly mean it represents a balance, points, or experience. It should be further verified against UI changes, field values, and preceding/following states.
4.2 Replace Direct Completion with “Hypothesis-Experiment-Result”
Models excel at generating plausible explanations, but plausible does not mean true. For uncertain behaviors, establish a hypothesis table:
| Hypothesis | Supporting Evidence | Verification Method | Current Status |
|---|---|---|---|
| A field represents object version | Field changes after update | Execute authorized updates sequentially and observe | Pending verification |
| Duplicate requests need deduplication | UI has duplicate submission protection | Submit identical requests in test environment | Pending verification |
| A state transition requires preconditions | Prompt appears on operation failure | Compare different initial states | Pending verification |
Verification should change one condition at a time to avoid unexplainable results caused by modifying multiple factors simultaneously. For projects lacking the original runtime environment, historical logs, videos, and known cases can be used for cross-referencing, but the coverage scope of such verification must be explicit.
4.3 Prioritize Recovering State Machines and Business Invariants
In legacy systems, what is most easily overlooked is not a single function, but state constraints between multiple functions. For example, whether the same operation can be repeated, whether resource deduction aligns with result generation, and whether connections can recover after an interruption can all affect overall reliability.
Define business invariants before implementing specific flows:
- Constrained resource quantities must not fall below legal lower limits;
- A single valid business operation must not produce duplicate side effects;
- State transitions must satisfy preconditions;
- Persisted results must match the results returned to the client;
- Failure recovery paths must not corrupt existing data.
These constraints can guide the model to generate implementations and can be translated into automated tests, preventing the system from only behaving correctly in normal flows.
5. How Public Materials and Video Analysis Supplement Evidence
5.1 Search Results Must Undergo Source Review
Public materials can supplement version changes, functional rules, and historical usage patterns, but search results may contain reprint errors, version confusion, and user speculation. The same statement repeated across multiple pages does not necessarily represent multiple independent evidence sources.
For key rules, prioritize finding traceable original materials, then cross-verify across different sources. Unverifiable conclusions can be treated as candidate hypotheses but should not be directly written into core business logic.
Retrieval targets should also be specific enough. For instance, “confirming the UI feedback after an operation failure” is more likely to yield usable results and controllable costs than “collecting all historical materials.”
5.2 Video Reveals Flows But Cannot Replace Internal Evidence
Video is suitable for observing operation sequences, UI changes, feedback timing, and visible states. However, footage usually cannot directly prove backend transaction boundaries, random rules, or server-side data structures.
The correct approach is to convert video into an event sequence:
Initial state → User action → Visible feedback → Subsequent state → Anomaly.
Attach timestamps and observation notes to each event, then correlate them with client logic, configurations, and historical records. This way, multimodal analysis provides reviewable behavioral evidence rather than unconfirmed internal architecture explanations.
6. The Key to Multi-Agent Collaboration is Division of Labor and Constraints
6.1 Multiple Execution Units Are Not Necessarily Faster
Parallel analysis is suitable for relatively independent work, such as material sorting, state modeling, test design, and implementation review. However, if multiple execution units modify core modules simultaneously, interface conflicts, duplicated effort, and inconsistent hypotheses are likely to occur.
A feasible role division is:
- Evidence Sorting Unit: Archives materials and establishes reference relationships;
- Behavior Analysis Unit: Proposes state models and unverified hypotheses;
- Implementation Unit: Develops features based on confirmed specifications;
- Testing Unit: Designs normal, boundary, and exception test cases;
- Review Unit: Checks evidence sufficiency, implementation deviations, and security risks.
The coordinator should be responsible for unifying specifications, managing dependencies, and approving major changes, rather than merely splitting tasks and waiting for results.
6.2 Use Task Contracts to Limit Excessive Autonomy
Models may proactively expand tasks, rewrite unrelated modules, or add unrequested features. While this autonomy is sometimes useful in the exploration phase, it can amplify risks in production environments.
Every task should clearly define input materials, allowed modification scope, output format, acceptance criteria, budget limits, and stop conditions. High-risk changes should require human confirmation. “Completing the task as much as possible” should not be interpreted as unlimited autonomous execution.
For example, when asked to fix a compatibility issue, restructuring the entire storage layer should be prohibited unless evidence already shows the original structure cannot meet the target and the change is approved.
7. Translate Quota Consumption into Explainable Engineering Costs
When evaluating costs, one should not only look at API call counts or subscription prices, but also factor in long context inputs, repeated retrievals, tool executions, parallel tasks, failed retries, and human review.
A more meaningful metric is:
Cost per effective delivery = Total resource cost ÷ Number of accepted deliverables.
Massive amounts of code that cannot pass tests cannot be considered effective output. Similarly, temporary quota restorations, limited-time discounts, or usage condition changes should not form the basis of a long-term budget.
Cost control can be approached from the following aspects:
- Classify and deduplicate materials before deep analysis.
- Load evidence by task to avoid repeatedly submitting full histories.
- Store confirmed facts and open hypotheses separately.
- Set retry limits for failures to prevent invalid loops.
- Arrange human checks at module boundaries to correct course promptly.
- Separately record costs for model processing, experiment execution, and human review.
These methods do not guarantee a fixed proportion of savings, but they reduce duplicated work and create a traceable relationship between resource expenditure and actual progress.
8. How to Build a Credible Acceptance and Evaluation System
“High fidelity” cannot rely solely on subjective experience, nor should a few successful scenarios be directly converted into an overall recovery ratio. Define a target feature list first, then measure separately:
- Feature Coverage: How many target features have been implemented;
- Behavioral Consistency: Whether evidence-backed inputs and outputs match expectations;
- Exception Reliability: Whether timeouts, duplicate submissions, and illegal states are handled correctly;
- Data Consistency: Whether business constraints still hold after interruption and recovery;
- Maintainability: Whether the implementation has clear boundaries, tests, and documentation;
- Evidence Coverage: How many key rules have been directly or cross-verified.
If evaluating the capabilities of different models, fix the input materials, authorized tools, budget, time limits, and acceptance criteria, and observe stability through multiple rounds of tasks. For original internal system behaviors that cannot be restored, the report should explicitly state “uncertain” rather than masking evidence gaps with precise numbers.
9. From Exploratory Reconstruction to Maintainable Systems
After the model assists in completing a prototype, it must transition into regular engineering governance. Use object storage to save authorized materials and experiment artifacts, version control to record changes, isolated runtime environments to manage dependencies, and logging, monitoring, and backup mechanisms to support operations.
Development, testing, and runtime environments should be separated; sensitive data usage should be minimized; logs must be appropriately desensitized; and important changes should undergo review, regression testing, and have rollback paths. Models can participate in documentation sorting, test generation, and issue classification, but the responsibility for production releases cannot be transferred to automated execution processes.
Overall, long context, multimodal analysis, and multi-agent collaboration can indeed improve the efficiency of legacy system research and reconstruction. Their most valuable role is helping developers organize complex evidence, discover correlations, and shorten verification cycles, rather than automatically turning incomplete materials into definitive answers.
Truly reliable practices must consistently adhere to: authorization first, traceable evidence, testable inferences, bounded tasks, accountable costs, and verifiable results. Only by forming this closed loop can LLM capabilities be transformed into sustainable engineering value.
