Artificial intelligence agent-based api request classification method and related device

CN121479385BActive Publication Date: 2026-09-22SHENZHEN YISHIHUOLALA TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511571036.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-10-30
Publication Date
2026-09-22
Estimated Expiration
2045-10-30

AI Technical Summary

Technical Problem

[0004]基于规则的分类方法主要是通过预定义关键词或正则表达式来匹配URL(UniformResource Locator‌,统一资源定位符)和请求头字段,从而实现分类,这种方法难以应对动态变化的API请求(如新业务场景)

Benefits of technology

[0018]本申请提供的上述实施例,通过融合多维特征提取、机器学习初步分类与人工智能Agent动态评估纠正的协同机制,从根本上提升了API请求分类的综合性能。该方法首先通过精细化解析与多维度特征提取,克服了传统基于规则方法特征提取局限的问题,为高精度分类奠定了数据基础;进而,引入人工智能Agent基于语义规则和业务场景进行实时智能纠错,有效解决了现有技术标签纠正效率低下、过度依赖人工的痛点,实现了分类过程的高度自动化;最终,该模块化设计使得系统不依赖于特定场景的固定规则,展现出卓越的泛化能力和动态适应性,能够通用地应用在例如安全监控、流量分析等多种场景,显著提升了API分类的准确性、鲁棒性和实用价值。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121479385B_ABST
    Figure CN121479385B_ABST
Patent Text Reader

Abstract

The application provides an API request classification method based on an artificial intelligence AGENT and related equipment, and the method comprises the following steps: analyzing a received API request to extract a URL, a request header and a request body in the API request and to pre-process the API request, so as to obtain structured request data; extracting features of multiple dimensions from the structured request data, and generating a multi-dimensional feature vector based on the extracted features; inputting the multi-dimensional feature vector into a trained machine learning classification model to obtain an initial classification label and a corresponding confidence; inputting the initial classification label, the confidence and the structured request data into an artificial intelligence Agent; the artificial intelligence Agent evaluates the initial classification label based on preset semantic rules and business scenario information, and corrects the initial classification label when the evaluation fails, so as to obtain a final classification label, and the final classification label is used to determine the request type of the API request. The application can improve the accuracy, robustness and practical value of API classification.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of API classification technology, and in particular relates to an API request classification method and related equipment based on artificial intelligence agents. Background Technology

[0002] API (Application Programming Interface) request classification is a core technology in modern internet services, widely used in areas such as security monitoring (e.g., detecting malicious requests), traffic analysis (e.g., differentiating business types), and service optimization (e.g., API version control).

[0003] Currently, common API classification methods mainly include rule-based classification methods, machine learning-based classification methods, and deep learning-based classification methods.

[0004] Rule-based classification methods primarily use predefined keywords or regular expressions to match URLs (Uniform Resource Locators) and request header fields to achieve classification. However, this method is difficult to handle dynamically changing API requests (such as new business scenarios).

[0005] Machine learning-based classification methods mainly utilize TF-IDF, bag-of-words models, etc. to extract features, and then combine them with classifiers such as SVM (Support Vector Machine) and random forest to achieve classification prediction. This method ignores complex information such as URL structure and request header context, resulting in the loss of key feature information and thus poor classification performance.

[0006] Deep learning-based classification methods primarily use neural networks, such as LSTM (Long Short-Term Memory) and Transformer, to process serialized request data. These methods typically rely on manually designed features or large amounts of labeled data, and in some scenarios, they incorporate simple post-processing to correct labels. However, existing label correction methods rely on manual review or simple threshold adjustments, which are inefficient and cannot be optimized in real time. Moreover, these models are usually trained for specific tasks (such as SMS verification codes) and are difficult to transfer to other scenarios (such as login scenarios). Furthermore, if positive samples (such as specific business requests) are scarce in the training samples, the model tends to favor the majority class, leading to a decrease in minority class recall. Summary of the Invention

[0007] This application provides an API request classification method and related equipment based on artificial intelligence agents, which can improve the accuracy, robustness and practical value of API classification.

[0008] Firstly, this application provides an API request classification method based on an artificial intelligence agent. The method includes: parsing a received API request to extract the URL, request header, and request body from the API request and preprocessing them to obtain structured request data; extracting multi-dimensional features from the structured request data and generating a multi-dimensional feature vector based on the extracted features; inputting the multi-dimensional feature vector into a trained machine learning classification model to obtain an initial classification label and its corresponding confidence score; inputting the initial classification label, confidence score, and structured request data into the artificial intelligence agent; evaluating the initial classification label based on preset semantic rules and business scenario information, and correcting the initial classification label if the evaluation fails, to obtain a final classification label, which is used to determine the request type of the API request.

[0009] In some embodiments, parsing a received API request includes: parsing the URL of the API request using a structured parsing tool to obtain a first parsing result, the first parsing result including query parameters, domain name, and path information; parsing the request header of the API request to obtain a second parsing result, the second parsing result including header field data in key-value pair format; and when the request body of the API request is in JSON format, parsing the JSON format request body to obtain a third parsing result, the third parsing result including the internal field structure.

