Trae Agent Automates Software Engineering with Three-Stage Problem Solving

author-Chen
Dr. Aurora Chen
Diagram illustrating Trae Agent's three-stage problem-solving process for automated software engineering: Patch Generation, Patch Pruning, and Patch Selection.

Trae Agent, an automated software engineer, addresses complex code-level problems by mimicking a collaborative engineering team. This advanced large language model (LLM)-based agent aims to bridge the gap between high success rates in independent function-level programming tasks and the significantly lower success rates observed in comprehensive code-level benchmarks like SWE-bench. While top LLMs such as GPT-4o achieve up to 92.7% success on isolated functions, their performance drops to 11.99% on the full SWE-bench test, highlighting the challenges Trae Agent is designed to overcome.

The agent's problem-solving process is structured into three core stages: Patch Generation, Patch Pruning, and Patch Selection.

Patch Generation

The initial stage focuses on generating a diverse array of potential solutions, or "patches," for a given software problem. This process is spearheaded by the "Coder Agent," which functions as the primary programmer.

The Coder Agent employs several strategies to produce candidate patches:

  • Parallel Generation: Multiple instances of the Coder Agent operate independently and in parallel, each creating a unique candidate patch. This parallel approach enhances the efficiency of solution discovery.

  • Enhancing Diversity: To ensure a broad range of solutions, Trae Agent utilizes a "high temperature sampling strategy." This encourages the agent to develop varied and creative solutions, increasing the likelihood of identifying an effective fix.

  • Utilizing a Toolbox: The Coder Agent is equipped with a comprehensive set of tools, similar to a human engineer's development environment. These tools include:

    • File editing tools: For viewing, creating, and modifying code files.

    • Command-line tools (Bash): For executing system commands and interacting with the codebase.

    • Structured thinking tools: These aid the agent in establishing a logical framework for problem-solving and tracking its thought processes, ensuring clarity and organization.

After generating numerous candidate solutions, the system proceeds to rigorously screen and refine these initial ideas.

Patch Pruning

The second stage, Patch Pruning, is designed to eliminate redundant and incorrect patches, thereby narrowing down the selection. This step is critical because the extensive "action space" and intricate "reasoning paths" of large language models often lead to the exploration of many divergent solutions in complex codebases. Data indicates that, on average, 40% of generated candidate patches are either redundant or incorrect. Pruning is thus a key strategy to mitigate inherent LLM weaknesses and improve overall efficiency and accuracy.

This stage comprises two main sub-steps:

Patch Deduplication

This step involves "merging similar drafts." The system "normalizes" each patch by removing elements that do not affect the code's actual logic, such as extra spaces, line breaks, and comments. Following this process, logically identical patches are identified, and only one version is retained, effectively reducing redundancy.