AI agents can accelerate the diagnosis of existing projects by investigating architecture, dependencies, duplication, apparently unused code, test coverage, and potential technical problems.

The proposal is not to replace traditional analysis tools, but to use agents to select and run those tools, investigate results, verify evidence, and produce organized recommendations.

This process can be applied to legacy projects, poorly documented systems, or applications that need modernization and refactoring.

1. Preparing the diagnosis

Before starting, it is important to define the investigation's objective and scope.

The agent needs to know whether it should evaluate the entire project or only certain areas, which problems should be prioritized, and what result is expected.

Some recommended instructions:

  • Initially work without modifying code.
  • Identify available tools before installing new dependencies.
  • Run commands in controlled environments.
  • Record tools used and their results.
  • Distinguish confirmed problems from suspicions.
  • Present evidence for each relevant finding.
  • Do not automatically start refactorings or deletions.

The diagnosis can be requested through a main prompt or working document that serves as a reference for the agents involved.

2. Initial project exploration

The first task is to direct the agent to explore the repository and understand its organization.

This stage may include:

  • Identifying technologies, frameworks, and versions.
  • Reading configuration files and manifests.
  • Recognizing main modules and directories.
  • Identifying entry points, services, and integrations.
  • Surveying existing scripts, tools, and tests.
  • Consulting project technical documentation.

The agent can use code searches, file inspection, and analysis tools to build an initial map.

Example instruction:

Explore the repository and identify:

- Technologies and frameworks used.
- Main modules and their responsibilities.
- Application entry points.
- Relevant dependencies and integrations.
- Analysis tools and tests already configured.
- Available technical documentation.

Do not modify the project.

Produce an architecture summary and indicate
which areas should be investigated in detail.

Exploration also helps determine which techniques and tools suit the stack found.

There is no need to load all code into context at once. The agent can progressively investigate relevant modules.

3. Investigation by specialty

After exploration, the diagnosis can be divided into specific investigations.

The agent should select tools compatible with the project, run analyses, and supplement the results with code inspections.

Some possibilities:

Area Techniques and tools
Architecture Import analysis, dependency graphs, call tracing, and tools such as dependency-cruiser
Dependencies npm outdated, npm audit, OSV-Scanner, and equivalent checks for the stack
Duplication jscpd, analysis of similar patterns, and investigation of repeated business rules
Unused code knip, static analysis, reference searches, and inspection of dynamic loading
Quality ESLint, SonarQube, type checkers, and language-specific analyzers
Tests Running existing suites, coverage reports, and mutation testing
Security Semgrep, CodeQL, dependency scanners, and configuration checks

These tools are examples, not a mandatory list. Selection should consider the language, project characteristics, and available resources.

How to guide an investigation

Instead of only asking the agent to find problems, specify how it should conduct the work.

Example — unused code analysis:

Investigate potentially unused components.

1. Identify tools compatible with the stack.
2. Check whether they are already available in the project.
3. Run analysis without modifying files.
4. Investigate the results found.
5. Check direct and dynamic references.
6. Consider routes, jobs, and external consumers.
7. Classify what has been confirmed and what
   still requires verification.

Report files, evidence, and recommendations.

Do not remove any component.

This procedure can be adapted for dependencies, duplication, architecture, or tests.

What matters is not automatically treating a tool's output as a definitive conclusion.

4. Parallelization with multiple agents

In larger projects, independent investigations can be distributed among specialized agents.

For example:

Agent Responsibility
A — Architecture Modules, services, internal dependencies, and flows
B — Dependencies Packages, versions, vulnerabilities, and unused code
C — Quality Duplication, inconsistencies, and maintenance problems
D — Tests Coverage, existing tests, and regression risks
Reviewer Verification of findings and consolidation of evidence

Each agent receives a defined scope, access to necessary tools, and a common format for presenting results.

This division allows different investigations to run simultaneously, avoiding everyone traversing the entire project performing the same checks.

A coordinating agent can monitor execution, identify overlaps, and request additional investigations.

There is no need to create permanent specialized agents for these activities. Responsibilities can be distributed among available coding agents using task-specific instructions.

In smaller projects, a single sequential execution may be more efficient.

5. Verifying findings

Tool reports and agent conclusions may contain false positives or incomplete interpretations.

Relevant results therefore need verification before becoming recommendations.

For example, an analyzer may identify a function without static references, but it may be used through dynamic imports, events, or external integrations.

Likewise, two similar implementations may serve different business requirements.

Verification can combine:

  • Additional reference searches.
  • Inspection of configuration and entry points.
  • Running existing tests.
  • Comparison between implementations.
  • Consulting documentation and contracts.
  • Independent analysis by another agent.

Reviewer agent

One strategy is to use an agent different from the one that produced the initial diagnosis.

Its responsibility is to compare conclusions against code and evidence rather than simply rewrite the report.

Example instruction:

Review the diagnostic findings.

For each item:
- Check the references presented.
- Confirm whether the problem actually exists.
- Investigate potential false positives.
- Identify insufficient evidence.
- Assess the stated technical impact.

Classify results as:
- Confirmed
- Potential
- Unconfirmed

Do not modify the project.

For higher-impact problems, especially those involving security, data, or critical architecture, confirmation may require additional validation and human review.

6. Consolidating results

Agents should use a consistent format to facilitate comparison, review, and prioritization of findings.

A record may contain:

  • Problem identification and description.
  • Affected files and modules.
  • Tools and commands used.
  • Evidence found.
  • Technical impact.
  • Confidence level.
  • Recommendation and pending checks.

Example finding:

## D-014 — Potentially unused service

Status: Potential
Impact: Low
Confidence: Medium

File:
src/services/legacyService.ts

Tools:
- knip
- Repository reference search

Evidence:
- No static references found.
- No direct imports identified.

Pending checks:
- Potential external consumers.
- Dynamic loading.

Recommendation:
Verify consumers before
considering removal of the service.

It is important to preserve the distinction between confirmed problems, potential risks, and improvement opportunities.

The consolidated report should eliminate duplicates, group related findings, and highlight those requiring further investigation.

It should also record analysis limitations, such as tools that could not run, unavailable tests, or modules not investigated.

7. Turning findings into an action plan

With the diagnosis verified, agents can help organize next steps.

Recommendations can be classified by impact, criticality, effort, risks, and dependencies.

The result can feed different activities:

Technical documentation

Update architectural maps, contracts, and project context files such as AGENTS.md or structures such as CHAOS, using only confirmed information.

Improvement planning

Group related problems, identify dependencies between changes, and propose an implementation sequence.

Ticket creation

Turn approved recommendations into tasks with an objective, scope, references, acceptance criteria, and necessary validations.

Refactoring preparation

Identify which tests or observability mechanisms need to exist before modifying critical components.

Turning a diagnosis into executable work should be a separate stage from investigation.

This allows priorities to be reviewed and recommendations that do not justify implementation cost or risk to be discarded.

Conclusion

The main benefit of AI agents in diagnosing existing projects is their ability to combine code investigation, tool execution, and contextual analysis in a coordinated workflow.

The strategy involves guiding initial exploration, selecting techniques appropriate to the project, distributing investigations, verifying findings, and standardizing results.

The goal is not to automate refactoring based on suspicions, but to use agents to produce verifiable diagnoses that help developers decide what actually needs improvement.

Sources and further reading