[0010] In some embodiments, the structured request data includes a first parsing result, a second parsing result, and a third parsing result; multiple dimensions of features are extracted from the structured request data, and a multidimensional feature vector is generated based on the extracted features, including: extracting the number of query parameters, path depth, and keyword features based on regular expression matching from the first parsing result; extracting the client type represented by User-Agent and the Content-Type field value from the second parsing result; extracting keyword features of the JSON field from the third parsing result; and combining and vectorizing all the extracted features to generate a multidimensional feature vector.

[0011] In some embodiments, the AI ​​Agent evaluates the initial classification label based on preset semantic rules and business scenario information, including: the AI ​​Agent determining whether the confidence level is less than a preset confidence threshold; performing semantic analysis on the structured request data to obtain the semantic analysis result; determining whether the semantic analysis result matches the initial classification label; and evaluating the application as failing if the confidence level is less than the confidence threshold or if the semantic analysis result does not match the initial classification label.

[0012] In some embodiments, the training process of the machine learning classification model includes: using the SMOTE oversampling technique to handle the sample imbalance problem in the training dataset; and standardizing the sample feature vectors before inputting them into the machine learning classification model for prediction.

[0013] In some embodiments, the operation of correcting the initial classification label when the evaluation fails to obtain the final classification label includes: generating prompt words by combining the initial classification label, confidence level, and structured request data based on a preset prompt word template; inputting the prompt words into the large language model mounted on the AI ​​Agent; obtaining the output of the large language model, and if the output includes the corrected label, using the corrected label as the final classification label; if the output includes correction suggestions, generating a new multidimensional feature vector based on the correction suggestions and the multidimensional feature vector; and returning to the step of inputting the multidimensional feature vector into the trained machine learning classification model based on the new multidimensional feature vector.

[0014] In some embodiments, after obtaining the final classification label, the method further includes: associating the final classification label with the API request and outputting it as a structured data file; and sending the structured data file to downstream applications for use.

[0015] Secondly, this application provides an API request classification device based on an artificial intelligence agent, the device comprising: The preprocessing module is used to parse the received API request to extract the URL, request headers, and request body from the API request to obtain structured request data; The feature extraction module is used to extract multi-dimensional features from structured request data and generate multi-dimensional feature vectors based on the extracted features. The initial classification module is used to input multi-dimensional feature vectors into the trained machine learning classification model to obtain initial classification labels and corresponding confidence scores; The label correction module is used to input the initial classification label, confidence level, and structured request data into the AI ​​Agent. The AI ​​Agent evaluates the initial classification label based on preset semantic rules and business scenario information, and corrects the initial classification label when the evaluation fails, thus obtaining the final classification label. The final classification label is used to determine the request type of the API request.

[0016] Thirdly, this application provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the API request classification method based on an artificial intelligence agent provided in any embodiment of the first aspect.

[0017] Fourthly, this application provides a computer device including one or more processors, a memory, and one or more computer programs. The processors and the memory are connected via a bus. The one or more computer programs are stored in the memory and configured to be executed by one or more processors. When the processors execute the computer programs, they implement the API request classification method based on artificial intelligence agents provided in any embodiment of the first aspect.

[0018] The embodiments provided in this application fundamentally improve the overall performance of API request classification by integrating a collaborative mechanism of multi-dimensional feature extraction, preliminary classification by machine learning, and dynamic evaluation and correction by an AI agent. First, this method overcomes the limitations of traditional rule-based feature extraction methods through refined analysis and multi-dimensional feature extraction, laying a data foundation for high-precision classification. Then, it introduces an AI agent for real-time intelligent error correction based on semantic rules and business scenarios, effectively solving the pain points of low efficiency and excessive reliance on manual intervention in existing label correction technologies, achieving a high degree of automation in the classification process. Finally, this modular design allows the system to operate independently of fixed rules for specific scenarios, exhibiting excellent generalization ability and dynamic adaptability. It can be universally applied to various scenarios such as security monitoring and traffic analysis, significantly improving the accuracy, robustness, and practical value of API classification. Attached Figure Description

[0019] Figure 1 This is a flowchart of an API request classification method based on an artificial intelligence agent provided in one embodiment of this application.

[0020] Figure 2 This is a functional block diagram of an API request classification device based on artificial intelligence agent provided in an embodiment of this application.

[0021] Figure 3 This is a structural block diagram of a computer device provided in one embodiment of this application. Detailed Implementation

[0022] To make the objectives, technical solutions, and beneficial effects of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0023] To illustrate the technical solution described in this application, specific embodiments are provided below.

