Multi-Agent-Based Source Code and SQL Analysis System
Patent Information
- Application Number
- KR1020250205239
- Authority / Receiving Office
- KR · KR
- Patent Type
- Patents
- Current Assignee / Owner
- Filing Date
- 2025-12-19
- Publication Date
- 2026-09-21
- Estimated Expiration
- 2045-12-19
Smart Images

Figure R1020250205239_ABST
Abstract
Description
Technology Field
[0001] The present invention relates to an intelligent software development support tool utilizing a Large Language Model (LLM). Background Technology
[0002] The advancement of Large Language Models (LLMs) has spurred the proliferation of language model-based agent technologies that automatically interpret users' natural language requests and perform corresponding tasks. Particularly in the field of software development, the potential of LLMs as intelligent development tools—which analyze vast amounts of source code or generate SQL statements interacting with databases—is receiving significant attention. While such tools possess the potential to reduce the burden on human developers and increase development efficiency, various technical limitations are emerging during the actual implementation phase.
[0003] Conventional LLM-based analysis tools have a structural limitation in that they must provide the entire long source code as direct model input. When the source code length increases or multiple files are input simultaneously, not only is a massive token cost incurred, but performance degradation also occurs as the LLM fails to accurately extract core code regions directly related to user requests. This problem becomes more severe as the amount of contextual elements within the code—such as call relationships, dependencies, and comment information—increases.
[0004] Similar problems also arise in SQL analysis. SQL possesses a complex abstract syntax structure, and various semantic elements—such as join relationships, nested queries, and Common Table Expressions (CTEs)—combine to define the overall behavior of an SQL statement. Existing LLMs often fail to accurately understand this logical structure, frequently resulting in the generation of SQL that deviates from the user's intended logic or outputting grammatically incorrect SQL. Furthermore, when SQL is generated without prior knowledge of the database schema (table names, column names, etc.), problems occur where practically unusable results are produced, such as referencing columns that do not exist in the schema.
[0005] In particular, when using LLMs with relatively low performance or lightweight capabilities, these source code analysis and SQL generation errors become more pronounced, and structural limitations exist that make it difficult to balance analysis accuracy with execution costs. Consequently, conventional technologies face the problem of being unable to reliably provide high-quality analysis and SQL generation capabilities in actual development environments, and a new structural approach is required to address this issue. The problem to be solved
[0006] The present invention is proposed to overcome the limitations of the prior art described above, and its main purpose is to simultaneously improve the efficiency and accuracy of source code analysis and SQL analysis and generation processes by applying a multi-agent-based structure. First, regarding source code analysis, the present invention provides a technology that eliminates the inefficiency of the conventional method, which required directly inputting the entire vast source code into the LLM, and effectively reduces token processing costs by concisely compressing and summarizing the core information of the input code and delivering it. Additionally, another objective is to dramatically improve code search capabilities and the accuracy of analysis results by establishing a foundation that enables the LLM to accurately search for and interpret the meaning of code areas required by the LLM through code block-based structuring, tree-based hierarchical management, refinement of comment information, and keyword prioritization.
[0007] Furthermore, regarding SQL analysis and generation, the present invention aims to improve the analysis accuracy of the LLM by introducing a dedicated SQL analysis module to reduce errors that occur when the LLM interprets complex abstract SQL syntax alone. This is achieved by providing internal structural elements of SQL—such as tables, columns, join relationships, and CTE flows—in a clearly defined information format. In addition, during the SQL generation process, the invention provides a technology that enables the automatic generation of highly reliable SQL statements by detecting syntax errors or schema non-conformities in advance through an SQL validation module and by having an SQL evaluation agent repeatedly evaluate and correct the suitability of the generated results.
[0008] Through this series of objectives, the present invention presents structural improvements necessary for LLM-based development tools to be reliably utilized in actual field operations, and has significant technical significance in greatly enhancing the practicality and technical completeness of intelligent development environments by simultaneously securing accuracy and efficiency in complex code and SQL analysis tasks. means of solving the problem
[0009] To solve the above problem, an analysis method executed on a computing device that performs multi-agent-based source code and SQL analysis according to the present embodiment comprises: receiving an input and a request including code or SQL from a user; classifying a task type for processing a request based on the input and request; performing a preliminary information processing and analysis procedure on the input code or SQL corresponding to the task type; and generating a response corresponding to the user request based on the result of the analysis procedure.
[0010] The step of classifying the above work types can classify requests into one of code analysis, SQL analysis, SQL generation, or simple query response.
[0011] The above-mentioned preliminary information processing step can be configured into summarized code information by extracting at least one of a filename, dependency, global variable, comment information, or function / class inclusion relationship from a code file.
[0012] The above-mentioned preliminary information processing step can be configured into structured SQL information by extracting at least one of a table, column, common table expression, join condition, or data flow relationship from an SQL statement.
[0013] The step of performing the above analysis procedure may include, in the case of a code analysis type, a process of evaluating the relevance of summarized code information and user requests to search for necessary code blocks step by step.
[0014] The above evaluation of relevance may include at least one of summarizing the code block, deriving code interpretation information, and calculating a suitability score with the query.
[0015] In the case of the SQL generation type, the step of performing the above analysis procedure preferably involves generating SQL based on user requirements and schema information, and finalizing the SQL by performing at least one of syntax checking or schema conformity checking on the generated SQL.
[0016] The above SQL confirmation may include a procedure of rewriting the SQL based on the inspection results and repeating the above inspection step.
[0017] To solve the above problem, a computing device for performing multi-agent-based source code and SQL analysis according to the present embodiment includes a processor and a memory communicating with the processor, wherein the memory stores instructions for the processor to perform operations, and the operations include an operation of receiving an input and a request including code or SQL from a user, an operation of classifying a task type for processing a request based on the input and request, an operation of performing a preliminary information processing and analysis procedure on the input code or SQL corresponding to the task type, and an operation of generating a response corresponding to the user request based on the result of the analysis procedure. Effects of the invention
[0018] According to the present invention, by performing source code analysis and SQL analysis and generation functions based on a multi-agent system, problems raised in conventional technology, such as token costs, reduced analysis accuracy, and difficulty in understanding SQL structures, can be effectively improved. First, regarding source code analysis, by structuring vast amounts of source code through a code information extraction module and summarizing only key elements to provide to the LLM, token usage is significantly reduced and processing efficiency is improved compared to the existing method of directly inputting the entire code. Furthermore, through structural analysis at the code block level, treeing of function and class inclusion relationships, and refinement and prioritization of comment information, the LLM can more accurately detect code areas actually related to user requests, thereby greatly increasing search accuracy and analysis reliability. The search state management module determines the appropriate end point of the search by cumulatively reflecting relevance evaluation results, thereby reducing unnecessary repetitive calculations and providing the effect of shortening the overall processing time while maintaining analysis quality.
[0019] The present invention also realizes significant improvements in terms of SQL analysis and generation. By structurally decomposing SQL statements and clearly providing information such as tables, columns, join relationships, and CTE dependencies, the SQL analysis module significantly reduces semantic misunderstandings or analysis errors that may occur when interpreting SQL statements using LLM alone. During the SQL generation process, the SQL inspection module detects syntax errors or database schema inconsistencies in advance, and the SQL evaluation agent repeatedly verifies and corrects the suitability of the generated SQL. Consequently, high-quality SQL that meets user requirements and database structures can be reliably generated. This structure based on iterative verification enhances the reliability of the automated SQL generation process and offers the advantage of guaranteeing a level of accuracy suitable for use in actual development environments.
[0020] This invention establishes a technical foundation that enhances the practical applicability of LLM-based development tools and provides an advanced analysis system capable of processing complex development objects, such as source code and SQL, with sophistication and efficiency. Through this, developers can significantly reduce the time spent on code analysis and SQL writing, and by reducing errors and inefficiencies caused by the limitations of LLM, they can achieve the effect of simultaneously improving quality and productivity. Brief explanation of the drawing
[0021] FIG. 1 is an exemplary diagram showing a system configuration according to one embodiment of the present invention. FIG. 2 is an exemplary diagram showing the configuration of a specific response server according to one embodiment of the present invention. FIG. 3 is a flowchart illustrating a multi-agent-based analysis method according to one embodiment of the present invention. FIG. 4 is an illustrative diagram showing an example of code information extraction according to one embodiment of the present invention. FIG. 5 is an exemplary diagram showing the operation of an agent and a module within a code analysis unit according to an embodiment of the present invention. FIG. 6 is an exemplary diagram showing the operation of an agent and a module within an SQL analysis unit according to an embodiment of the present invention. FIG. 7 is an illustrative diagram showing an example of SQL analysis according to one embodiment of the present invention. FIG. 8 is an exemplary diagram showing the operation of an agent and a module within an SQL generation unit according to an embodiment of the present invention. FIG. 9 is an exemplary diagram showing the implementation of a method according to one embodiment of the present invention in the form of a computing device. Specific details for implementing the invention
[0022] Hereinafter, specific embodiments of the present invention will be described with reference to the drawings. The following detailed description is provided to facilitate a comprehensive understanding of the methods, apparatuses, and / or systems described herein. However, this is merely illustrative and the present invention is not limited thereto.
[0023] In describing the embodiments of the present invention, detailed descriptions of known technologies related to the present invention are omitted if it is determined that such descriptions may unnecessarily obscure the essence of the invention. Furthermore, the terms described below are defined considering their functions in the present invention, and these definitions may vary depending on the intentions or practices of the user or operator. Therefore, their definitions should be based on the content throughout this specification.
[0024] The terms used in the detailed description are merely for describing embodiments of the invention and should not be limiting in any way. Unless explicitly stated otherwise, expressions in the singular form include the meaning of the plural form.
[0025] In this description, expressions such as "include" or "include" are intended to refer to certain characteristics, numbers, steps, actions, elements, parts or combinations thereof, and should not be interpreted to exclude the existence or possibility of one or more other characteristics, numbers, steps, actions, elements, parts or combinations thereof other than those described.
[0026] In addition, terms such as first, second, etc. may be used to describe the compartment elements of the embodiments of the present invention. These terms are used merely to distinguish the compartment element from other compartment elements, and the essence, order, or sequence of the compartment element is not limited by the terms.
[0027] Various embodiments of the present invention will be described in detail below with reference to the attached drawings.
[0028] FIG. 1 is an exemplary diagram showing a system configuration according to one embodiment of the present invention.
[0029] The system according to the present embodiment may be composed of a user terminal (10) and a response server (300).
[0030] The user terminal (10) used in the present invention refers to a device for a user to input source code, SQL statements, or natural language-based queries and to receive analysis or generation results from a response server (300), and may include any computing device capable of network connection, such as a PC, laptop, tablet, or smartphone.
[0031] The response server (300) refers to a server (300) system that receives input from a user terminal (10), performs various development support tasks such as source code analysis, SQL analysis, and SQL generation, and provides the results to the user terminal (10).
[0032] The present invention may include a multi-agent structure in which a plurality of functional agents cooperate with each other. Here, an agent is an execution unit configured to perform specific functions based on reasoning capabilities based on a large language model, and can perform roles such as intent analysis, code search, relevance check, SQL analysis, SQL generation, and response generation.
[0033] The system of the present invention is composed of a user terminal (10) and a multi-agent-based response server (300), and the user inputs a source code file, an SQL statement, or a natural language query requesting analysis or generation through the user terminal (10) and transmits it to the response server (300) via a network.
[0034] When the response server (300) receives input from the user terminal (10), it first calls the intent analysis agent (310) to classify whether the request corresponds to a type of code analysis, SQL analysis, SQL generation, or simple query response. Depending on the classified intent, the server (300) enters a preliminary information processing step to perform the corresponding task. If source code is included, the code information extraction module (320) analyzes the code structure to generate a code context consisting of filenames, dependencies, global variables, comment information, and inclusion relationships of functions and classes. If SQL is included, the SQL analysis module (354) parses the SQL statement to derive structural information such as table and column structures and join relationships. This preliminary information processing process provides a foundation for the agent to operate efficiently in each subsequent analysis branch.
[0035] Subsequently, the response server (300) branches the task according to the intent classification result. If code analysis is required, the server (300) searches for relevant code blocks based on the code context and user request through a code search agent (342), and calculates a summary of the code block, knowledge that can be derived from the code, and a relevance score with the query using a relevance check agent (344). The search state management module (346) calculates the cumulative relevance based on these scores to determine the need for further search, and if it is determined that sufficient information has been obtained, it terminates the search and moves to the response generation stage.
[0036] When SQL analysis is required, an SQL extraction agent (352) extracts SQL statements from the input, an SQL analysis module (354) performs structural analysis, and subsequently, response generation agents (348, 356, 370) convert the analysis results into natural language responses. When SQL generation is required, an SQL generation agent (362) generates the initial SQL based on user requirements and schemas, and an SQL inspection module (364) verifies the syntax and schema suitability of the SQL. The SQL analysis module (354) analyzes the generated SQL structure to provide information necessary for evaluation, and an SQL evaluation agent (368) scores the SQL suitability; if it falls below the standard, the SQL is rewritten and the same procedure is repeated. If the request corresponds to a simple query, the response generation agents (348, 356, 370) directly generate the response without going through a separate analysis step.
[0037] Finally, the response generation agent (348, 356, 370) integrates the code information derived from each branch, the SQL analysis result, or the SQL generation result to generate a final response in natural language form and transmits it to the user terminal (10). Through this system configuration and operation method, the present invention can efficiently and accurately support complex development tasks related to source code and SQL by combining the simple input / output function of the user terminal (10) with the advanced multi-agent processing structure on the server side (300), and can achieve technical effects such as reducing token costs, improving structural analysis, and ensuring reliability based on iterative verification.
[0038] FIG. 2 is an example diagram showing the configuration of a specific response server (300).
[0039] FIG. 2 illustrates a processing structure performed within a multi-agent-based response server (300) according to the present invention, schematically showing how a final response is generated through data flow and operation procedures between a code information extraction module (320), a code repository (330), various functional agents, and an analysis module after a user's request is input into the server (300).
[0040] The response server (300) first receives code metadata or source code files input along with the request from the user and transmits them to the code information extraction module (320). The code information extraction module (320) analyzes filenames, dependencies, global variables, comments, and the inclusion structure of functions and classes from the input code to generate summarized code information, and the analyzed information is stored in the code repository (330). This preprocessing process is utilized as base data to enable subsequent agents to perform search and analysis tasks more efficiently.
[0041] The user request is simultaneously transmitted to an intent analysis agent (310), and the intent analysis agent (310) classifies which branch the request belongs to among code analysis, SQL analysis, and SQL generation. The classification result is transmitted to each branch's agent group to perform the corresponding task.
[0042] When classified as code analysis, the server (300) calls a code search agent (342) to search for code blocks related to the user request based on the code tree and code meta-information stored in the code repository (330). The discovered code blocks are passed to a relevance check agent (344), which calculates a code summary, knowledge extractable from the code, a relevance score with respect to the user request, etc.
[0043] The results of the relevance check are transmitted to the search status management module (346) to evaluate the accumulated relevance and to determine whether to perform additional searches. If the search status management module (346) determines that sufficient relevance has been secured, the information collected so far is transmitted to the response generation agent (348), and the final response generation procedure is performed.
[0044] When classified as SQL analysis, the SQL extraction agent (352) identifies and extracts SQL statements from user input or uploaded files, and the extracted SQL statements are transmitted to the SQL analysis module (354) to perform structural analysis such as parsing structure, table and column configuration, CTE dependency relationships, and JOIN conditions. The analyzed results are transmitted to the response generation agent (348) and converted into a response containing explanations or analysis content suitable for the user request.
[0045] When classified as SQL generation, the SQL generation agent (362) generates an initial SQL statement based on user requirements and a database schema, and the generated SQL statement is passed to the SQL inspection module (364) to verify syntax accuracy and schema suitability.
[0046] Even if the inspection result is normal, the SQL analysis module (354) reanalyzes the SQL structure to provide structural information to be used for subsequent evaluation. The SQL evaluation agent (368) synthesizes the inspection and analysis results to evaluate whether the SQL matches user requirements, and if the evaluation score falls below the standard, it instructs the SQL generation agent (362) to rewrite it and repeats the same procedure. SQL statements that pass the evaluation are transmitted to the response generation agents (348, 356, 370) and configured into the final response form.
[0047] As such, the internal structure of the server (300) shown in FIG. 2 is a visual representation of a series of procedures in which an intent analysis agent (310) branches a request based on a code information extraction module (320) and a repository, and multiple agents and analysis modules corresponding to each type of task operate cooperatively to generate a final response. Through this, the server (300) can select an appropriate analysis path according to the type of user request and provide a highly reliable response through step-by-step verification.
[0048] Below, the processing process for a specific response is explained with reference to Fig. 3.
[0049] Figure 3 defines a series of processing procedures for automatically analyzing source code and SQL or generating SQL based on a multi-agent system, and consists of a four-step flow performed on a computer device.
[0050] First, the system receives source code, SQL statements, or natural language-based requests input through a user terminal (10) (S100). In this input stage, not only the file itself but also the user query is received, and is used as basic data to identify the analysis targets and requirements needed in the subsequent processing stage.
[0051] Next, based on the received input and request, the system classifies whether the request corresponds to a specific task type, such as code analysis, SQL analysis, SQL generation, or simple query response (S200). This step is performed by an agent that conducts intent analysis and determines the purpose of the request to select the appropriate analysis procedure to be executed subsequently. Through this, the system can exclude unnecessary processing steps based on the nature of the request and efficiently perform tasks through branches optimized for the corresponding task.
[0052] Subsequently, the system performs preliminary information processing and analysis procedures on the input code or SQL according to the classified task type (S300). For example, in the case of code analysis, information such as code structure, comments, and dependencies is extracted from the source code, and related code blocks are explored; in the case of SQL analysis, SQL statements are parsed to structurally analyze tables, columns, Common Table Expressions (CTEs), join relationships, etc. In the case of SQL generation, initial SQL generation, syntax and schema checks, and structural analysis and evaluation may be performed repeatedly. These preliminary information processing and analysis procedures are carried out through the cooperation of agents and modules for each branch, and are a key step for accurately interpreting user requests and deriving analysis or generation results with high reliability.
[0053] Finally, the system generates a response corresponding to a user request based on the results derived from the above analysis procedure (S400). In this step, an analyzed code description, a structural interpretation of SQL, a generated SQL statement, or a natural language response to a simple query may be generated, and the response generation agent (348, 356, 370) comprehensively reflects the analysis information accumulated in the previous step to complete the final response. The completed response is transmitted to the user terminal (10) and provided so that the user can check it immediately.
[0054] Through this series of flows, the analysis method of the present invention can efficiently handle everything from identifying the purpose of user input to preprocessing, analysis, and response generation, and can provide high accuracy and flexibility even in complex development tasks through a multi-agent structure.
[0055] The specific analysis method according to the present embodiment is described below by classifying it according to the classification.
[0056] [Code Analysis]
[0057] The code analysis function according to the present invention is performed by multiple agents and modules operating sequentially and cooperatively within the server (300) when a user inputs a request including source code. This process is broadly divided into a preliminary code information extraction step, a code analysis step, and a response generation step, and each step is further composed of detailed procedures.
[0058] First, when a user submits a request including code analysis, the system forwards it to an intent analysis agent (310) to classify the request. After the intent analysis agent (310) identifies that the request is a code analysis task, it forwards the input code file or code metadata to a code information extraction module (320). The code information extraction module (320) performs a structural analysis of the code to extract filenames, dependencies, global variables, comment information, inclusion relationships of functions and classes, etc., and generates a summarized code context composed of these. The generated context is stored in a code repository (330) and is subsequently used as reference material for the code search process.
[0059] Specifically, the code information extraction module (320) according to the present invention analyzes the input source code and automatically generates various meta-information and structural information that can be utilized in subsequent code search and relevance evaluation steps.
[0060] FIG. 4 is an illustrative diagram showing an example of code information extraction according to one embodiment of the present invention.
[0061] Referring to FIG. 4, the system first receives a source code file uploaded or entered by a user and transmits it to a code information extraction module (320). The module scans the entire source code to identify import statements of external modules corresponding to dependencies. In the example code, import math exists, which is included in the dependency list as key information indicating that the code depends on an external math library.
[0062] In the following step, global variables declared in the global scope of the code are extracted. In the example code, DEFAULT_RADIUS = 5 corresponds to this. Since these global variables are configuration values that affect the operation of the entire code, the analysis module stores them as separate metadata items.
[0063] Next, the code information extraction module (320) collects comments included in the code. In the example, there are comments such as # basic radius value and class that calculates the area of a circle, and the module separates these, breaks them down into words, refines them into meaningful phrases, and compiles them into comment information. This comment information is used as natural language-based context data that explains the intent of the code, and subsequently helps the agent improve the accuracy of search or analysis.
[0064] Additionally, the code information extraction module (320) analyzes the structure of the code and generates a source code tree. This is represented as a hierarchical structure reflecting the inclusion relationships of functions, classes, etc., and in the example code, the following tree is constructed.
[0065] class Circle is identified as the top-level class node.
[0066] Inside the class, two function nodes (__init__, area) are connected as children.
[0067] Outside the class, the print_area function is added as an independent function node.
[0068] Since the Circle class declaration contains an adjacent comment explaining it (a class that calculates the circle's area), that comment is included in the adjacent_comments item.
[0069] The source code tree constructed in this manner represents the structure of the code in an abstract form and serves as core data to support searching by specific functions or classes in subsequent stages. In particular, in this invention, instead of directly transmitting the code block itself to the LLM, only this tree structure and meta-information are input first, thereby reducing token costs while accurately reflecting the entire code structure.
[0070] In summary, the code information extraction module (320) automatically selects and compresses meaningful information from the original source code and organizes it into summarized code information through a series of procedures including (1) dependency analysis, (2) global variable extraction, (3) comment refinement, (4) code structure parsing and source code tree generation. This plays an important role as a preliminary step for the multi-agent-based code analysis system to operate efficiently and accurately.
[0071] The next step is the code analysis step, which corresponds to the core processing flow of the present invention.
[0072] FIG. 5 is an example diagram showing the operation of an agent and a module within a code analysis unit (340) according to one embodiment of the present invention.
[0073] Referring to FIG. 5, multiple agents operate sequentially to search for and analyze code blocks related to a user request. First, a code search agent (342) is executed to search for code blocks within a code repository (330) based on a user query and code context. This agent identifies code blocks likely to be related to the request using at least one method among source tree-based search, keyword-based search, or file-wide search, and passes the blocks to a subsequent step.
[0074] The searched code block is then transmitted to a relevance check agent (344). The relevance check agent (344) summarizes the contents of the received code block, derives code interpretation information such as the functional meaning or data flow of the code, and calculates a relevance score that quantifies the relevance to the user query. This relevance evaluation enables not only a local judgment on a single code block but also a cumulative judgment on all code blocks analyzed so far.
[0075] The results of the relevance check are immediately transmitted to the search status management module (346). The search status management module (346) determines whether the analysis conducted so far is sufficient to resolve the user query based on the accumulated code summary and relevance information. If it is not sufficient, the module instructs the code search agent (342) to perform additional searches to continue exploring related code blocks. On the other hand, if it is determined that the accumulated relevance score meets the threshold, the additional search is stopped and the process proceeds to the next step. This management method can increase search efficiency and reduce LLM-based analysis costs by minimizing the search of irrelevant code.
[0076] When the search phase is completed, the collected code blocks and relevance information are transmitted to the response generation agent (348). The response generation agent (348) constructs a final response to the user query based on the code summary, code interpretation information, and accumulated knowledge obtained so far. The response is generated in the form of natural language and can take various forms depending on the user request, such as a description of the function of the analyzed code, the operation method of the logic, identification of the cause of the problem, and suggestions for improvement.
[0077] As such, the code analysis procedure according to the present invention is composed of a stepwise and hierarchical structure of code information extraction -> code search -> relevance check -> search status management -> response generation, and accurate and efficient code analysis can be realized by multiple agents operating cooperatively.
[0078] [SQL Analysis]
[0079] The SQL analysis function according to the present invention is performed in such a manner that when a user inputs a request including an SQL statement, an intent analysis agent (310), an SQL extraction agent (352), an SQL analysis module (354), and a response generation agent (356) operate sequentially within the server (300). The SQL analysis process is processed along an independent branch separate from the code analysis process and is configured in multiple stages to automate the accurate identification and analysis of the SQL structure.
[0080] FIG. 6 is an example diagram showing the operation of an agent and a module within an SQL analysis unit (350) according to one embodiment of the present invention.
[0081] Referring to FIG. 6, in the first step, a response server (300) that receives a user request transmits input to an intent analysis agent (310). The intent analysis agent (310) analyzes the purpose of the user request and classifies the request as an SQL analysis task. This task can be determined based on whether there are SQL syntax elements in the request statement, analysis-oriented phrases included in the user expression, or whether SQL code is included in the file upload. If it is determined that SQL analysis is required, the system enters the SQL analysis branch.
[0082] In the next step, the SQL extraction agent (352) operates. The SQL extraction agent (352) identifies and separates actual SQL statements from the user's input prompt or uploaded file. Since the user can input both natural language descriptions and SQL syntax, in this step, the task of accurately extracting SQL statements based on SQL syntax components such as SELECT, WITH, JOIN, and INSERT present in the text is performed. If there are multiple SQL statements, they are separated into sentence units and configured as individual analysis targets.
[0083] Once SQL extraction is complete, the extracted SQL statement is transmitted to the SQL analysis module (354). The SQL analysis module (354) is a core module that generates structured SQL information by syntactically parsing the input SQL statement. This module first checks whether the statement can be interpreted correctly (syntactic compatibility, syntax linkage, etc.) through the parsing of the SQL. Subsequently, it automatically analyzes the table names, column names, Common Table Expression (CTE) definitions and reference relationships, JOIN conditions and JOIN types, subquery structures, and data flow relationships used in the SQL statement. For example, it generates structured analysis information by identifying how a CTE defined in the WITH clause is used in a subsequent SELECT statement, and which column criteria the JOIN clause is based on. This analysis process is utilized not only for semantic interpretation of the SQL but also as supporting data for responding to user queries.
[0084] FIG. 7 is an illustrative diagram showing an example of SQL analysis according to one embodiment of the present invention.
[0085] Referring to FIG. 7, the SQL analysis module (354) performs the function of parsing an input SQL statement and subdividing it into structural information units to clearly interpret the logical components of the SQL. In the example, a SELECT statement including a WITH clause is given as input SQL, and the analysis module converts it into structured SQL information through the following multi-step procedure.
[0086] First, the SQL analysis module (354) parses the input SQL statement to identify which dialect the SQL is written in and checks whether it has been grammatically interpreted correctly. In the example of the drawing, the automatically detected dialect is determined to be 'oracle', and the parsing status is displayed as SUCCESS. This parsing information serves as a basis for determining whether subsequent analysis is performed correctly.
[0087] Next, the analysis module separates and identifies the key components included in the SQL statement into data information items. First, it checks whether a Common Table Expression (CTE) defined in the WITH clause exists; in the example, it analyzes that a single CTE named 'active_accounts' is defined. Subsequently, it identifies the tables referenced in the SELECT or JOIN clauses, and 'account', 'active_accounts a', 'customer c', 'transaction t', etc., are extracted as table information. Additionally, it analyzes and lists all column items referenced in the SQL statement; in the example, it confirms that various columns such as customer_id, account_id, balance, customer_name, and transaction_amount are included.
[0088] Furthermore, the analysis module analyzes dependencies within the SQL to visually structure the data flow. In the example, since the CTE 'active_accounts' is generated from the 'account' table, the relationship 'active_accounts -> account' is recorded in the CTE Dependencies section. Additionally, the dependencies between the tables referenced in the main SELECT statement and the CTE are analyzed, ultimately revealing that the MAIN QUERY is executed based on tables such as 'customer', 'transaction', 'active_accounts', and 'account'. This analysis of dependencies is an essential element for accurately understanding the logical processing order and data flow of SQL.
[0089] The SQL analysis module (354) analyzes the JOIN syntax performed in the SQL statement to structurally organize the type of JOIN, the join condition, and the data relationship created through the join. The SQL statement in the example drawing includes INNER JOIN and LEFT JOIN, and the following analysis is performed for each JOIN. First, in the case of INNER JOIN, a join is performed between 'customer c' and 'active_accounts a', and the condition is 'c.customer_id = a.customer_id'. Then, LEFT JOIN is performed between the result set joined earlier and 'transaction t', and the condition is 'a.account_id = t.account_id'. Each JOIN relationship is recorded together with the JOIN number, the relationship type, and the connection condition, so that the relational structure of the SQL can be clearly expressed.
[0090] In this way, the SQL analysis module (354) parses the input SQL statement to break down elements such as CTEs, tables, columns, dependencies, and JOIN relationships step by step, and reconstructs them into structured information, thereby enabling a clear understanding of the semantic structure of the SQL. This example is an example of the processing steps performed by the SQL analysis module (354), and the SQL analysis function of the present invention can effectively contribute to simplifying the complexity of SQL statements and improving analysis accuracy.
[0091] When the analysis is completed in the SQL analysis module (354), the result is transmitted to the response generation agent (356). The response generation agent (356) constructs a response in a natural language form that is easy for the user to understand, based on the analyzed SQL structure information. For example, it can generate an explanatory or summary response that corresponds to the user query, such as summarizing the table relationships referenced by the SQL, explaining the structure and data flow of the CTE, or explaining the meaning of each JOIN condition.
[0092] Thus, the SQL analysis procedure according to the present invention is composed of a step-by-step flow of (1) classification of request intent -> (2) SQL extraction -> (3) SQL structure analysis -> (4) response generation, and each agent and module of the SQL analysis branch shown in the drawing operates sequentially to interpret the structural meaning of the SQL and provide the final analysis result to the user.
[0093] In the present invention, both code analysis and SQL analysis are procedures for interpreting and extracting specific information based on user requests; however, differences arise in the internal configuration and processing steps because the structural characteristics and analysis purposes of the two data types are different. Code analysis has a multi-stage structure consisting of multiple agents and a search state management module (346), whereas SQL analysis has a relatively linear and simple structure leading from SQL extraction -> SQL analysis -> response generation. These differences stem from the differences in the inherent data characteristics and analysis difficulty of source code and SQL.
[0094] First, since source code is complex in terms of length, structure, and context and requires search-based analysis, multiple stages such as a search agent, a relevance check agent (344), and a search state management module (346) are essential in code analysis. Source code is hierarchically organized by file, function, and class units, and the program's behavior is determined by the interaction of various elements such as multiple function calls, conditional statements, loops, and global states. Due to these characteristics, the system must first locate the necessary parts in the code repository (330) and repeatedly evaluate whether the found code is actually related to the user request. During this process, the search state management module (346) intervenes to control the search and perform additional searches if necessary. In other words, since code analysis is a process of deriving meaning through search without knowing where the necessary code is located, a multi-stage agent flow is inevitable.
[0095] On the other hand, because SQL has a standardized structure and its meaning is clearly embedded within the statement, a search phase is not required in SQL analysis. SQL statements possess a clear syntactic structure, such as SELECT, FROM, JOIN, and WHERE, and the subjects of analysis—including tables, columns, and join conditions—are all explicitly specified within the SQL. Therefore, by extracting the SQL statement and performing SQL parsing, the analysis system can directly identify all necessary relational information (e.g., table dependencies, JOIN relationships, CTE flow, etc.). Consequently, since SQL analysis only requires structural decomposition, iterative and exploratory steps such as searching, relevance evaluation, and state management are unnecessary. In other words, SQL analysis is a process where meaning can be derived solely through parsing, as the statement itself contains the structure.
[0096] In conclusion, since code analysis is a process of exploring unstructured and complex data to extract meaning, multi-stage agent collaboration is essential; in contrast, SQL analysis consists of concise, module-centric procedures as it involves the structural decomposition of standardized statements. Due to these differences, as shown in the diagram, the two analysis branches have different system configurations and processing stages.
[0097] [SQL Generation]
[0098] FIG. 8 is an exemplary diagram showing the operation of an agent and a module within an SQL generation unit according to an embodiment of the present invention.
[0099] Referring to FIG. 8, the SQL generation function according to the present invention is performed in such a way that when a user inputs a natural language request describing data query conditions, processing methods, or desired result forms, a plurality of agents and an analysis module operate sequentially within the server (300) to automatically generate and verify SQL statements. SQL generation requires a more sophisticated multi-stage verification structure than SQL analysis and is carried out in the following flow.
[0100] First, when user input is transmitted to the server (300), an intent analysis agent (310) determines the purpose of the request. If the intent analysis agent (310) identifies that the request is not a simple SQL interpretation but an SQL generation task, it activates the SQL generation branch and passes it to a subsequent step. The analyzed intent is transmitted directly to the SQL generation agent (362) and is used as basic data to extract requirements (filter conditions, join targets, output columns, grouping conditions, etc.) necessary for SQL generation from the input statement.
[0101] Next, an SQL generation agent (362) operates to generate an initial SQL draft based on user requirements and a database schema. In this process, the agent interprets the user's natural language request and constructs structural elements of the SQL statement, such as SELECT statements, FROM target tables, JOIN relationships, WHERE conditions, GROUP BY, ORDER BY, etc. The generated SQL draft is passed to a subsequent verification step.
[0102] In the next step, the generated SQL statement is passed to the SQL inspection module (364). The SQL inspection module (364) verifies whether the SQL draft is grammatically correct and whether it accurately references table names and column names defined in the database schema. For example, if there is a schema mismatch, such as referencing a non-existent column or connecting columns of incorrect types in a JOIN condition, it detects and reports the error. The SQL inspection module (364) serves as the first line of defense to ensure the basic structural validity of the SQL statement.
[0103] Once the SQL inspection phase is complete, the SQL statement is passed to the SQL analysis module (354) for a more structured and semantic review. This module parses the SQL draft to analyze which tables the SQL references, how join relationships are formed, and how the data flow unfolds. It also checks whether the logical components within the SQL, such as whether CTEs are used, the structure of subqueries, and the validity of computed columns, match the user requirements. The SQL analysis module (354) verifies that the SQL generation result is not merely grammatically valid, but actually satisfies the data processing method intended by the user.
[0104] In the next step, the SQL evaluation agent (368) evaluates the suitability of the SQL generation result by combining the information provided by the SQL inspection module (364) and the SQL analysis module (354). The evaluation agent calculates a suitability score between 0 and 1 to determine how faithfully the generated SQL reflects user requirements, and if it falls below a threshold, it instructs the SQL generation agent (362) to rewrite the SQL. Thus, the SQL generation process is automatically repeated as needed, and correction work can be performed multiple times until a SQL statement that satisfies the user's intent is finally produced.
[0105] SQL statements that have passed all verification and evaluation processes are transmitted to a response generation agent (370) in the final stage. The response generation agent (370) compiles summary information and explanations obtained during the SQL inspection, analysis, and evaluation process, along with the completed SQL statements, into a natural language format and provides them to the user. Through this, the user can verify not only the SQL statements but also the basis and structural characteristics of the SQL statements, thereby increasing the reliability of the final result.
[0106] [Resource Allocation]
[0107] The multi-agent-based architecture according to the above embodiment enables the generative AI system to be operated more efficiently and reliably by clearly distinguishing the roles of the GPU and the CPU.
[0108] The entire system is divided into GPU-based components that call the LLM to perform high-level inference, decision-making, and generation, and CPU-based components that execute deterministic logic such as rule-based processing, parsing, and state management. The GPU handles high-dimensional tasks such as intent analysis, response generation, code search and relevance evaluation, and SQL extraction, generation, and evaluation, while the CPU takes on tasks suitable for fast and accurate processing, such as code information extraction, search state management, SQL analysis, and SQL inspection.
[0109] This separation structure offers several practical advantages. It allows for the optimization of costs and resources. Since GPU costs are very high for LLM calls, handling simple preprocessing or rule-based verification with CPU modules allows the GPU to focus solely on high-difficulty inference and generation tasks, significantly reducing overall operating costs. It is also advantageous for preventing illusions and enhancing reliability. Because the SQL or code output generated by the GPU is syntactically and logically verified through CPU inspection and analysis modules, the non-deterministic errors inherent to LLM can be mitigated at the system level. Furthermore, overall processing speed is improved. Since LLM calls are relatively slow while CPU operations are very fast, having the CPU handle preprocessing, state management, and rule-based operations reduces pipeline bottlenecks and shortens user response times. Finally, controllability and debugging efficiency are enhanced. While it is difficult to identify the cause of errors if all logic resides within the LLM, placing clear CPU logic—such as search state management or rule-based analysis modules—in stages makes it much easier to track the system's execution flow and diagnose problems.
[0110] In conclusion, this architecture can be summarized as a structure of technical excellence that optimally combines the characteristics of GPUs and CPUs to simultaneously achieve cost reduction, improved accuracy, enhanced speed, and operational efficiency.
[0111] In summary, the present invention can reduce token costs and improve accuracy in LLM-based analysis and generation processes by providing structured source code and SQL. Furthermore, analysis reliability and processing efficiency are enhanced by efficiently searching for only necessary information through a multi-agent stepwise verification and search management structure. Moreover, by applying iterative verification procedures during the SQL generation process, syntactic and schematal errors can be prevented in advance, enabling the stable generation of high-quality SQL.
[0112] FIG. 9 is an exemplary diagram showing the implementation of a system (300) in the form of a computing device according to one embodiment of the present invention.
[0113] Referring to FIG. 9, in some embodiments of the present invention, the computer device (300) may be implemented in the form of a computing device.
[0114] One or more of the modules constituting the computer device (300) are implemented on a general-purpose computing processor and thus may include a processor (308), an input / output I / O (302), a memory (304), an interface (306), and a bus (314). The processor (308), the input / output device (302), the memory (304), and / or the interface (306) may be connected to each other via the bus (314). The bus (314) corresponds to a path through which data travels.
[0115] Specifically, the processor (308) may include at least one of a CPU (Central Processing Unit), MPU (Micro Processor Unit), MCU (Micro Controller Unit), GPU (Graphic Processing Unit), microprocessor, digital signal processor, microcontroller, application processor (AP), and logic elements capable of performing similar functions.
[0116] The input / output device (302) may include at least one of a keypad, a keyboard, a touchscreen, and a display device. The memory (304) may store data and / or programs, etc.
[0117] The interface (306) can perform the function of transmitting data to a communication network or receiving data from a communication network. The interface (306) may be wired or wireless. For example, the interface (306) may include an antenna or a wired / wireless transceiver, etc. The memory (304) is a volatile operational memory for protecting personal information while enhancing the operation of the processor (308), and may further include high-speed DRAM and / or SRAM, etc.
[0118] Additionally, memory (304) stores programming and data configurations that provide the functions of some or all of the modules described herein.
[0119] A program or application is loaded as a set of instructions including each operation using the above-described language model stored in memory (304), and the processor is enabled to perform each operation.
[0120] The various embodiments described herein may be implemented, for example, in a recording medium readable by a computer or similar device using software, hardware, or a combination thereof.
[0121] According to hardware implementation, the embodiments described herein may be implemented using at least one of ASICs (application specific integrated circuits), DSPs (digital signal processors), DSPDs (digital signal processing devices), PLDs (programmable logic devices), FPGAs (field programmable gate arrays), processors, controllers, microcontrollers, microprocessors, and other electrical units for performing functions. In some cases, the embodiments described herein may be implemented as the control module itself.
[0122] According to software implementation, embodiments such as the procedures and functions described herein may be implemented in separate software modules. Each of the software modules may perform one or more functions and operations described herein. Software code may be implemented as a software application written in a suitable programming language. The software code may be stored in a memory module and executed by a control module.
[0123] Although various embodiments of the present invention have been described in detail above, those skilled in the art will understand that various modifications can be made to the above-described embodiments without departing from the scope of the present invention. Therefore, the scope of the present invention should not be limited to the described embodiments, but should be defined by the claims set forth below as well as equivalents thereof.
Claims
Claim 1 An analysis method executed on a computing device that performs multi-agent-based source code and SQL analysis performed on a computer device, comprising: receiving an input and a request including code or SQL from a user; a step in which an intent analysis agent classifies a task type for processing a request into one of code analysis, SQL analysis, and SQL generation based on the input and request; and a step of performing a preliminary information processing and analysis procedure by branching to a processing path corresponding to the classified task type. The analysis method comprises the step of generating a response corresponding to a user request based on the result of the analysis procedure above; wherein the step of branching to perform prior information processing and analysis procedures is to selectively apply either an iterative path or a single-pass path in which the repetition and termination of processing are controlled based on evaluation or inspection results according to the task type, wherein if the task type is code analysis, a source code tree and meta-information representing the inclusion relationship of functions or classes from the received code are generated, and the source code tree and meta-information are input first prior to the code block itself, and a suitability score between the code block and the request is calculated and accumulated, and the repetition of code block search is controlled based on the accumulated suitability score, and the search is terminated when the accumulated suitability score meets a threshold, wherein if the task type is SQL generation, the SQL is finalized by repeating the rewriting and re-inspection of the SQL based on the inspection result of the generated SQL, and if the task type is SQL analysis, structured SQL information is generated through single-pass syntax analysis of the SQL statement extracted from the input. Claim 2 delete Claim 3 The analysis method according to claim 1, wherein the prior information processing step comprises extracting at least one of a filename, dependency, global variable, comment information, or function / class inclusion relationship from a code file and configuring it into summarized code information. Claim 4 The analysis method according to claim 1, wherein the prior information processing step comprises extracting at least one of a table, column, common table expression, join condition, or data flow relationship from an SQL statement and configuring it into structured SQL information. Claim 5 delete Claim 6 An analysis method according to claim 1, characterized in that the code analysis includes at least one of summarizing a code block, deriving code interpretation information, and calculating a suitability score with a query. Claim 7 An analysis method according to claim 1, wherein the step of performing the analysis procedure is an SQL generation type, characterized by generating SQL based on user requirements and schema information, and determining the SQL by performing at least one of a syntax check or a schema conformity check on the generated SQL. Claim 8 An analysis method according to claim 7, characterized in that the SQL confirmation includes a procedure of rewriting the SQL based on the inspection result and repeating the inspection step. Claim 9 The system includes a processor and a memory communicating with the processor, wherein the memory stores instructions for the processor to perform operations, and the operations include: receiving an input and request containing code or SQL from a user; an intent analysis agent classifying a task type for processing a request into one of code analysis, SQL analysis, and SQL generation based on the input and request; branching to a processing path corresponding to the classified task type to perform a preliminary information processing and analysis procedure; and generating a response corresponding to the user request based on the result of the analysis procedure. The operation of branching to perform preliminary information processing and analysis procedure selectively applies either an iterative path or a single-pass path, wherein the repetition and termination of processing are controlled based on evaluation or inspection results depending on the task type. When the task type is code analysis, the system generates a source code tree and meta-information indicating the inclusion relationship of functions or classes from the received code, inputs the source code tree and meta-information prior to the code block itself, calculates and accumulates a suitability score between the code block and the request, and controls the repetition of code block search based on the accumulated suitability score, wherein the accumulated suitability score is a threshold A computing device characterized by: terminating the above search when satisfied; if the above operation type is SQL generation, rewriting and re-examining the above SQL based on the inspection result of the generated SQL to finalize the SQL; and if the above operation type is SQL analysis, generating structured SQL information through single-pass parsing of the SQL statement extracted from the input. Claim 10 A computing device according to claim 9, wherein the above-mentioned prior information processing operation extracts at least one of a filename, dependency, global variable, comment information, or function / class inclusion relationship from a code file and compiles it into summarized code information. Claim 11 A computing device according to claim 9, wherein the prior information processing operation comprises extracting at least one of a table, column, common table expression, join condition, or data flow relationship from an SQL statement and configuring it into structured SQL information.
Citation Information
Patent Citations
SQL (Structured Query Language) analysis method and system based on large model, terminal and medium
CN118152427A
Retrieval generation method and system based on multi-agent collaboration, terminal and medium
CN120723880A
Multi-agent workflows for resolving coding complications via generative ai integrations
US20250378007A1
SQL (Structured Query Language) statement processing method and device, electronic equipment and storage medium
CN115269632A
Apparatus, system, and method for providing question and answer service including source code explanation, and method for providing chatbot service using the same
KR1020230045150A