API calling interaction method and system based on agent and storage medium
Through the interactive method of API call based on agents, the problem of lack of flexibility and intelligence in traditional API call methods is solved, and the independent decision-making and dynamic collaboration of API calls are realized, which significantly improves the efficiency and stability of API calls and reduces the difficulty and cost of development.
Patent Information
- Application Number
- CN202510360856.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-25
- Publication Date
- 2025-06-27
AI Technical Summary
Traditional API calling methods lack flexibility and intelligence, and developers need to understand API details in depth and write complex calling code manually, which leads to high development difficulty, low efficiency and error-prone, especially when facing diversified APIs and complex interaction scenarios.
Adopting an agent-based API call interaction method, by building an agent with independent decision-making ability and domain knowledge, the transformation of API calls from fixed coding to independent decision-making, from single execution to dynamic collaboration. The method includes steps such as agent construction and registration, task reception and analysis, agent selection and collaboration, API call execution and monitoring, result processing and feedback.
Significantly improve the flexibility and intelligence level of API calls, reduce development thresholds and labor costs, enhance complex task processing capabilities, optimize resource utilization and system performance, improve system robustness and fault tolerance, and support rapid business expansion and maintenance convenience.
Smart Images

Figure CN120216146A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to an agent-based API call interaction method and a storage medium. Background Art
[0002] With the increasing complexity and diversification of software systems, the interaction and collaboration between different systems have become more and more frequent. As an important software interface, API allows data interaction and function calls between different applications, so as to achieve more powerful and rich function integration. However, traditional API call methods are usually relatively fixed and rigid, lacking flexibility and intelligence. Developers often need to have in-depth understanding of the specific details of the API and manually write complex call codes. This not only increases the difficulty and workload of development, but also easily leads to errors and low efficiency. Especially when facing a large number of different types of APIs and complex interaction scenarios, the problem is more prominent. Summary of the Invention
[0003] The present invention proposes an agent-based API call interaction method. Through the deep integration of agent technology, it realizes the leap of API calls from "fixed coding" to "autonomous decision-making" and from "single execution" to "dynamic collaboration", and has significant advantages in improving efficiency, reducing costs, enhancing stability and scalability, etc., and is applicable to fields with high complexity and high real-time requirements such as e-commerce, Internet of Things, and finance. The technical solution of the present invention is realized as follows:
[0004] An agent-based API call interaction method, characterized by including the following steps:
[0005] Step S1: Agent construction and registration. Construct multiple agents with independent decision-making capabilities and domain knowledge. The agents are implemented based on machine learning and natural language processing technologies and are registered to the agent management system. The system maintains an agent capability directory, recording the function descriptions, input and output parameters, and task type information of the agents;
[0006] Step S2: Task reception and parsing. Receive task requests through a unified interface. The requests include natural language, structured queries, or specific message formats. Perform natural language processing and semantic analysis on the task requests to extract the target API, operation type, input parameters, and expected results;
[0007] Step S3: Agent selection and collaboration. Match the task characteristics with the agent capability directory to generate a matching score and screen candidate agents. Decompose complex tasks, plan the dependency relationships between subtasks, and allocate agents to execute collaboratively. Dynamically select agents and allocate resources based on the capability matching degree, real-time status, and resource consumption model;
[0008] Step S4: API call execution and monitoring, generating an optimized API call request, executing it, and monitoring the status in real time; triggering exception handling and fault tolerance mechanisms, including retry, alternative API switching, and degradation strategies; verifying the integrity of the API response results, and collecting performance data to optimize subsequent calls;
[0009] Step S5: Result processing and feedback, parsing the API response data and converting it into the format specified by the user, and feeding back the results through the interface.
[0010] As a preferred technical solution, in step S3, the matching of task characteristics and agent capabilities specifically includes:
[0011] 1) Task requirement parsing and agent capability matching; when receiving an API call task request, first, the task parsing module deeply parses it to extract detailed task characteristics and requirement information. The agent management system compares these parsed task characteristics with each capability index in the agent capability catalog;
[0012] 2) Agent collaboration planning and task decomposition; for API call requests determined to be complex tasks, the agent management system starts the collaboration planning module. This module decomposes the complex task into multiple subtasks according to the logical structure and data flow of the task, determines the dependencies and execution order between the subtasks, and precisely matches the most suitable agent for each subtask from the initially screened agent list according to the characteristics and requirements of the subtasks, and establishes a collaboration relationship graph between the agents to clarify the paths and interfaces for information transmission;
[0013] 3) Agent selection decision-making and resource allocation optimization; after determining the potential agent list and the collaboration plan for complex tasks, the agent management system uses intelligent decision-making algorithms for the final agent selection, and through optimization algorithms, allocates reasonable computing resources and execution permissions to each selected agent to ensure that it can execute tasks efficiently;
[0014] 4) Agent collaboration startup and real-time coordination; after agent selection and resource allocation are completed, the agent management system sends a startup instruction to the selected agents and simultaneously starts the collaboration monitoring process; each agent starts to execute its respective subtasks according to the pre-planned collaboration plan; the collaboration monitoring process tracks the execution progress and collaboration status of the agents in real time and promptly discovers possible collaboration problems.
[0015] As a preferred technical solution, the process of comparing task features with each capability index in the intelligent agent capability catalog specifically includes the following steps: 1) Task feature extraction and arrangement. From the parsed task request, key information directly related to task execution is clearly extracted. For the key information of tasks involving water conservancy facility operations, the extracted key information is converted into the form of a feature vector to facilitate quantitative comparison with the indexes in the intelligent agent capability catalog; 2) Loading and preprocessing of the intelligent agent capability catalog. The intelligent agent management system reads the relevant data of the intelligent agent capability catalog from the storage medium and performs quantification and standardization processing on each index in the intelligent agent capability catalog; 3) Feature comparison and matching degree calculation. Each dimension of the task feature vector is compared one by one with the corresponding capability index dimension of each intelligent agent in the intelligent agent capability catalog. Based on the matching conditions of each dimension, the overall matching degree score between each intelligent agent and the task is calculated. Through this weighted summation calculation method, a comprehensive score representing the matching degree between each intelligent agent and the task is generated for each intelligent agent; 4) According to the preset matching degree threshold, the matching degree scores of all intelligent agents are screened.
[0016] As a preferred technical solution, the API call execution and monitoring implementation process specifically includes:
[0017] 1) API call request generation and optimization;
[0018] 2) API call execution and real-time status monitoring;
[0019] 3) Exception handling and fault tolerance mechanism triggering;
[0020] 4) API call result reception and integrity verification
[0021] 5) Performance data collection and feedback optimization.
[0022] As a preferred technical solution, the API call request generation and optimization process includes: The selected intelligent agent generates a specific API call request according to the task requirements and the interaction specifications with the API service provider. The intelligent agent uses its built-in API call optimization module to further optimize the request; The intelligent agent performs security verification and signature processing on the API call request to ensure the legality and integrity of the request, prevent malicious attacks and data tampering, and follow the security authentication mechanism of the API service provider.
[0023] As a preferred technical solution, the API call execution and real-time status monitoring process specifically includes: The agent sends the optimized API call request to the corresponding API service provider and starts the API call execution monitoring module. This module communicates with the interface of the API service provider in real time to obtain the execution status information of the API call, including information on key status nodes such as whether the request has been successfully received by the API server, whether the server has started processing the request, the current processing progress, and whether a response has been generated; At the same time, the monitoring module also monitors underlying technical indicators related to the API call execution in real time, such as the network connection status and data transmission rate.
[0024] As a preferred technical solution, the exception handling and fault tolerance mechanism is triggered as follows: If an abnormal situation is detected during the API call execution, the exception handling module of the agent will be immediately activated. The exception handling module first makes a preliminary judgment and classification according to the pre-set exception handling strategy. For some common recoverable errors, the agent will automatically start the retry mechanism and gradually increase the retry interval time according to the exponential backoff algorithm to avoid causing excessive request pressure on the API server. At the same time, the retry times and relevant error information are recorded for subsequent analysis and optimization. For relatively serious non-recoverable errors, the agent will trigger the fault tolerance mechanism, and the fault tolerance mechanism includes automatically switching to the standby API, sending an alarm to the agent management system and requesting manual intervention, or returning partial available data or prompt information to the user according to the pre-set degradation strategy to maintain the basic functions of the system and the coherence of the user experience as much as possible.
[0025] An agent-based API call interaction system, characterized by including: a construction and registration unit, a task acceptance and parsing module, an agent selection and API call execution unit, and a result processing and feedback unit.
[0026] A non-temporary storage medium is used to store a program, and this program is used to make an agent-based API call interaction system perform the following actions: execute an agent-based API call interaction method as described above
[0027] Compared with the prior art, the present solution has the following beneficial effects:
[0028] (1) Significantly improve the flexibility and intelligence level of API calls. By introducing agents with autonomous decision-making capabilities, the system can dynamically select the optimal API call strategy according to task requirements, getting rid of the dependence on fixed code in traditional methods. The agent is trained based on machine learning models and historical data, and can identify complex API call patterns and adaptively adjust strategies, so as to efficiently handle diverse business scenarios and dynamic API environments.
[0029] (2) Reduce the development threshold and labor costs, support natural language task descriptions, and enable users to complete call requests without in-depth understanding of API technical details or programming syntax. For example, when a user inputs "Statistical total order amount of user A in the past three months", the system automatically parses and triggers the order API and calculation logic, significantly reducing the coding workload of developers. At the same time, non-technical personnel can also conveniently use the API function, expanding the application scenarios and user groups.
[0030] (3) Enhance the complex task processing ability. For complex tasks involving multiple steps and cross-systems (such as data integration and analysis), the system automatically decomposes tasks, plans execution paths, and allocates multiple agents to collaborate through an agent collaboration mechanism. For example, an e-commerce data analysis task can be decomposed into sub-tasks such as order acquisition, user information query, and correlation analysis, which are executed in parallel by different agents and share data, significantly shortening the overall response time of the task.
[0031] (4) Optimize resource utilization and system performance. The dynamic agent selection algorithm comprehensively considers indicators such as function matching degree, real-time load, and historical performance to ensure that tasks are preferentially assigned to the optimal resources. For example, high-realtime tasks are automatically assigned to agents with low load and high performance. At the same time, API call times are reduced through request merging and parameter optimization, reducing network overhead and overall improving resource utilization and system throughput.
[0032] (5) Improve system robustness and fault tolerance. Monitor the entire life cycle of API calls in real time and quickly respond to problems such as network fluctuations and interface exceptions. For example, use an exponential backoff retry mechanism to handle temporary errors. When the interface is unavailable, automatically switch to a backup API or return a degraded result to avoid service interruption. In addition, the result integrity verification and performance data feedback mechanism continuously optimize system strategies, reducing the business impact caused by API failures and ensuring the continuity and stability of the user experience.
[0033] (6) Support rapid business expansion and convenient maintenance. The agent management system supports the rapid registration and ability update of new agents. Enterprises can flexibly expand API function modules according to business needs without reconstructing the existing system. For example, when adding a water conservancy monitoring API, only need to register the corresponding agent and update the ability catalog, and the system can automatically adapt to related tasks, significantly reducing system upgrade and maintenance costs. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0035] Figure 1 This is a flowchart of an agent-based API call interaction method of the present invention;
[0036] Figure 2 This is a flowchart for the implementation of agent selection and collaboration of the present invention. Detailed implementation manners
[0037] Next, the technical solution of the present invention will be clearly and completely described in conjunction with the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0038] Refer to Figures 1-2 , the present invention provides an agent-based API call interaction method. The agent-based API call interaction method of the present invention includes the following steps:
[0039] Step 1: Agent construction and registration
[0040] 1. Construct multiple agents with different functions and characteristics. Each agent has independent decision-making ability and certain domain knowledge, and can understand and process specific types of task requests. These agents can be implemented based on technologies such as machine learning, deep learning, and natural language processing. For example, a neural network model is used to train a large amount of API call data so that it can recognize different API call patterns and related semantic information.
[0041] 2. Register the constructed agents into the agent management system. The agent management system is responsible for the life cycle management of the agents, including operations such as creation, start, stop, update, and resource allocation. At the same time, the agent management system maintains an agent capability directory, recording information such as the function description of each agent, the requirements for input and output parameters, and the types of tasks it is good at processing, so as to quickly locate and select appropriate agents according to task requirements later.
[0042] Step 2: Task reception and parsing
[0043] 1. Set up a unified task reception interface for receiving API call task requests from external systems or users. The task requests can be in various forms, such as structured query languages, natural language descriptions, or message bodies in specific formats.
[0044] 2. After receiving a task request, use natural language processing technology and semantic analysis tools to parse the task request, extract key information, including the target API, operation type, input parameters, expected results, etc. For example, for a task request described in natural language "Query the latest order information of user [specific username]", through semantic analysis, it is identified that the order management API needs to be called, the operation type is query, the input parameter is the username, and the expected result is the latest order information of this user.
[0045] Step Three: Intelligent Agent Selection and Collaboration Implementation Process
[0046] 1. Task Requirement Analysis and Intelligent Agent Capability Matching
[0047] 1) After receiving an API call task request, first, the task parsing module deeply parses it to extract detailed task characteristics and requirement information, including but not limited to the data domain involved, the complexity of the operation, the required response speed, and specific business rules, etc.
[0048] 2) The intelligent agent management system compares these parsed task characteristics with each capability index in the intelligent agent capability catalog. The specific implementation steps are as follows:
[0049] (1) Task Characteristic Extraction and Sorting
[0050] 1. Key Information Extraction
[0051] 1) From the parsed task request, clearly extract the key information directly related to task execution. For example, in a task in the water conservancy field, if it is to query the water level change trend in a specific area, then the key information includes "area range" (such as geographical coordinates, river basin name, etc.), "water level" (as the hydrological element of concern), and "change trend" (involving the need for time series analysis).
[0052] 2) For tasks involving the operation of water conservancy facilities, such as "Open the flood discharge gate of a certain reservoir to a specific opening", extract key information such as "reservoir name", "flood discharge gate", and "opening set value". These key information will be used as the basic data points for subsequent comparison.
[0053] 2. Feature Vector Construction
[0054] 1) Convert the extracted key information into the form of feature vectors for quantitative comparison with the indexes in the intelligent agent capability catalog. Each feature is assigned a specific dimension, and its value or category represents the specific situation of this feature in the task.
[0055] 2) For example, for the regional scope, it can be converted into digital coordinates through a geocoding system and occupy the corresponding dimensions in the feature vector; for hydrological elements such as water levels, predefined codes (e.g., 1 represents water level, 2 represents flow rate, etc.) can be used for identification; for operation types (such as query, control, etc.), there are also corresponding codes. In this way, a complete task is represented as a multi-dimensional feature vector, clearly presenting all aspects of the task.
[0056] (II) Agent Capability Catalog Loading and Preprocessing
[0057] 1. Catalog Data Reading
[0058] The agent management system reads the relevant data of the agent capability catalog from storage media (such as databases, file systems, etc.). This catalog contains detailed capability descriptions of each agent, such as the types of water conservancy tasks the agent is good at handling (such as flood prediction, water resource scheduling, water conservancy facility monitoring, etc.), the scope of water conservancy facilities it can operate (covering information on different reservoirs, sluices, pumping stations, etc.), the required data input formats and sources (such as hydrological monitoring data and geographical information data in specific formats), the types and accuracy requirements of the output data (such as the time resolution of prediction results, the accuracy of water level values, etc.), and its performance indicators (such as processing speed, accuracy, etc.).
[0059] 2. Capability Index Quantification and Standardization
[0060] To effectively compare with the task feature vector, various indicators in the agent capability catalog are quantified and standardized. For some qualitative capability descriptions, such as the types of tasks it is good at, a classification coding method is adopted; for performance indicators, they are normalized to a unified numerical range. For example, the processing speed is converted into a value between 0 and 1 according to the relative ratio, so as to be able to make a fair comparison with other agents in subsequent comparisons. At the same time, information such as data input and output formats is also structured to enable accurate matching with task features.
[0061] (III) Feature Comparison and Matching Degree Calculation
[0062] 1. Dimension Matching
[0063] 1) Each dimension of the task feature vector is compared one by one with the corresponding capability index dimensions of each agent in the agent capability catalog. For example, the "regional scope" dimension in the task feature vector is matched with the "processing regional scope" capability index of the agent to check whether there is an intersection or complete coverage; for the "operation type" dimension, it is precisely matched with the "supported operation type" index of the agent to determine whether the agent has the operation ability required to execute this task.
[0064] 2) If there is a mismatch in a certain dimension, for example, the task requires processing the data format of a specific new sensor, but the agent's capabilities catalog shows that the agent does not support this data format, then the agent's matching score in this dimension will be zero or a lower preset value.
[0065] 2. Overall matching degree evaluation
[0066] 1) Based on the matching situations in each dimension, calculate the overall matching degree score of each agent with the task. The weighted summation method can be used to assign corresponding weights to each dimension according to its importance in the task. For example, in a task with extremely high requirements for the accuracy of water level prediction, the matching situations of the agent in dimensions such as "water level data processing ability" and "accuracy of prediction model" will be given higher weights, while for some relatively less important dimensions, such as data visualization ability (if the task has low requirements for visualization), lower weights will be given.
[0067] 2) Through this calculation method of weighted summation, generate a comprehensive score representing the matching degree of each agent with the task. The higher the score, the more likely the agent is to be competent for the task.
[0068] (IV) Preliminary screening and sorting
[0069] 1. Threshold screening
[0070] According to the preset matching degree threshold, screen the matching degree scores of all agents. Only the agents with scores higher than the threshold will be included in the preliminary candidate list. The setting of this threshold can be adjusted according to the requirements of the actual application scenario. If the requirements for the accuracy and efficiency of task execution are relatively high, the threshold can be increased accordingly; if the task is relatively flexible and there are many agents to choose from, the threshold can be appropriately lowered to expand the candidate range.
[0071] 2. Sorting and output
[0072] Sort the preliminarily screened agents in descending order of their matching degree scores and output this ordered list of agents. The agents ranked in the front have higher priorities in subsequent task assignment and execution. Unless restricted by other factors (such as current load, resource availability, etc.), they will be preferentially selected to execute the task. Such a sorting method ensures that when multiple agents all have a certain execution ability, the agent that is most matched with the task and most likely to complete the task efficiently is preferentially selected, improving the task execution efficiency and quality of the entire system.
[0073] 3) At the same time, consider the real-time status information of the agents, such as the current computing resource occupancy rate, the number of tasks being executed, and their priorities, etc. By comprehensively considering these factors, initially screen out a list of potential agents that can execute this task.
[0074] 2. Agent Collaboration Planning and Task Decomposition (for complex tasks)
[0075] 1) For API call requests determined to be complex tasks, such as tasks that require simultaneously calling multiple different data source APIs and performing data integration and analysis, the agent management system starts the collaboration planning module.
[0076] 2) This module decomposes the complex task into multiple subtasks according to the logical structure and data flow of the task, and determines the dependency relationships and execution order among the subtasks. For example, in a sales data analysis task on an e-commerce platform, it may first be necessary to call the order API to obtain order data, then call the user API to obtain user information, and then perform an association analysis on the two. At this time, it will be decomposed into three subtasks: order data acquisition, user information acquisition, and association analysis.
[0077] 3) According to the characteristics and requirements of the subtasks, accurately match the most suitable agent for each subtask from the initially screened list of agents, and establish a collaboration relationship graph among the agents to clarify the paths and interfaces for information transmission. For example, after the order data acquisition agent completes the task, it transmits the data to the association analysis agent, and at the same time, the user information acquisition agent also transmits the data it has obtained to the association analysis agent for integration processing.
[0078] 3. Agent Selection Decision and Resource Allocation Optimization
[0079] 1) After determining the list of potential agents and the collaboration plan for the complex task, the agent management system uses an intelligent decision-making algorithm for the final agent selection. This decision-making algorithm comprehensively considers multiple factors. In addition to the previously mentioned ability matching degree and real-time status, it also includes the historical performance data of the agents (such as average response time, error rate, etc.), recent activity levels (reflecting their adaptability to the current environment), and resource consumption models (estimating the computing resources and network bandwidth required to execute this task, etc.).
[0080] 2) Through an optimization algorithm, allocate reasonable computing resources and execution permissions to each selected agent to ensure that it can execute the task efficiently. For example, for a task with high real-time requirements, preferentially allocate more CPU cores and high-speed memory to the agents responsible for key links, and at the same time limit the resource competition of other low-priority tasks for them to ensure the rapid execution and response of the task.
[0081] 4. Agent Collaboration Startup and Real-time Coordination
[0082] 1) Once the agent selection and resource allocation are completed, the agent management system sends a start instruction to the selected agent and simultaneously starts the cooperation monitoring process.
[0083] 2) Each agent starts to execute its respective subtasks according to the pre-planned cooperation scheme. During the execution process, they conduct real-time information interaction and status synchronization through the inter-agent communication protocol. For example, when an agent completes a certain data processing step, it immediately sends a data ready signal to the subsequent dependent agent, along with relevant data summaries and processing status information, so that the subsequent agent can respond in a timely manner and start processing.
[0084] 3) The cooperation monitoring process tracks the execution progress and cooperation status of the agents in real time, promptly discovers possible cooperation problems, such as data transmission delays, abnormal agent execution, etc., and takes corresponding coordination measures. For example, if it is found that a certain agent's data transmission is interrupted due to a network failure, the monitoring process will attempt to re-establish the connection or start an alternative data transmission channel, and notify the relevant agents to adjust their waiting times and processing logics to ensure the smooth progress of the entire cooperation process.
[0085] Step Four: API Call Execution and Monitoring Implementation Process
[0086] 1. API Call Request Generation and Optimization
[0087] 1) The selected agent generates a specific API call request according to the task requirements and the interaction specifications with the API service provider. During the generation process, the agent first sorts and preprocesses the data required for the task to ensure that the format and content of the data meet the parameter requirements of the API.
[0088] 2) The agent uses its built-in API call optimization module to further optimize the request. For example, according to the historical response data and performance metrics of the API, it adjusts the parameter order of the request, combines multiple related small requests into one large request (if the API supports batch operations), in order to reduce the number of API calls and network transmission overheads, and improve the overall execution efficiency.
[0089] 3) At the same time, the agent conducts security verification and signature processing on the API call request to ensure the legality and integrity of the request, prevent malicious attacks and data tampering, and follow the security authentication mechanism of the API service provider, such as using authorization protocols like OAuth for identity authentication and authorization.
[0090] 2. API Call Execution and Real-Time Status Monitoring
[0091] 1) The agent sends the optimized API call request to the corresponding API service provider and activates the API call execution monitoring module.
[0092] 2) This module communicates with the interface of the API service provider in real time to obtain the execution status information of the API call, including information on key status nodes such as whether the request has been successfully received by the API server, whether the server has started processing the request, the current processing progress (if the API provides relevant feedback), and whether a response has been generated.
[0093] 3) At the same time, the monitoring module also monitors in real time underlying technical metrics related to the execution of the API call, such as the network connection status and data transfer rate, in order to promptly detect potential problems such as network failures and server overloads that may affect the success of the API call. For example, the stability of the network connection is detected by periodically sending heartbeat packets. Once it is found that the network latency exceeds the preset threshold, network optimization measures are immediately initiated, such as switching the network access point or adjusting the parameters of the data transfer protocol.
[0094] 3. Triggering of Exception Handling and Fault Tolerance Mechanisms
[0095] 1) If an abnormal situation is detected during the execution of the API call, such as the API server returning an error code (indicating incorrect request parameters, insufficient permissions, internal server errors, etc.), timeout without response, or network connection interruption, the exception handling module of the agent will be immediately activated.
[0096] 2) The exception handling module first makes a preliminary judgment and classification according to the preset exception handling strategy. For some common recoverable errors, such as timeout errors caused by network fluctuations, the agent will automatically start the retry mechanism, gradually increasing the retry interval time according to the exponential backoff algorithm, avoiding excessive request pressure on the API server, and at the same time recording the retry times and relevant error information for subsequent analysis and optimization.
[0097] 3) For more serious non-recoverable errors, such as incompatible request formats caused by changes in the interface of the API service provider or long-term unavailability of the server, the agent will trigger the fault tolerance mechanism. This may include automatically switching to an alternative API (if configured), sending an alert to the agent management system and requesting manual intervention, or returning partially available data or prompt information to the user according to the preset degradation strategy to maintain the basic functions of the system and the coherence of the user experience as much as possible.
[0098] 4. Receiving and Integrity Verification of API Call Results
[0099] 1) After the API call is successfully executed and the response result returned by the API service provider is received, the result receiving module of the agent verifies the integrity of the result. The verification content includes checking whether the format of the response data conforms to the expectation, whether the data volume is complete (compared with the returned data structure and quantity described in the API documentation), and whether it contains necessary metadata (such as status code, error message description, etc.).
[0100] 2) If it is found that there are problems such as data loss or format errors in the result, the agent will attempt to communicate with the API service provider and perform data repair and re - acquisition according to the error repair mechanism provided by it (such as re - requesting specific data segments, re - calling after correcting incorrect request parameters, etc.), ensuring that the finally received result data is accurate and complete and can meet the requirements of subsequent task processing and result feedback.
[0101] 5. Performance Data Collection and Feedback Optimization
[0102] 1) During the entire API call execution process, the agent continuously collects performance data related to the API call, including detailed metrics such as request sending time, response receiving time, actual processing time, data transfer volume, etc., and feeds this data back to the agent management system.
[0103] 2) The agent management system uses this performance data for statistical analysis and performance evaluation. On the one hand, it is used to optimize the current API call strategy and resource allocation plan of the agent. For example, adjust the task assignment priority of the agent according to the average response time of different APIs or optimize the network resource configuration. On the other hand, after summarizing these data, it generates an API performance report and provides it to system administrators and developers so that they can optimize the performance and plan resource expansion for the entire API call interaction system. For example, when it is found that the overall response time of a certain API is long and the call frequency is high, consider optimizing the performance of this API or looking for alternative solutions. At the same time, it also provides data support for the system's capacity planning and resource allocation to ensure that the system can operate stably and serve efficiently as the business volume grows.
[0104] Through the above innovative implementation process, efficient, intelligent, and reliable operation has been achieved in two key aspects: agent selection and collaboration, and API call execution and monitoring, effectively improving the overall performance and stability of the agent - based API call interaction system, and being able to better meet the complex and changing business requirements and technical environments.
[0105] Step Five: Result Processing and Feedback
[0106] 1. After the agent receives the response result returned by the API service provider, it processes and parses the result. According to the expected result of the task request, useful data is extracted and converted into a format suitable for users or external systems to understand. For example, if the API returns JSON-formatted data containing multiple order information, the agent can extract key information such as order numbers, order amounts, and order placement times according to the user's needs, and organize this information into a concise and clear table form.
[0107] 2. Finally, the processed result is fed back to the user or external system through the task receiving interface, completing the entire API call interaction process.
[0108] Compared with the prior art, the beneficial effects of this solution are as follows:
[0109] 1. Agent autonomous decision-making and collaborative interaction:
[0110] By introducing agents, the present invention enables them to make autonomous decisions according to task requirements and select appropriate API call strategies, getting rid of the dependence on manually writing fixed code in traditional API call methods. The collaboration mechanism among agents further enhances the system's ability to handle complex tasks. They can dynamically allocate tasks and share information to complete API calls in the optimal way, improving the flexibility and adaptability of the interaction and being able to better cope with changing business requirements and API environments.
[0111] 2. Natural language-driven task parsing and execution:
[0112] Supports receiving API call task requests in natural language form, greatly reducing the threshold of interaction between users and the system. Users do not need to understand complex API details and programming syntax. They only need to describe the required operations in daily language, and the system can automatically parse and execute the corresponding API calls. This not only improves development efficiency but also enables non-technical personnel to conveniently use APIs for data interaction and function calls, expanding the application scope and user group of APIs.
[0113] 3. Agent dynamic selection and optimization:
[0114] In the process of agent selection, multiple factors such as function matching degree, load situation, and historical execution performance are comprehensively considered to achieve the dynamic selection and optimal configuration of agents. This method ensures that each task can be assigned the most suitable agent resources, improving the overall performance and resource utilization rate of the system. At the same time, the agent can make adaptive adjustments according to the real-time status and performance indicators of the API. For example, when encountering a high API response delay, it automatically switches to a backup API or takes other optimization measures to ensure the stability and reliability of API calls.
[0115] 4. Comprehensive API Call Monitoring and Fault Tolerance Handling:
[0116] A perfect API call monitoring mechanism is established to monitor the entire life cycle of API calls in real time, enabling timely detection and handling of various abnormal situations. By introducing fault tolerance handling strategies such as retry mechanisms and alternative API switching, the robustness and fault tolerance of the system are improved, the impact on business processes caused by API call failures is reduced, and the continuity and stability of the user experience are ensured.
[0117] The above are only the preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present invention shall be included within the protection scope of the present invention.
Claims
1. An agent-based API calling interaction method, characterized in that: The following steps are involved: Step S1: Agent construction and registration, constructing multiple agents with independent decision-making capabilities and domain knowledge, the agents are implemented based on machine learning and natural language processing technologies, and registered with the agent management system; the system maintains the agent capability directory, records the agent's functional description, input and output parameters, and task type information; Step S2: Task reception and analysis: receiving a task request through a unified interface, wherein the request includes natural language, structured query or specific message format; performing natural language processing and semantic analysis on the task request to extract the target API, operation type, input parameters and expected results; Step S3: Agent selection and collaboration, matching task features with agent capability catalogs, generating matching scores and screening candidate agents; decomposing complex tasks, planning dependencies between subtasks, and assigning agents to collaborate and execute; dynamically selecting agents and allocating resources based on capability matching, real-time status, and resource consumption models; Step S4: API call execution and monitoring, generating optimized API call requests, executing and monitoring the status in real time; triggering exception handling and fault tolerance mechanisms, including retry, standby API switching and downgrade strategies; Verify the integrity of API response results and collect performance data to optimize subsequent calls; Step S5: Result processing and feedback: parsing the API response data and converting it into the user-specified format, and feeding back the results through the interface.
2. The agent-based API calling interaction method according to claim 1, characterized in that: In step S3, the matching of task characteristics and agent capabilities specifically includes: 1) Task requirement analysis and agent capability matching: When receiving an API call task request, the task analysis module first performs a deep analysis to extract detailed task features and requirement information. The agent management system then compares these analyzed task features with the various capability indicators in the agent capability catalog; 2) Agent collaboration planning and task decomposition: For API call requests that are determined to be complex tasks, the agent management system starts the collaboration planning module, which decomposes the complex task into multiple subtasks based on the logical structure and data flow of the task, and determines the dependencies and execution order between the subtasks. According to the characteristics and requirements of the subtasks, the most suitable agent is accurately matched to each subtask from the preliminary screened agent list, and a collaboration relationship diagram between agents is established to clarify the path and interface for information transmission; 3) Agent selection decision and resource allocation optimization: After determining the list of potential agents and the collaborative plan for complex tasks, the agent management system uses an intelligent decision-making algorithm to make the final agent selection. Through the optimization algorithm, it allocates reasonable computing resources and execution permissions to each selected agent to ensure that it can perform tasks efficiently. 4) Initiation and real-time coordination of agent collaboration: After agent selection and resource allocation, the agent management system sends a startup instruction to the selected agent and starts the collaboration monitoring process at the same time; each agent begins to execute its own subtask according to the pre-planned collaboration plan; the collaboration monitoring process tracks the execution progress and collaboration status of the agent in real time, and promptly discovers possible collaboration problems.
3. The agent-based API calling interaction method according to claim 2, characterized in that: The process of comparing the task features with the various capability indicators in the agent capability catalog specifically includes the following steps: 1) extracting and organizing task features, from the parsed task request, clearly extracting the key information directly related to the task execution, and for the key information of the task involving the operation of water conservancy facilities, converting the extracted key information into the form of feature vectors, so as to facilitate quantitative comparison with the indicators in the agent capability catalog; 2) loading and preprocessing the agent capability catalog, the agent management system reads the relevant data of the agent capability catalog from the storage medium, and quantifies and standardizes the various indicators in the agent capability catalog; 3) feature comparison and matching degree calculation, each dimension of the task feature vector is compared one by one with the corresponding capability indicator dimension of each agent in the agent capability catalog, and the matching of each dimension is comprehensively calculated to calculate the overall matching degree score of each agent and the task. Through this weighted summation calculation method, a comprehensive score representing the degree of matching between each agent and the task is generated for each agent; 4) according to the preset matching degree threshold, the matching degree scores of all agents are screened.
4. The agent-based API calling interaction method according to claim 1, characterized in that: The API call execution and monitoring implementation process specifically includes: 1) API call request generation and optimization; 2) API call execution and real-time status monitoring; 3) Exception handling and fault tolerance mechanism triggering; 4) API call result reception and integrity verification 5) Performance data collection and feedback optimization.
5. The agent-based API calling interaction method according to claim 4, characterized in that: The API call request generation and optimization process includes: the selected agent generates a specific API call request according to the task requirements and the interaction specifications with the API service provider, and the agent uses its built-in API call optimization module to further optimize the request; the agent performs security verification and signature processing on the API call request to ensure the legitimacy and integrity of the request, prevent malicious attacks and data tampering, and comply with the security authentication mechanism of the API service provider.
6. The agent-based API calling interaction method according to claim 4, characterized in that: The API call execution and real-time status monitoring process specifically includes: the intelligent agent sends the optimized API call request to the corresponding API service provider, and starts the API call execution monitoring module, which communicates with the interface of the API service provider in real time to obtain the execution status information of the API call, including whether the request is successfully received by the API server, whether the server starts processing the request, the current processing progress, and whether a response has been generated, etc. Information on key status nodes; at the same time, the monitoring module also monitors the network connection status, data transmission rate and other underlying technical indicators related to API call execution in real time.
7. The agent-based API calling interaction method according to claim 4, characterized in that: The exception handling and fault-tolerance mechanism is triggered as follows: if an abnormal situation is detected during the execution of the API call, the exception handling module of the intelligent agent will be immediately activated. The exception handling module will first make a preliminary judgment and classification based on the pre-set exception handling strategy. For some common recoverable errors, the intelligent agent will automatically start the retry mechanism and gradually increase the retry interval according to the exponential backoff algorithm to avoid excessive request pressure on the API server. At the same time, the number of retries and related error information are recorded for subsequent analysis and optimization. For more serious unrecoverable errors, the intelligent agent will trigger the fault-tolerance mechanism. The fault-tolerance mechanism includes automatically switching to a backup API, sending an alarm to the intelligent agent management system and requesting manual intervention, or returning some available data or prompt information to the user according to a preset degradation strategy, so as to maintain the basic functions of the system and the consistency of the user experience as much as possible.
8. The agent-based API calling interactive system according to claim 1, characterized in that: include: Construction and registration unit, task acceptance and parsing module, agent selection and API call execution unit, result processing and feedback unit.
9. A non-temporary storage medium, characterized in that: It is used to store a program, which is used to enable the agent-based API call interaction system as described in claim 8 to perform the following actions: execute an agent-based API call interaction method as described in any one of claims 1 to 7 above.
Citation Information
Cited By
Multi-agent collaborative management method and system
CN120542463A
Multi-agent collaborative management method and system
CN120542463B
Information processing method and device, storage medium and computer equipment
CN120706578A
Information processing method and device, storage medium and computer device
CN120706578B
Intelligent agent-based information system state analysis method and device, equipment and medium
CN120805123A