[0024] Firstly, this application provides an API request classification method based on an artificial intelligence agent. This method fundamentally improves the overall performance of API request classification by integrating a collaborative mechanism of multi-dimensional feature extraction, preliminary classification by machine learning, and dynamic evaluation and correction by an artificial intelligence agent. Firstly, this method overcomes the limitations of traditional rule-based feature extraction methods through refined analysis and multi-dimensional feature extraction, laying a data foundation for high-precision classification. Secondly, it introduces an artificial intelligence agent for real-time intelligent error correction based on semantic rules and business scenarios, effectively solving the pain points of low efficiency and excessive reliance on manual labor in existing label correction technologies, achieving a high degree of automation in the classification process. Finally, this modular design allows the system to operate independently of fixed rules for specific scenarios, exhibiting excellent generalization ability and dynamic adaptability. It can be universally applied to various scenarios such as security monitoring and traffic analysis, significantly improving the accuracy, robustness, and practical value of API classification.

[0025] The steps included in this method can be found in [reference needed]. Figure 1 The following describes the steps involved in this method.

[0026] S101. Parse the received API request to extract the URL, request header and request body from the API request and preprocess them to obtain structured request data.

[0027] This method can be applied to servers, such as server clusters and standalone servers.

[0028] An API request is a network request sent by a client to a server according to the Application Programming Interface (API) specification, aiming to obtain a specific service or resource. The core components of an API request include the request line (including the URL), request headers, and request body. For example, an API request for a user login might be an HTTP POST request sent to https: / / api.example.com / v1 / login, containing a User-Agent header, a Content-Type header, and a JSON (JavaScript Object Notation) formatted request body, i.e., {"username":"user123","password":"pass456"}.

[0029] After receiving an API request, the server parses it. This involves breaking down the raw byte stream or string of the API request into a structured object that the program can understand and manipulate, according to the HTTP (Hypertext Transfer Protocol) protocol and specific formats (such as JSON). Preprocessing can also be performed during API request parsing. Preprocessing refers to cleaning, transforming, and standardizing the data before or after parsing to ensure data quality and consistency.

[0030] In some embodiments, parsing a received API request includes: parsing the URL of the API request using a structured parsing tool to obtain a first parsing result, the first parsing result including query parameters, domain name, and path information; parsing the request header of the API request to obtain a second parsing result, the second parsing result including header field data in key-value pair format; and when the request body of the API request is in JSON format, parsing the JSON format request body to obtain a third parsing result, the third parsing result including the internal field structure.

[0031] For example, suppose the URL looks like this: https: / / api.example.com / v1 / users / 123?action=query&format=json

[0032] The operation of parsing a URL can be: The URL https: / / api.example.com / v1 / users / 123?action=query&format=json is parsed into components such as protocol (https), host (api.example.com), path ( / v1 / users / 123), and query parameters ({'action': 'query', 'format': 'json'}).

[0033] Assume the request headers are as follows: GET / api / v1 / data HTTP / 1.1 Host: api.example.com User-Agent: Mozilla / 5.0 (Windows NT 10.0; Win64; x64) AppleWebKit / 537.36 Content-Type: application / json; charset=utf-8 Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9... Accept: * / * X-Custom-Header: someValue".

[0034] During parsing, the string in the request header is split into lines, with a colon (:) as the separator. The first line is taken as the request line, and the remaining lines are split into keys and values, and then converted into a dictionary, map, or similar structured object.

[0035] If the request body is {"name": "John", "age": 30}, then when parsing the request body, the string {"name": "John", "age": 30} can be parsed into a Python dictionary or a Java object.

[0036] Preprocessing operations can include handling missing request headers (such as adding a default value of application / json for missing Content-Type), standardizing date formats, and filtering illegal characters (such as SQL injection code).

[0037] Structured request data refers to request information organized in a unified and standardized key-value pair or tree structure (such as JSON Object) after the parsing and preprocessing operations described above. It is not a raw string, but rather decomposed into discrete, individually accessible data elements.

[0038] S102. Extract features of multiple dimensions from the structured request data, and generate a multi-dimensional feature vector based on the extracted features.

[0039] The structured request data includes the first, second, and third parsing results mentioned above. The operation of extracting multi-dimensional features from the structured request data and generating a multi-dimensional feature vector based on these features can include: extracting the number of query parameters, path depth, and keyword features based on regular expression matching from the first parsing result; extracting the client type represented by the User-Agent and the Content-Type field value from the second parsing result; extracting keyword features from the JSON field from the third parsing result; and combining and vectorizing all extracted features to generate a multi-dimensional feature vector.

[0040] Among them, features extracted from structured request data in multiple dimensions are used to characterize the characteristics of API requests. These features can be data of numerical, categorical and / or Boolean attributes.

[0041] The features of multiple dimensions can specifically include URL dimension features, request header dimension features, and request body dimension features.

[0042] For example, URL dimension features can include path depth (e.g., the depth of / v1 / a / b / c is 4), the number of query parameters, and the presence of specific keywords (e.g., whether the path contains "pay", generating a boolean feature has_pay: True). Request header dimension features can include the device type represented by User-Agent (e.g., "mobile", "browser", "bot"), the value of Content-Type (e.g., application / json), and the presence of security headers (e.g., is_authorization_present: True). Request body dimension features can include the number of JSON fields, the value of specific fields (e.g., amount_value: 100.0), and the maximum depth of nested structures.

[0043] Features extracted from multiple dimensions are discrete. These features can be transformed and combined into a unified, fixed-length mathematical vector through techniques such as standardization and encoding (e.g., One-Hot encoding). This mathematical vector is the input form that machine learning classification models can directly process.

[0044] The multidimensional feature vector is this mathematical vector, for example, it can be [4, 2, 1, 0, 1, 0, 1, 100.0,...].

[0045] Where 4 represents the path depth, 2 represents the number of parameters, 1 represents has_pay as True, 0 and 1 represent the device type after One-Hot encoding (such as "mobile"), and 100.0 represents the value of the amount field.

[0046] S103. Input the multidimensional feature vector into the trained machine learning classification model to obtain the initial classification label and the corresponding confidence score.

[0047] A machine learning classification model is an algorithmic model that has been trained on a labeled dataset of historical API requests. It learns the complex mapping between feature vectors and classification labels, and predicts the category of new, unseen feature vectors. For example, a machine learning classification model could be trained using gradient boosting decision tree algorithms (such as XGBoost or LightGBM). The input to this model can be a 300-dimensional feature vector, and the output can be a classification label and its confidence score. The classification label indicates the type of API request the machine learning classification model classifies (i.e., the classification result), such as login request, payment request, query request, etc. The confidence score is the degree of certainty with which the machine learning classification model outputs the classification label; it is typically a probability value between 0 and 1, with higher values ​​indicating greater certainty. For example, if the output of a machine learning classification model is: label: "payment", confidence: 0.92, this means the model is 92% confident that the API request is a payment request.

[0048] After inputting a multidimensional feature vector into a machine learning classification model, the model outputs a classification label and its corresponding confidence score. This classification label is the initial classification label.

[0049] In some embodiments, the training process of the machine learning classification model includes: using the SMOTE oversampling technique to handle the sample imbalance problem in the training dataset; and standardizing the sample feature vectors before inputting them into the machine learning classification model for prediction.

[0050] A training dataset is a collection of known data used to train a machine learning classification model. Each data point contains a "multidimensional feature vector" and its corresponding "true label." The model learns and infers patterns from these data to gain the ability to predict unknown data.

[0051] For example, the training dataset could be a dataset containing 100,000 historical API request records. Each record has been accurately labeled with a category by human intervention, such as: The multidimensional feature vector _1 corresponds to the label "login" (representing a login request). The multidimensional feature vector_2 has the label "payment" (representing a payment request). The multidimensional feature vector_3 has the label "query" (representing a query request).

[0052] Imbalanced datasets refer to a situation where the number of samples from different classes differs significantly in a training dataset. This causes machine learning classification models to become overly biased towards the majority class during training, neglecting the minority class, resulting in extremely low prediction accuracy (recall) for the minority class. For example, in an API request dataset, there might be 1,000 payment requests (minority class) but a staggering 50,000 query requests (majority class). If this dataset were used directly for model training, the model would tend to predict all requests as query requests, thus achieving high overall accuracy, but this would prevent the model from recognizing payment requests at all.

[0053] To avoid sample imbalance, this embodiment introduces the SMOTE oversampling technique. SMOTE balances the dataset by artificially synthesizing new minority class samples. It randomly selects the K nearest neighbors for each minority class sample and then randomly selects a point on the connecting line as the new sample. For example, suppose the original imbalanced dataset has 100 payment request samples (minority class) and 10,000 query request samples (majority class). After applying SMOTE, the algorithm will synthesize 9,900 new, similar payment request samples from the existing 100 payment request samples. The final dataset will have approximately 10,000 payment request samples and approximately 10,000 query request samples, allowing the model to learn the features of both classes equally.

[0054] In addition to introducing the SMOTE oversampling technique, this embodiment standardizes the sample feature vectors before inputting them into the machine learning classification model for prediction. Here, the sample feature vector refers to the multi-dimensional feature vector corresponding to a single sample in the training dataset, which is the basic unit for the model to learn and predict.

[0055] Standardization is used to unify the scale of numerical features in a multidimensional feature vector. Specifically, by subtracting the mean and dividing by the standard deviation, the original data can be scaled to a standard normal distribution with a mean of 0 and a standard deviation of 1. This addresses the problem that different features, due to their different dimensions and value ranges, can have varying degrees of impact on the model.

[0056] For example, before standardization, feature 1 (path depth) ranges from [1, 20], and feature 2 (transaction amount) ranges from [0.01, 10000.00]. Because of its large value, even small changes in the amount feature have a dominant impact on the model, masking the importance of path depth. After standardization, both features 1 and 2 are transformed to similar scales, such as [-2.5, 2.5]. This allows the model to equally weigh the importance of all features, leading to stable convergence and improved performance.

[0057] S104. Input the initial classification label, confidence level, and structured request data into the AI ​​Agent; The AI ​​Agent evaluates the initial classification label based on preset semantic rules and business scenario information, and corrects the initial classification label if the evaluation fails, to obtain the final classification label, which is used to determine the request type of the API request.

[0058] An AI agent can be a software intelligent entity that encapsulates decision-making logic. Its core is a Large Language Model (LLM). It is assigned specific roles and rules, and can simulate the reasoning process of human experts, analyzing, judging, and making decisions on input information.

[0059] For example, an AI agent could be a large language model (such as GPT-4) set as an API classification expert by a prompt. It can receive classification labels, confidence scores, and structured request data generated in previous steps from the machine learning classification model, and evaluate the reasonableness of the machine learning classification model's predictions based on preset semantic rules and business scenario information.

[0060] Semantic rules can be pre-configured knowledge bases and judgment criteria within the Agent. Semantic rules define the logical relationship between data in a request (such as URL paths and field names) and its business meaning (e.g., "a path containing 'login' indicates a login service"). Business scenario information provides the domain context and requirements for the classification tasks performed by the machine learning classification model. For example, in a financial risk control scenario, all transfer requests must be marked as high-risk.

[0061] The operation of the AI ​​Agent evaluating the initial classification label based on preset semantic rules and business scenario information may include: the AI ​​Agent determining whether the confidence level is less than a preset confidence level threshold; performing semantic analysis on the structured request data to obtain the semantic analysis result; determining whether the semantic analysis result matches the initial classification label; and evaluating as failing if the confidence level is less than the confidence level threshold or if the semantic analysis result does not match the initial classification label.

[0062] A confidence threshold is a pre-defined critical value used to measure the certainty of a machine learning classification model's judgment. This value can be a floating-point number between 0 and 1, serving as a benchmark to distinguish between "high confidence" and "low confidence" predictions. Predictions with a confidence level below this threshold are considered unreliable. For example, assuming a confidence threshold is set to 0.7, if the initial classification label has a confidence level of 0.65, the AI ​​agent will determine that the initial classification label has insufficient confidence because 0.65 is less than 0.7.

[0063] The AI ​​agent also performs semantic analysis on structured request data. Semantic analysis refers to the process by which the AI ​​agent understands the meaning and purpose contained in the parsed results of structured request data (including URLs, request headers, and request bodies). It goes beyond simple keyword matching, inferring the true business intent of API requests by analyzing the context and compositional relationships of components.

[0064] For example, semantic analysis of structured request data can include: (1) Analyze the URL path. Assuming the URL path is / v1 / users / 1234 / payment-methods, based on the content of this path, it can be inferred that this is an operation about "user payment management" rather than a simple "user information query". (2) Analyze the request body. Assuming that the parsed result of the request body includes the JSON field {"transaction_type": "refund", "amount": 50.00}, it can be identified that the JSON field represents a "refund" operation, rather than a "payment" operation.

[0065] (3) Analyze the request header. Assuming that the parsing result of the request header includes Content-Type: application / octet-stream and User-Agent: Apache-HttpClient / 4.5, it can be inferred that the API request may come from a file transfer call between backend services.

[0066] Semantic analysis results refer to the conclusions reached by an AI agent regarding the category of an API request after semantic analysis. This is an independent judgment made by the AI ​​agent based on its understanding of the "true intent of the request." For example, for an API request, suppose the initial category label output by the machine learning classification model is "user_management" (representing a user management request). However, after semantic analysis, the AI ​​agent finds that the request body contains {"action": "charge"}, and therefore the semantic analysis result is "payment" (representing a payment request).

[0067] After determining the semantic analysis results, they are compared with the initial classification labels to determine whether they match. If both correspond to the same request type (e.g., both are payment requests), they are considered a match; if they correspond to different request types (e.g., one corresponds to a payment request and the other to a user management request), they are considered a mismatch.

[0068] If the semantic analysis result does not match the initial classification label, or if the confidence level of the initial classification label is less than the confidence threshold, the evaluation is considered a failure, meaning that the classification result of the machine learning classification model is unacceptable and its output initial classification label needs to be corrected. If the semantic analysis result matches the initial classification label, and the confidence level of the initial classification label is greater than or equal to the confidence threshold, the evaluation is considered a success, and the initial classification label output by the machine learning classification model can be directly used as the final classification label.

[0069] When the AI ​​agent fails the evaluation, it corrects the initial classification label to obtain the final classification label. The operation may include: generating prompt words by combining the initial classification label, confidence level, and structured request data based on a preset prompt word template; inputting the prompt words into the large language model carried by the AI ​​agent; obtaining the output of the large language model, and if the output includes the corrected label, using the corrected label as the final classification label; if the output includes correction suggestions, generating a new multidimensional feature vector based on the correction suggestions and the multidimensional feature vector; and returning the step of inputting the multidimensional feature vector into the trained machine learning classification model based on the new multidimensional feature vector.

[0070] The preset prompt word template is a pre-designed, structured text framework used to guide and constrain the execution logic of the large language model. It includes fixed instruction context, variable placeholders, and output format requirements, ensuring that the large language model can play a specific role and perform a specific task.

[0071] For example, the prompt template could be: { You are an API classification expert. Please evaluate the following classification results: - Initial category: {initial_label} - Model confidence: {confidence} - Structured request data: {structured_data} Please analyze based on your knowledge. Your output must be in strict JSON format: {{"reasoning": "<your reasoning>", "corrected_label": "<new label>", "action": "<'correct'|'correct_and_advise'>"}}.

[0072] If you believe the classification is correct, leave `corrected_label` empty. If you believe the classification is incorrect, please provide `corrected_label`. If you find any ambiguity in the feature, you can mark it in `action`.

[0073] }

[0074] The prompt word template includes placeholders for the initial classification label, confidence score, and structured request data, such as {initial_label}, {confidence}, and {structured_data}. After filling the initial classification label, confidence score, and structured request data into the corresponding placeholders in the prompt word template, a complete input text that can be submitted to the large language model, i.e., the prompt word, can be generated.

[0075] The large language model integrated into an AI agent refers to a large-scale pre-trained language model that serves as its core computing engine. It is responsible for receiving prompts, understanding instructions, and performing reasoning and text generation based on its vast amount of parameterized knowledge. For example, the APIs of large language models such as OpenAI's GPT-4, Anthropic's Claude, or Meta's Llama 2 can be integrated into the agent system, allowing the AI ​​agent to gain intelligent analytical capabilities by calling these models' API interfaces.

[0076] The output refers to the response text generated by the large language model based on the input prompts. The output can be structured data that includes reasoning processes, decision conclusions, or specific suggestions.

[0077] The corrected label refers to the new classification label directly provided by the large language model, used to replace the incorrect initial classification label. If the output includes the corrected label, for example, assuming the output is {"reasoning": "The URL path contains 'payment' and the request body contains the financial field 'amount', it should be a payment request.", "corrected_label":"payment", "action": "correct"}, then the corrected label "payment" can be used as the final classification label.

[0078] Corrective suggestions refer to diagnostic meta-information output by the large language model, rather than directly providing an answer. They indicate possible reasons for incorrect initial classification labels or offer guidance on how to adjust feature representations to make correct classifications. If the output includes corrective suggestions, for example, assuming the output is {"reasoning": "The value 'preauth' in the 'action' field of the request body is rare in the training data, causing model confusion. It is recommended to pay attention to this field.", "corrected_label": "", "action": "correct_and_advise"}, then based on the corrective suggestion "The value 'preauth' in the 'action' field of the request body is rare in the training data, causing model confusion. It is recommended to pay attention to this field." and the multidimensional feature vector, a new multidimensional feature vector is generated. Finally, based on this new multidimensional feature vector, the process returns to inputting the multidimensional feature vector into the trained machine learning classification model, allowing the machine learning classification model to re-predict the request type of the API request. Finally, an AI agent is used to further detect whether the new initial classification label output by the machine learning classification model needs correction.

[0079] In some embodiments, the new multidimensional feature vector can also be a regenerated feature vector after fine-tuning or enhancing the original feature extraction process based on correction suggestions provided by a large language model. It may contain new feature dimensions, different feature encoding methods, or adjusted feature weights, designed to better represent the requested features that cause model confusion.

[0080] For example, the original multidimensional feature vector is: [path_has_login: 1, num_params: 2, ..., body_has_amount: 1] (The model misclassifies it as "login"); The correction suggestions output by the large language model are: "Although the path contains login, the amount in the body is the decisive feature and should be given higher weight." Then, the original feature extraction process can be fine-tuned or enhanced to generate new multidimensional feature vectors, for example: [path_has_login: 1, num_params: 2, ..., body_has_amount: 3] (Here, the value of the boolean feature body_has_amount is adjusted from 1 to 3, simulating an increase in weight. In actual implementation, this might be reflected in the feature engineering stage or the model attention mechanism).

[0081] In some embodiments, after obtaining the final classification label, the method further includes: associating the final classification label with the API request and outputting it as a structured data file; and sending the structured data file to downstream applications for use.

[0082] The final category label is the final category result of the API request. After obtaining the final category label, a mapping relationship can be established at the data level between the final category label and the original API request to realize the association between the two. Establishing a mapping relationship between the two allows either side to find the corresponding other side through a query operation, which is usually achieved by sharing a unique identifier (such as a request ID), database primary and foreign keys, or co-occurrence in the same data record.

[0083] After the association is completed, a structured data file is output. A structured data file is a file that organizes and stores data in a specific format that is easy for computer programs to parse and process automatically, and also easy for humans to read. Specific formats can include JSON, XML, CSV, etc.

[0084] Downstream applications refer to other software systems, services, or modules that require the API classification results. These applications use the structured classification results as input data for their own functions to drive higher-level business logic. Downstream applications can be one or more, such as security monitoring systems, business traffic analysis platforms, API gateways, etc.

[0085] For example, suppose the downstream application is a security monitoring system. After receiving the structured data file, it automatically triggers alerts or blocking mechanisms if it detects a large number of API requests being classified as "attack probes" or "sensitive data access." Or suppose the downstream application is a business traffic analysis platform. After receiving the structured data file, it can aggregate and statistically analyze data according to different business types (such as payment, login, and search), generating real-time traffic dashboards and business reports. Or suppose the downstream application is an API gateway. After receiving the structured data file, it can execute different routing policies, rate limiting rules, or billing policies based on the final classification label of the API requests (such as "internal" or "external").

[0086] Secondly, this application provides an API request classification device based on artificial intelligence agents. In some embodiments, such as... Figure 2 As shown, the device includes: The preprocessing module 101 is used to parse the received API request to extract the URL, request header and request body from the API request to obtain structured request data; The feature extraction module 102 is used to extract features of multiple dimensions from structured request data and generate a multi-dimensional feature vector based on the extracted features. The initial classification module 103 is used to input multi-dimensional feature vectors into a trained machine learning classification model to obtain initial classification labels and corresponding confidence scores. The label correction module 104 is used to input the initial classification label, confidence level and structured request data into the artificial intelligence agent; the artificial intelligence agent evaluates the initial classification label based on preset semantic rules and business scenario information, and corrects the initial classification label when the evaluation fails, so as to obtain the final classification label. The final classification label is used to determine the request type of the API request.

[0087] In some embodiments, the step of parsing the received API request specifically includes: parsing the URL of the API request using a structured parsing tool to obtain a first parsing result, the first parsing result including query parameters, domain name and path information; parsing the request header of the API request to obtain a second parsing result, the second parsing result including header field data in key-value pair form; and when the request body of the API request is in JSON format, parsing the JSON format request body to obtain a third parsing result, the third parsing result including internal field structure.

[0088] In some embodiments, the structured request data includes a first parsing result, a second parsing result, and a third parsing result. The step of extracting multi-dimensional features from the structured request data and generating a multi-dimensional feature vector based on the extracted features specifically includes: extracting the number of query parameters, path depth, and keyword features based on regular expression matching from the first parsing result; extracting the client type represented by User-Agent and the Content-Type field value from the second parsing result; extracting keyword features from the JSON field from the third parsing result; and combining and vectorizing all extracted features to generate a multi-dimensional feature vector.

[0089] In some embodiments, the AI ​​Agent evaluates the initial classification label based on preset semantic rules and business scenario information, specifically including: the AI ​​Agent determining whether the confidence level is less than a preset confidence threshold; performing semantic analysis on the structured request data to obtain the semantic analysis result; determining whether the semantic analysis result matches the initial classification label; and evaluating as failing if the confidence level is less than the confidence threshold or if the semantic analysis result does not match the initial classification label.

[0090] In some embodiments, the training process of the machine learning classification model includes: using the SMOTE oversampling technique to handle the sample imbalance problem in the training dataset; and standardizing the sample feature vectors before inputting them into the machine learning classification model for prediction.

[0091] In some embodiments, the operation of correcting the initial classification label when the evaluation fails to obtain the final classification label includes: generating prompt words by combining the initial classification label, confidence level, and structured request data based on a preset prompt word template; inputting the prompt words into the large language model mounted on the AI ​​Agent; obtaining the output of the large language model, and if the output includes the corrected label, using the corrected label as the final classification label; if the output includes correction suggestions, generating a new multidimensional feature vector based on the correction suggestions and the multidimensional feature vector; and returning to the step of inputting the multidimensional feature vector into the trained machine learning classification model based on the new multidimensional feature vector.

[0092] In some embodiments, the apparatus is further configured to associate the final classification label with the API request and output it as a structured data file; and send the structured data file to downstream applications for use.

[0093] The API request classification device based on artificial intelligence agent provided in this application and the API request classification method based on artificial intelligence agent provided in the first aspect of this application belong to the same inventive concept. The specific implementation process is detailed in the full text of the specification, especially the various embodiments provided in the first aspect, which will not be repeated here.

[0094] Thirdly, this application provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the API request classification method based on an artificial intelligence agent provided in any embodiment of the first aspect.

[0095] Fourthly, this application provides a computer device, Figure 3The diagram shows a specific structural block diagram of a computer device, which includes one or more processors 101, a memory 102, and one or more computer programs. The processors 101 and the memory 102 are connected via a bus. The one or more computer programs are stored in the memory 102 and configured to be executed by the one or more processors 101. When the processors 101 execute the computer programs, they implement the API request classification method based on an artificial intelligence agent provided in any embodiment of the first aspect. The computer device can be a desktop computer or a mobile terminal, including at least one of a mobile phone, tablet computer, personal digital assistant, or wearable device.

[0096] It should be understood that the steps in the various embodiments of this application are not necessarily executed sequentially according to the order indicated by the step numbers. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in each embodiment may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least a portion of the sub-steps or stages of other steps.

[0097] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments described above. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and RAMbus dynamic RAM (RDRAM), etc.

[0098] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0099] The above embodiments merely illustrate several implementation methods of the present invention, and their descriptions are relatively specific and detailed, but they should not be construed as limiting the scope of the invention patent. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of the present invention, and these all fall within the protection scope of the present invention. Therefore, the protection scope of this invention patent should be determined by the appended claims.

Claims

1. A method for classifying API requests based on artificial intelligence agents, characterized in that, The method includes: The received API request is parsed to extract the URL, request headers, and request body from the API request and preprocessed to obtain structured request data; Multiple-dimensional features are extracted from the structured request data, and a multi-dimensional feature vector is generated based on the extracted features; The multidimensional feature vector is input into the trained machine learning classification model to obtain the initial classification label and the corresponding confidence score; The initial classification label, the confidence level, and the structured request data are input into the AI ​​Agent; the AI ​​Agent evaluates the initial classification label based on preset semantic rules and business scenario information, and corrects the initial classification label if the evaluation fails, to obtain the final classification label, which is used to determine the request type of the API request; The operation of the AI ​​Agent to correct the initial classification label when the evaluation fails, and to obtain the final classification label, includes: Based on a preset prompt word template, the initial category label, the confidence level, and the structured request data are combined to generate prompt words; The prompt words are input into the large language model carried by the AI ​​Agent; Obtain the output of the large language model. If the output includes a corrected label, use the corrected label as the final classification label. If the output includes a correction suggestion, generate a new multidimensional feature vector based on the correction suggestion and the multidimensional feature vector. Return to the step of inputting the multidimensional feature vector into the trained machine learning classification model based on the new multidimensional feature vector.

2. The method as described in claim 1, characterized in that, Parse the received API request, including: The URL of the API request is parsed using a structured parsing tool to obtain a first parsing result, which includes query parameters, domain name, and path information. Parse the request header of the API request to obtain a second parsing result, which includes header field data in key-value pair format; When the request body of the API request is in JSON format, the JSON request body is parsed to obtain a third parsing result, which includes the internal field structure.

3. The method as described in claim 2, characterized in that, The structured request data includes the first parsing result, the second parsing result, and the third parsing result; Extracting multi-dimensional features from the structured request data and generating a multi-dimensional feature vector based on the extracted features includes: Extract the number of query parameters, path depth, and keyword features based on regular expression matching from the first parsing result; Extract the client type and Content-Type field values ​​represented by User-Agent from the second parsing result; Extract keyword features from the JSON fields in the third parsing result; All extracted features are combined and vectorized to generate a multidimensional feature vector.

4. The method as described in claim 1, characterized in that, The operation of the AI ​​Agent evaluating the initial classification labels based on preset semantic rules and business scenario information includes: The AI ​​Agent determines whether the confidence level is less than a preset confidence level threshold; Perform semantic analysis on the structured request data to obtain semantic analysis results; determine whether the semantic analysis results match the initial classification labels; If the confidence level is less than the confidence level threshold, or if the semantic analysis result does not match the initial classification label, the evaluation is deemed unsuccessful.

5. The method as described in claim 1, characterized in that, The training process of the machine learning classification model includes: The SMOTE oversampling technique is used to address the imbalance problem in the training dataset. Before inputting the sample feature vector into the machine learning classification model for prediction, the sample feature vector is standardized.

6. The method as described in claim 1, characterized in that, After obtaining the final classification label, the method further includes: The final classification label is associated with the API request and output as a structured data file; The structured data file is then sent to downstream applications for use.

7. An API request classification device based on an artificial intelligence agent, characterized in that, The device includes: The preprocessing module is used to parse the received API request to extract the URL, request header and request body from the API request to obtain structured request data; The feature extraction module is used to extract features of multiple dimensions from the structured request data and generate a multi-dimensional feature vector based on the extracted features. The initial classification module is used to input the multidimensional feature vector into the trained machine learning classification model to obtain the initial classification label and the corresponding confidence score; The label correction module is used to input the initial classification label, the confidence level, and the structured request data into the AI ​​Agent; the AI ​​Agent evaluates the initial classification label based on preset semantic rules and business scenario information, and corrects the initial classification label when the evaluation fails, to obtain the final classification label, which is used to determine the request type of the API request; The operation of the AI ​​Agent to correct the initial classification label when the evaluation fails, and to obtain the final classification label, includes: Based on a preset prompt word template, the initial category label, the confidence level, and the structured request data are combined to generate prompt words; The prompt words are input into the large language model carried by the AI ​​Agent; Obtain the output of the large language model. If the output includes a corrected label, use the corrected label as the final classification label. If the output includes a correction suggestion, generate a new multidimensional feature vector based on the correction suggestion and the multidimensional feature vector. Return to the step of inputting the multidimensional feature vector into the trained machine learning classification model based on the new multidimensional feature vector.

8. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1 to 6.

9. A computer device comprising one or more processors, a memory, and one or more computer programs, wherein the processors and the memory are connected via a bus, and the one or more computer programs are stored in the memory and configured to be executed by the one or more processors, characterized in that, When the processor executes the computer program, it implements the method as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Malicious mining software detection method based on large language model

    CN118585996A

  • Large and small model collaborative target detection and recognition method based on thinking chain

    CN120449105A