Intelligent agent communication method, readable storage medium and electronic equipment
By introducing a unified communication framework and message queue into the multi-agent software system, the problem of inconsistent communication methods among different agents is solved, achieving efficient message transmission and resource utilization, and improving the system's operating efficiency and reliability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- GREAT WALL MOTOR CO LTD
- Filing Date
- 2026-01-28
- Publication Date
- 2026-05-01
AI Technical Summary
In multi-agent software systems, different agents are developed by different teams, resulting in different communication methods. This necessitates protocol conversion during system operation, consuming hardware resources and time, and reducing operational efficiency.
A unified communication framework is adopted, which enables direct communication between agents through message queues and communication interfaces, avoiding protocol conversion. The target agent is selected by using message queue caching and selection weight algorithm, high-priority messages are processed first, and the number of times to send and the expiration time are set to ensure message timeliness.
It improves the operating efficiency of the software system, reduces hardware resource consumption and communication time, and increases the success rate of message sending and the reliability of the system.
Smart Images

Figure CN121967535A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of software technology, and more specifically, to an intelligent agent communication method, a readable storage medium, and an electronic device in the field of software technology. Background Technology
[0002] To improve the operating efficiency of software systems, multiple agents are typically used to build the software system.
[0003] For software systems with multiple agents, different agents are developed by different teams for different scenarios during the development process, and therefore, the communication methods used by different agents may differ. As a result, during the operation of the software system, the agents need to communicate through protocol conversion, leading to low overall system efficiency. Summary of the Invention
[0004] This application provides an agent communication method, a readable storage medium, and an electronic device, which can improve the operating efficiency of software systems with multiple agents.
[0005] Firstly, a method for intelligent agent communication is provided, the method comprising:
[0006] When a target message is received from a source agent among multiple agents, the target message is cached in a message queue; Extract the target message from the message queue; Based on the extracted target message, a target intelligent agent for processing the target message is determined from other intelligent agents, wherein the other intelligent agents are intelligent agents other than the source intelligent agent among the plurality of intelligent agents; Send the target message to the target agent.
[0007] In this embodiment, upon receiving a target message from a source agent among multiple agents, the target message is cached in a message queue. The target message is then extracted from the message queue. Based on the extracted target message, a target agent is determined from the other agents to process the target message, and the target message is sent to that target agent. The agents communicate through message structures and communication interfaces, enabling indirect communication via the communication framework without protocol conversion. This avoids protocol conversion during communication, reduces hardware resource and time consumption, and improves the operating efficiency of the software system.
[0008] Optionally, determining the target agent for processing the target message from other agents includes: extracting the type identifier and service identifier of the target message from the target message; when the type identifier indicates that the message type of the target message is a non-broadcast message, determining N candidate agents from the other agents, wherein the N candidate agents include agents for processing the message corresponding to the service identifier, and N is an integer greater than 0; The target agent is determined from the N candidate agents.
[0009] In this embodiment of the application, for a target message, N candidate intelligent agents are determined according to the message type and service type of the target message. One of the N candidate intelligent agents is selected as the target intelligent agent, and the target message is sent to the target intelligent agent for processing, which can achieve accurate delivery of the target message.
[0010] Optionally, determining the target agent from the N candidate agents includes: for each candidate agent, determining a selection weight for the candidate agent based on at least one of the candidate agent's current load, response time, and health score; and determining the target agent from the N candidate agents based on the selection weight of each candidate agent.
[0011] In this embodiment of the application, when there are multiple candidate agents, the target agent is determined from the multiple candidate agents based on one or more of the current load, response time and health score of each candidate agent. The candidate agent with a smaller load, shorter response time and higher health score can be selected as the target agent, so that the target message can be sent to a reliable agent, which can increase the probability that the message is responded to normally.
[0012] Optionally, the method further includes: when the type identifier indicates that the message type of the target message is a broadcast message, obtaining the health tag of each of the plurality of agents other than the source agent; and identifying the agent whose health tag indicates that it is healthy as the target agent.
[0013] In this embodiment of the application, when the target message is a broadcast message, the target intelligent agent in a healthy state is determined based on the health tag of each intelligent agent other than the source intelligent agent, and the target message is broadcast to the target intelligent agent in a healthy state. This can avoid sending the target message to unhealthy intelligent agents, thereby reducing unnecessary message sending and improving communication efficiency.
[0014] Optionally, the target message includes metadata, and caching the target message in a message queue includes: extracting the priority identifier of the target message from the metadata; caching the target message in the message queue based on the priority identifier of the target message, so as to extract the target message from the message queue according to the priority order of each message cached in the message queue.
[0015] In this embodiment of the application, the priority identifier of the target message is extracted from the metadata, and the target message is cached in the message queue based on the priority identifier of the target message. The target message can be extracted from the message queue and sent according to the priority order of each message cached in the message queue. In this way, the message with higher importance can be sent first according to the importance of each message in the message queue, thereby ensuring that the message with higher importance is processed first.
[0016] Optionally, sending the target message to the target agent includes: determining whether the cache duration of the target message in the message queue has reached the cache duration limit; if the cache duration limit has not been reached, then sending the target message to the target agent.
[0017] In this embodiment of the application, before sending the target message to the target agent, it is determined whether the cache duration of the target message in the message queue has reached the cache duration limit. If the cache duration limit has not been reached, the target message is sent to the target agent. If the cache duration limit has been reached, the target message is discarded, which can ensure the timeliness of the target message.
[0018] Optionally, after sending the target message to the target agent, the method further includes: if it is determined that the target message failed to be sent, extracting the number of times the target message was sent and the upper limit of the number of times the message was sent from the metadata; if the number of times the message was sent did not reach the upper limit of the number of times the message was sent, updating the number of times the message was sent, and re-caching the target message in the message queue.
[0019] In this application, a maximum number of message sending attempts is set. When sending a target message to a target agent fails, the message can be sent multiple times consecutively, thereby improving the success rate of message delivery. Simultaneously, stopping message sending when the maximum number of attempts is reached reduces unnecessary message sending and thus minimizes resource consumption.
[0020] Optionally, caching the target message in the message queue includes: upon receiving the target message, extracting the expiration time of the target message from the metadata; and if it is determined based on the expiration time that the target message has not expired, caching the target message in the message queue.
[0021] In this embodiment, an expiration time is set for the target message. After receiving the target message, its expiration time is obtained. If the expiration time determines that the target message has not expired, it is cached in a message queue for transmission to the target agent. If the expiration time determines that the target message has expired, it is discarded. This ensures the timeliness of the target message, reduces unnecessary message transmission, and improves communication efficiency.
[0022] Secondly, a smart agent communication device is provided, the device comprising: A caching module is used to cache the target message into a message queue when a target message is received from a source agent among multiple agents; An extraction module is used to extract the target message from the message queue; The determination module is used to determine, based on the extracted target message, a target intelligent agent from other intelligent agents for processing the target message, wherein the other intelligent agents are intelligent agents other than the source intelligent agent among the plurality of intelligent agents; The sending module is used to send the target message to the target intelligent agent.
[0023] Thirdly, an electronic device is provided, the electronic device comprising: Memory, used to store executable program code; A processor is configured to call and run the executable program code from the memory, causing the electronic device to perform the method in any possible implementation of the first aspect described above.
[0024] Fourthly, a program product is provided, comprising: executable program code, which, when run on an electronic device, causes the electronic device to perform the method in any possible implementation of the first aspect described above.
[0025] Fifthly, a readable storage medium is provided that stores executable program code, which, when run on an electronic device, causes the electronic device to perform the method in any possible implementation of the first aspect described above. Attached Figure Description
[0026] Figure 1 This is a schematic diagram illustrating the implementation principle of an intelligent agent communication method provided in an embodiment of this application; Figure 2 This is a flowchart illustrating the steps of an intelligent agent communication method provided in an embodiment of this application; Figure 3 This is a flowchart illustrating an intelligent agent communication method provided in an embodiment of this application; Figure 4 This is a schematic diagram of the structure of an intelligent agent communication device provided in an embodiment of this application; Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0027] The technical solutions in this application will be clearly and thoroughly described below with reference to the accompanying drawings. In the description of the embodiments of this application, unless otherwise stated, " / " means "or," for example, A / B can mean A or B. "And / or" in the text is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Furthermore, in the description of the embodiments of this application, "multiple" refers to two or more than two.
[0028] Hereinafter, the terms "first" and "second" are used for descriptive purposes only and should not be construed as implying or suggesting relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature.
[0029] An intelligent agent is a software entity with autonomous decision-making and message processing capabilities, responsible for completing specific business functions. To improve the operational efficiency of a software system, multiple intelligent agents are typically used to build the system. When a software system has multiple intelligent agents, these agents may need to communicate with each other during the system's operation to collaborate and complete specific tasks.
[0030] Taking an intelligent cockpit system as an example, such a system includes agents for voice recognition, navigation, understanding driving intentions, and vehicle fault analysis. During operation, the navigation agent needs to call upon the voice recognition agent to recognize the driver's voice input, thus identifying the destination and providing navigation accordingly.
[0031] Typically, different intelligent agents are developed by different R&D teams for different scenarios. Therefore, different intelligent agents may use different communication methods. For example, intelligent agents can use Hypertext Transfer Protocol (HTTP), WebSocket Protocol, Transmission Control Protocol Socket (TCP Socket), in-process calls, and other communication methods to communicate.
[0032] Because different agents use different communication methods, they need to communicate through protocol conversion during the operation of the software system. This not only consumes too much hardware resources during the communication process, but also takes a long time, resulting in low operating efficiency of the entire software system.
[0033] To address the aforementioned technical problems, this application provides an agent communication method. In this method, a unified communication framework is established for multiple agents. The agents communicate with each other through this framework. After communication, the agent sending the message sends a message to the communication framework, which then caches the message in a message queue. Simultaneously, the communication framework periodically retrieves messages from the message queue and sends them to the corresponding agents. Each agent communicates with the communication framework through a unified communication interface and message structure. This unifies the message structure and communication interface among the agents, allowing them to communicate indirectly through the framework without protocol conversion. This avoids protocol conversion during communication, reduces hardware resource and time consumption, and improves the operating efficiency of the software system.
[0034] It is understandable that during the development of each intelligent agent, different research and development teams develop communication interfaces for the intelligent agents to communicate with the communication framework according to a unified communication protocol. In this way, different intelligent agents can communicate with the communication framework through a unified communication interface.
[0035] For ease of distinction, the agent that sends the message will be referred to as the source agent, and the agent that receives the message will be referred to as the target agent.
[0036] See Figure 1 , Figure 1 This is a schematic diagram illustrating the implementation principle of an intelligent agent communication method provided in an embodiment of this application. For example... Figure 1 As shown, the entire software system includes agents 1 through N, a communication framework, and other components not shown. The communication framework is a software entity that includes a message bus, several middleware components, a message queue, a registry center, and several worker threads.
[0037] Multiple agents communicate with the communication framework via a message bus. Each agent, once online, can register with the registry center. During registration, the agent can register its agent identifier (ID), name, and type, as well as the business identifier of the service it handles. It can also register its address, port number, transmission protocol, and metadata.
[0038] During communication, the source agent sends a message to the message bus using a pre-defined message structure. The middleware preprocesses the message and stores it in a message queue. Worker threads retrieve messages from the message queue, identify the target agent from all registered agents, and send the message to the target agent via the message bus.
[0039] Each message in the pre-defined message structure includes a message identifier, type identifier, routing information, business data, association information, metadata, and error information. The message identifier uniquely identifies the message; the type identifier indicates whether the message is a broadcast message, a point-to-point message, or an event message; the routing information includes the agent identifiers of the message sender (the agent that generated the message) and the message receiver (the agent that processed the message); the business data refers to the message payload, i.e., the specific data the sender needs to send to the receiver. Association information identifies the session or dialogue between agents, as well as requests and responses. The metadata includes the message's priority identifier, creation time, expiration time, number of times it can be sent, the maximum number of times it can be sent, and the business identifier. It should be understood that the information included in each message may include, but is not limited to, the examples above.
[0040] Figure 1 The software system shown is deployed in a device, which can contain one or more hardware components. Multiple intelligent agents and communication frameworks can be deployed in one piece of hardware or distributed across different hardware components. Examples of devices include vehicles, software systems include smart cockpit systems, and vehicle hardware includes electronic control units (ECUs), multimedia control units (MCUs), and cockpit domain controllers (CDCs).
[0041] It should be understood that the above are merely illustrative examples, and the equipment may include, but is not limited to, vehicles, and the software system may include, but is not limited to, smart cockpit systems.
[0042] See Figure 2 , Figure 2 This is a flowchart illustrating the steps of an intelligent agent communication method provided in an embodiment of this application. The executing entity of this method can be hardware that deploys a communication framework in a device, and the method may include the following steps: Step 201: When a target message is received from a source agent among multiple agents, the target message is cached in a message queue.
[0043] Step 202: Extract the target message from the message queue.
[0044] In this embodiment, each agent communicates with the message bus in the communication framework. After generating business data for a certain service, the agent (i.e., the source agent) can construct the target message of the above message structure based on the business data and then send the target message to the message bus in the communication framework.
[0045] like Figure 1 As shown, assuming Agent 1 is used for speech recognition and Agent 2 is used for navigation, when Agent 2 needs to perform speech recognition, it can package the speech data to be recognized (i.e., business data) into multiple consecutive target messages (each target message includes an audio segment from the speech data). It sends one target message to the message bus of the communication framework each time, continuously sending each target message. In each packaged target message, the business data is a corresponding audio segment, the routing information includes the agent identifiers of Agent 2 and Agent 1, and the metadata includes the target message's priority identifier, creation time, expiration time, number of transmissions, maximum number of transmissions, and business identifier, etc.
[0046] Among them, the priority identifier and service identifier can be set by the intelligent agent 2 based on the priority of the speech recognition service, the creation time can be set by the intelligent agent 2 according to the actual creation time of the target message, and the expiration time, number of times to send, and upper limit of the number of times to send can be preset values or can be specifically set by the intelligent agent 2 based on the actual situation.
[0047] In this embodiment, upon receiving a target message from the source agent, the communication framework (i.e., middleware) can preprocess the target message. After preprocessing, the target message can be cached in a message queue. For example, when caching target messages in the message queue, each target message can be stored sequentially in the message queue according to the time the communication framework (i.e., communication bus) receives the target message. Correspondingly, each message stored in the message queue can follow a first-in, first-out (FIFO) principle. When the communication framework (i.e., worker threads) retrieves messages from the message queue, it can retrieve the earliest cached target message from the message queue in chronological order.
[0048] It should be noted that there may be a considerable time interval between a target message being cached in the message queue and its retrieval from the message queue. That is, after a target message is cached in the message queue, it may not be retrieved and sent immediately. Referring to the example above, when each received target message is cached in the order of its reception time, after a target message is cached in the message queue, it can only be removed and sent by the communication framework after the previously stored target messages have been retrieved.
[0049] Optionally, middleware may include logging middleware. For each message received by the message bus, during preprocessing, the logging middleware can record the sender, receiver, business data within the message, and other information. The various messages recorded by the logging middleware can be used for tracing after a system failure to quickly determine the cause of the failure. Middleware may include monitoring middleware. Monitoring middleware can statistically analyze the number of messages transmitted in the message bus, the average latency, and the error rate of the message bus. The various data monitored by the monitoring middleware can help users monitor the status of the entire system. Middleware may include rate limiting middleware. Rate limiting middleware can limit the number of messages transmitted in the message bus based on a token bucket algorithm or other algorithms. Rate middleware can control the message data output in the message bus to ensure the reliable operation of the communication framework. It should be understood that the above are merely illustrative examples, and the specific types and number of middleware may include, but are not limited to, the examples above.
[0050] It is understandable that during operation, the communication framework receives messages (i.e., target messages) sent by any agent (i.e., the source agent) and caches the messages in a message queue. The message queue can store a large number of messages sent by different agents at the same time.
[0051] Step 203: Based on the extracted target message, determine the target agent from other agents to process the target message.
[0052] Step 204: Send the target message to the target agent.
[0053] Among them, other intelligent agents are those other than the source intelligent agent among multiple intelligent agents. Figure 1 For example, when the source agent sending the target message is agent 2, the other agents are agents other than agent 2, namely agent 1, agent 3 and agent N.
[0054] In this embodiment, after retrieving the target message from the message queue, the communication framework can determine the target agent for processing the target message from other agents based on the message type and service type of the message, and send the target message to the target agent.
[0055] In this embodiment, upon receiving a target message from a source agent among multiple agents, the target message is cached in a message queue. The target message is then extracted from the message queue. Based on the extracted target message, a target agent is determined from the other agents to process the target message, and the target message is sent to that target agent. The agents communicate through message structures and communication interfaces, enabling indirect communication via the communication framework without protocol conversion. This avoids protocol conversion during communication, reduces hardware resource and time consumption, and improves the operating efficiency of the software system.
[0056] Optionally, the target agent for processing the target message is determined from other agents, including: Extract the type identifier and business identifier of the target message from the target message; When the type identifier indicates that the message type of the target message is a non-broadcast message, N candidate agents are determined from other agents. The N candidate agents include the agent used to process the message corresponding to the business identifier, and N is an integer greater than 0. Determine the target agent from N candidate agents.
[0057] In practical applications, for the same business function, one intelligent agent can be deployed in the software system, or multiple identical intelligent agents can be deployed. When multiple intelligent agents are deployed for a particular business function, each message for that business function can be processed by one of the intelligent agents.
[0058] In one implementation, each message may include a corresponding type identifier, and the message's metadata includes a business identifier. After retrieving the target message from the message queue, the communication framework (i.e., the worker thread) first extracts the type identifier and metadata from the target message, and then extracts the business identifier from the metadata. After extracting the type identifier and business identifier, if the type identifier indicates that the target message is a non-broadcast message such as a point-to-point message or an event message, it can be determined that the target message needs to be sent to a specific agent. At this point, the communication framework (i.e., the worker thread) can determine N candidate agents from other agents to process the target message, thereby identifying one or more candidate agents.
[0059] As illustrated above, when each agent registers with the registry center, it can register the service identifier of the service it handles. The registry center can record the service identifier of each agent. During the process of determining candidate agents, the communication framework obtains the service identifier of each agent other than the source agent from the registry center. For each obtained service identifier, if the service identifier is the same as the service identifier extracted from the metadata of the target message, the agent is determined to be a candidate agent; if the service identifier is different from the service identifier extracted from the metadata of the target message, the agent is determined not to be a candidate agent. This process can identify one or more candidate agents.
[0060] After identifying at least one candidate agent, the communication framework can select one from N candidate agents as the target agent. For example, if there is only one candidate agent, that candidate agent can be directly selected as the target agent. If there are multiple candidate agents, when selecting the target agent from among them, the one with the lowest load can be chosen as the candidate agent.
[0061] The workload of an agent can be characterized by the number of messages it is currently processing; the larger the number of messages processed, the greater the agent's workload. The registry can count the number of messages each agent receives and processes in real time. When determining the target agent from multiple candidate agents, the registry can be used to obtain the number of messages each agent is currently processing, and the candidate agent with the smallest number of messages can be selected as the target agent.
[0062] Alternatively, a polling mechanism can be used to select each candidate agent as the target agent in turn. For example, for multiple agents (i.e., multiple candidate agents) corresponding to the same business, the agents can be sorted, and each time a target agent is selected, one that is different from the previously selected agent can be chosen from the multiple candidate agents in turn.
[0063] Alternatively, a target agent can be randomly selected from multiple candidate agents. Specific methods for selecting a target agent from multiple candidate agents may include, but are not limited to, the examples above.
[0064] In this embodiment of the application, for a target message, N candidate intelligent agents are determined according to the message type and service type of the target message. One of the N candidate intelligent agents is selected as the target intelligent agent, and the target message is sent to the target intelligent agent for processing, which can achieve accurate delivery of the target message.
[0065] Optionally, the target agent is determined from N candidate agents, including: For each candidate agent, the selection weight of the candidate agent is determined based on at least one of the candidate agent's current load, response time, and health score; Based on the selection weight of each candidate agent, the target agent is determined from N candidate agents.
[0066] In one approach, when multiple candidate agents are identified, one or more of the current load, response time, and health score of each candidate agent can be comprehensively analyzed to determine the selection weight of each candidate agent. Then, the one with the highest selection weight is selected as the target agent from the N candidate agents.
[0067] For example, when managing each agent, the registry center can count the number of messages that each agent is processing and use the number of messages that the agent is processing as the agent's current load.
[0068] Simultaneously, the average time taken by the agent to process each message over a period of time prior to the current moment can be calculated periodically, and this average time can be used as the agent's response time. For example, this can be calculated every 3 minutes. In each calculation, the time taken by the agent to process each message in the 2 minutes prior to the current moment can be obtained to get multiple times. The average of these multiple times can be calculated to obtain the average time, which can then be used as the response time.
[0069] Simultaneously, the success rate of the agent in processing messages over a period of time prior to the current moment can be calculated periodically, and this success rate can be used as a health score. For example, this can be calculated every 3 minutes. In each calculation, the total number of messages processed by the agent in the 2 minutes prior to the current moment and the total number of times the agent failed to process messages in the 2 minutes prior to the current moment can be determined. The ratio of the total number of failures to the total number of failures yields the success rate, which is then used as the health score.
[0070] The above are merely illustrative examples; the specific calculation methods for current load, response time, and health score may include, but are not limited to, the examples above.
[0071] When there are multiple candidate agents, for each candidate agent, the current load, response time, and health score of each candidate agent at the current moment can be obtained from the registry center. Then, the selection weight of the candidate agent is calculated and determined using the formula shown below.
[0072]
[0073] Where Wi represents the selection weight of the candidate agent, Li represents the current load of the candidate agent, Ri represents the response time of the candidate agent, Hi represents the health score of the candidate agent, α represents the weight coefficient of the current load, β represents the weight coefficient of the response time, and γ represents the weight coefficient of the health score.
[0074] For each candidate agent, after obtaining the current load, response time, and health score, the current load, response time, and health score can be substituted into the formula shown above to calculate the selection weight of the candidate agent, and the target agent with the highest selection weight can be determined from multiple candidate agents.
[0075] As shown by this formula, the greater the current load of a candidate agent, the smaller its selection weight; the longer its response time, the smaller its selection weight; and the higher its health score, the greater its selection weight. When determining the target agent from multiple candidate agents based on the selection weight, the candidate agent with the smaller load, shorter response time, and higher health score can be selected as the target agent.
[0076] In practical applications, the selection weight of candidate agents can also be determined by calculating one or two of the current load, response time, and health score.
[0077] In this embodiment of the application, when there are multiple candidate agents, the target agent is determined from the multiple candidate agents based on one or more of the current load, response time and health score of each candidate agent. The candidate agent with a smaller load, shorter response time and higher health score can be selected as the target agent, so that the target message can be sent to a reliable agent, which can increase the probability that the message is responded to normally.
[0078] Optionally, the method may further include: When the type identifier indicates that the target message is a broadcast message, obtain the health tag of each agent other than the source agent among multiple agents; The agent whose health label indicates health is identified as the target agent.
[0079] In one implementation, after extracting the type identifier from the target message, if If the type identifier indicates that the target message is a broadcast message, then it can be determined that the target message needs to be sent to every agent except the source agent. At this time, the communication framework (i.e., the worker thread) can determine all agents in a healthy state from the other agents besides the source agent and send the target message to each agent in a healthy state.
[0080] For example, the registry center can set a health flag for each agent during the management process. Each agent sends a heartbeat packet to the registry center periodically (e.g., every 30 seconds) during operation. If a heartbeat packet is not sent, it indicates that the agent may be abnormal.
[0081] For each agent, if the registry center does not receive a heartbeat packet from the agent for a preset time period (e.g., 90 seconds), it sets the agent's health flag to a first state, indicating that the agent is in an unhealthy state. Conversely, for each agent, if the registry center receives a heartbeat packet from the agent within a preset time period, it sets the agent's health flag to a second state, indicating that the agent is in a healthy state.
[0082] After determining that the target message is a broadcast message, the worker thread can obtain the health tag of each agent except the source agent from the registry center. Based on each agent's health tag, it identifies each agent with a health tag in the second state from all agents except the source agent; this type of agent is the target agent. Then, the target message is sent to each agent with a health tag in the second state to broadcast the target message to all agents in the healthy state.
[0083] Specifically, when there are 0 agents with the health flag marked as the second state, the target message can be discarded, and a notification can be sent to the source agent, informing the source agent that there is no target agent that can process the target message.
[0084] In this embodiment of the application, when the target message is a broadcast message, the target intelligent agent in a healthy state is determined based on the health tag of each intelligent agent other than the source intelligent agent, and the target message is broadcast to the target intelligent agent in a healthy state. This can avoid sending the target message to unhealthy intelligent agents, thereby reducing unnecessary message sending and improving communication efficiency.
[0085] Optionally, the step of caching the target message in the message queue may include: Extract the priority identifier of the target message from the metadata; Based on the priority identifier of the target message, the target message is cached in the message queue, so that the target message can be retrieved from the message queue in the order of priority of each message cached in the message queue.
[0086] In one implementation, when caching target messages in a message queue, each target message can be stored sequentially based on its priority identifier. Each time a target message is retrieved from the message queue, the highest-priority target message can be retrieved and sent according to its priority order.
[0087] For example, during the preprocessing of the target message, the communication framework can extract the priority identifier of the target message from the target message's metadata, and then store the target message and the corresponding priority identifier in the message queue.
[0088] The priority identifier indicates the priority of the target message; the higher the priority, the more important the target message. For example, for the entire software system, five priorities can be set from high to low, with priority identifiers as follows: "CRITICAL", "HIGH", "NORMAL", "LOW", and "IDLE". For each message cached in the message queue, the higher the priority, the earlier it will be retrieved from the message queue and sent by the communication framework.
[0089] When a message queue stores multiple messages, their priority indicators can be any of the following: "critical," "high," "normal," "low," and "idle," as shown in the examples above. When retrieving a message from the message queue, if one or more messages with the priority indicator "critical" exist, those messages are retrieved first. If no messages with the priority indicator "critical" exist, one or more messages with the priority indicator "high" are retrieved first. If neither "high" nor "critical" messages exist, one or more messages with the priority indicator "normal" are retrieved first. This process continues, ensuring that the message with the highest priority is retrieved each time a message is retrieved from the message queue.
[0090] During message sending, when the highest priority message is retrieved from the message queue, it is sent directly to the target agent. When multiple highest priority messages are retrieved from the message queue, each retrieved message can be sent sequentially.
[0091] It is understandable that once a target message is cached in the message queue, it can only be retrieved from the message queue by the communication framework after other messages with higher priority in the message queue have been extracted and sent.
[0092] In this embodiment of the application, the priority identifier of the target message is extracted from the metadata, and the target message is cached in the message queue based on the priority identifier of the target message. The target message can be extracted from the message queue and sent according to the priority order of each message cached in the message queue. In this way, the message with higher importance can be sent first according to the importance of each message in the message queue, thereby ensuring that the message with higher importance is processed first.
[0093] Optionally, a target message is sent to the target agent, including: Determine whether the cache duration of the target message in the message queue has reached the maximum cache duration limit; If the cache duration limit has not been reached, the target message is sent to the target agent.
[0094] In one implementation, during the generation of the target message, the source agent can set a maximum caching duration for the target message and add this maximum caching duration to the metadata. After retrieving the target message from the message queue, the maximum caching duration can be extracted from the target message's metadata. Simultaneously, the interval between the time the target message was stored in the message queue and the time it was retrieved from the message queue is determined; this interval is the caching duration of the target message in the message queue. Then, the caching duration is compared with the obtained maximum caching duration. If the caching duration is less than the maximum caching duration, the target message is sent to the target agent.
[0095] Conversely, if the cache duration is greater than or equal to the cache duration limit, the target message is discarded and not sent to the target agent. After discarding the target message, a notification can be sent to the source agent to inform it that the target message transmission failed, allowing the source agent to regenerate the target message or take other measures.
[0096] In practical applications, when the cache duration of a target message in the message queue reaches the cache duration limit, it indicates that the target message has lost its timeliness. At this time, discarding the target message can prevent the expired target message from affecting the system.
[0097] In this embodiment of the application, before sending the target message to the target agent, it is determined whether the cache duration of the target message in the message queue has reached the cache duration limit. If the cache duration limit has not been reached, the target message is sent to the target agent. If the cache duration limit has been reached, the target message is discarded, which can ensure the timeliness of the target message.
[0098] Optionally, after sending the target message to the target agent, the method may further include: If it is determined that the target message failed to be sent, extract the number of times the target message was sent and the maximum number of times it can be sent from the metadata; If the number of times to send has not reached the maximum number of times to send, update the number of times to send and re-cachise the target message to the message queue.
[0099] In one implementation, during the generation of the target message, the source agent can set an initial value for the number of times the target message will be sent, typically set to 1. Simultaneously, a maximum number of times the target message can be sent (i.e., a maximum sending count) can be set, which is greater than 1, for example, 2, 3, 4, or 5. Before sending the target message to the communication bus, the number of times the target message will be sent and the maximum sending count can be added to the metadata.
[0100] After retrieving the target message from the message queue and sending it to the target agent, the communication framework determines that the target message was successfully sent if it receives a response message from the target agent within the expected response time. No further processing is performed on the target message at this point. Each agent, upon receiving a message, sends a response message to the communication framework to notify it that the message was successfully received.
[0101] Conversely, after retrieving the target message from the message queue and sending it to the target agent, if the communication framework does not receive a response message from the target agent within the expected response time, it determines that the target message transmission has failed. Upon determining that the target message transmission has failed, it extracts the transmission count and maximum transmission count from the target message's metadata. Comparing the transmission count and the maximum transmission count, if the transmission count is less than the maximum transmission count, the target message is re-stored in the message queue, and the transmission count is incremented by 1. If the transmission count is greater than or equal to the maximum transmission count, it is determined that the target message could not be successfully transmitted. In this case, a notification message can be sent to the source agent to inform it that the target message could not be successfully transmitted, allowing the source agent to regenerate the target message or take other measures.
[0102] Once the target message is re-stored in the message queue, and then retrieved from the queue and sent to the target agent, the communication framework determines that the message was successfully sent if it receives a response message from the target agent within the expected response time. No further processing is performed on the target message. If no response message is received within the expected response time, the message transmission is considered to have failed. Similarly, upon determining that the message transmission failed, the sending count and maximum sending count are extracted from the target message's metadata. These are compared; if the sending count is less than the maximum, the target message is re-stored in the message queue, and the sending count is incremented. If the sending count is greater than or equal to the maximum, the message transmission is considered unsuccessful. In this case, a notification is sent to the source agent, informing it that the message transmission failed and prompting the source agent to regenerate the target message or take other measures.
[0103] In this application, a maximum number of message sending attempts is set. When sending a target message to a target agent fails, the message can be sent multiple times consecutively, thereby improving the success rate of message delivery. Simultaneously, stopping message sending when the maximum number of attempts is reached reduces unnecessary message sending and thus minimizes resource consumption.
[0104] Optionally, the target message is cached in a message queue, including: Upon receiving a target message, extract the expiration time of the target message from the metadata; If the target message is determined not to have expired based on the expiration time, the target message is cached in the message queue.
[0105] The expiration time can be understood as the validity period of the target message. When the time it takes for the communication framework to receive the target message exceeds the expiration time, it indicates that the target message has expired because it has taken a long time to be transmitted from the source agent to the communication framework.
[0106] In one implementation, when the source agent generates the target message, it can set an expiration time for the target message and add the expiration time to the target message's metadata. Correspondingly, after receiving the target message sent by the source agent, the communication framework first extracts the expiration time from the target message's metadata, then compares the system's current time with the expiration time. If the expiration time is after the current time, it determines that the target message is valid and has not expired. At this point, the target message can be cached in the message queue.
[0107] Conversely, if the expiration time is before the current time, the target message is determined to be invalid and expired. In this case, the target message can be discarded, and a notification message can be sent to the source agent to inform the source agent that the target message has expired beyond the expiration time, so that the source agent can regenerate the target message or take other measures.
[0108] In practical applications, when there are many messages transmitted on the communication bus, it may take a long time for the source agent to send the target message to the communication framework. If this time is too long, the target message may become invalid and lose its function.
[0109] In this embodiment, an expiration time is set for the target message. After receiving the target message, its expiration time is obtained. If the expiration time determines that the target message has not expired, it is cached in a message queue for transmission to the target agent. If the expiration time determines that the target message has expired, it is discarded. This ensures the timeliness of the target message, reduces unnecessary message transmission, and improves communication efficiency.
[0110] See Figure 3, Figure 3 This is a flowchart illustrating an intelligent agent communication method provided in an embodiment of this application. Figure 3 As shown, the communication framework includes a message bus, a middleware chain (comprising several middleware components), a message queue, worker threads, and a registry center. When Agent 1 (the source agent) sends a target message, it sends the target message to the message bus. Multiple middleware components in the middleware chain preprocess the target message sent to the message bus, extracting the expiration time from the target message's metadata. If the expiration time indicates the target message is not expired, it is cached in the message queue. If the expiration time indicates the target message has expired, it is discarded, and a notification is sent to Agent 1 informing it that the target message has expired. During the process of caching the target message in the message queue, a priority identifier can be extracted from the target message's metadata, and this priority identifier, along with the target message itself, is stored in the message queue.
[0111] Specifically, for target messages received by the message bus, the log middleware can record the message sender, receiver, business data within the message, and other information. The monitoring middleware can statistically analyze the number of messages transmitted on the message bus, the average latency, and the error rate. The rate middleware can control the message data output from the message bus to ensure the reliable operation of the communication framework.
[0112] Meanwhile, worker threads can periodically retrieve target messages from the message queue, prioritizing the highest-priority target message each time. After retrieving a target message, a type identifier is obtained from its metadata. If the type identifier indicates the target message is a non-broadcast message, N candidate agents are selected from the other agents, and the target agent is chosen from these N candidates. The target message is then sent to the target agent. If the type identifier indicates the target message is a broadcast message, a health flag is obtained from the registry center for each agent other than the source agent. Agents with healthy health flags are identified as the target agent, and the target message is sent to them. After sending the message to the target agent and receiving a response message from the target agent, the worker thread sends a response message to the target agent.
[0113] In this process, after the worker thread retrieves the target message from the message queue, it determines whether the cache duration of the target message in the message queue has reached the cache duration limit. If the cache duration limit has not been reached, the target message is sent to the target agent. If the cache duration limit has been reached, the target message is discarded and a notification message is sent to the source agent.
[0114] Furthermore, during the process of sending the target message, if it is determined that the target message will fail to be sent, the number of times the target message has been sent and the maximum number of times it can be sent are extracted from the metadata. If the number of times the sending count has not reached the maximum number of times it can be sent, the sending count is updated and the target message is cached again in the message queue. If the number of times the sending count has reached the maximum number of times it can be sent, the sending of the target message is stopped.
[0115] The above text combined Figures 1 to 3 The intelligent agent communication method provided in the embodiments of this application is described in detail below; the following will be combined with Figure 4 and Figure 5 The apparatus embodiments of this application are described in detail below. It should be understood that the apparatus in the embodiments of this application can perform the various methods described in the foregoing embodiments of this application, that is, the specific working processes of the various products described below can be referred to the corresponding processes in the foregoing method embodiments.
[0116] See Figure 4 , Figure 4 This is a schematic diagram of the structure of an intelligent agent communication device provided in an embodiment of this application. Figure 4 As shown, the intelligent agent communication device 400 may include: The caching module 401 is used to cache the target message into a message queue when it receives a target message sent by a source agent among multiple agents; Extraction module 402 is used to extract the target message from the message queue; The determining module 403 is used to determine, based on the extracted target message, a target intelligent agent from other intelligent agents for processing the target message, wherein the other intelligent agents are intelligent agents other than the source intelligent agent among the plurality of intelligent agents; The sending module 404 is used to send the target message to the target intelligent agent.
[0117] Optionally, the determining module 403 is specifically used to extract the type identifier and service identifier of the target message from the target message; when the type identifier indicates that the message type of the target message is a non-broadcast message, N candidate agents are determined from the other agents, the N candidate agents include agents for processing messages corresponding to the service identifier, and N is an integer greater than 0; the target agent is determined from the N candidate agents.
[0118] Optionally, the determining module 403 is specifically configured to, for each candidate agent, determine the selection weight of the candidate agent based on at least one of the candidate agent's current load, response time, and health score; and determine the target agent from the N candidate agents based on the selection weight of each candidate agent.
[0119] Optionally, the determining module 403 is further configured to, when the type identifier indicates that the message type of the target message is a broadcast message, obtain the health tag of each of the plurality of agents other than the source agent; and determine the agent whose health tag indicates that it is healthy as the target agent.
[0120] Optionally, the target message includes metadata, and the caching module is specifically used to extract the priority identifier of the target message from the metadata; based on the priority identifier of the target message, the target message is cached in the message queue, so as to extract the target message from the message queue according to the priority order of each message cached in the message queue.
[0121] Optionally, the sending module 404 is specifically used to determine whether the cache duration of the target message in the message queue has reached the cache duration limit; if the cache duration limit has not been reached, the target message is sent to the target agent.
[0122] Optionally, after sending the target message to the target agent, the caching module 401 is further configured to extract the number of times the target message was sent and the upper limit of the number of times the target message was sent from the metadata if it is determined that the target message failed to be sent; and when the number of times the message was sent has not reached the upper limit of the number of times the message was sent, update the number of times the message was sent and re-cach the target message in the message queue.
[0123] Optionally, the caching module 401 is specifically configured to extract the expiration time of the target message from the metadata when the target message is received; and if it is determined based on the expiration time that the target message has not expired, cache the target message in the message queue.
[0124] See Figure 5 , Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. For example... Figure 5 As shown, the electronic device 500 is, for example, a server, including: a memory 501 and a processor 502, wherein the memory 501 stores executable program code 5011, and the processor 502 is used to call and execute the executable program code 5011 to perform an intelligent agent communication method.
[0125] Furthermore, embodiments of this application also protect an intelligent agent communication device, which may include a memory and a processor, wherein the memory stores executable program code, and the processor is used to call and execute the executable program code to execute an intelligent agent communication method provided in embodiments of this application.
[0126] This embodiment can divide the device into functional modules according to the above method example. For example, each module can correspond to a separate functional module, or two or more functions can be integrated into one output module. The integrated module can be implemented in hardware. It should be noted that the module division in this embodiment is illustrative and only represents one logical functional division. In actual implementation, there may be other division methods.
[0127] When the functional modules are divided according to their respective functions, the device may also include a determining module, a replacing module, and a controlling module. It should be noted that all relevant content regarding the steps involved in the above method embodiments can be referenced to the functional descriptions of the corresponding functional modules, and will not be repeated here.
[0128] It should be understood that the device provided in this embodiment is used to execute the above-described intelligent agent communication method, and therefore can achieve the same effect as the above-described implementation method.
[0129] When using integrated units, the device may include a determining module and a control module. Specifically, when the device is applied to an electronic device, the output module can be used to control and manage the operation of the electronic device. The storage module can be used to support the execution of relevant program code by the electronic device.
[0130] The output module can be a processor or a body setup module, which can implement or execute various exemplary logic blocks, modules, and circuits shown in conjunction with the disclosure of this application. The processor can also be a combination of functions that implement computing capabilities, such as a combination of one or more microprocessors, a combination of digital signal processing (DSP) and microprocessors, etc., and the storage module can be a memory.
[0131] This embodiment also provides a readable storage medium storing executable program code. When the executable program code is run on an electronic device, the electronic device executes the above-described related method steps to implement the intelligent agent communication method provided in the above embodiment.
[0132] This embodiment also provides a program product that, when run on an electronic device, causes the electronic device to perform the aforementioned related steps to realize the intelligent agent communication method provided in the above embodiment.
[0133] In this embodiment, the device, readable storage medium, program product, or chip are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can be referred to the beneficial effects of the corresponding methods provided above, and will not be repeated here.
[0134] Through the above description of the embodiments, those skilled in the art will understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0135] In the embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another device, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0136] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A method for intelligent agent communication, characterized in that, The method includes: When a target message is received from a source agent among multiple agents, the target message is cached in a message queue; Extract the target message from the message queue; Based on the extracted target message, a target intelligent agent for processing the target message is determined from other intelligent agents, wherein the other intelligent agents are intelligent agents other than the source intelligent agent among the plurality of intelligent agents; Send the target message to the target agent.
2. The method as described in claim 1, characterized in that, The step of determining the target intelligent agent from other intelligent agents for processing the target message includes: Extract the type identifier and service identifier of the target message from the target message; When the type identifier indicates that the message type of the target message is a non-broadcast message, N candidate agents are determined from the other agents. The N candidate agents include agents for processing the message corresponding to the service identifier, where N is an integer greater than 0. The target agent is determined from the N candidate agents.
3. The method as described in claim 2, characterized in that, The step of determining the target agent from the N candidate agents includes: For each candidate agent, the selection weight of the candidate agent is determined based on at least one of the candidate agent's current load, response time, and health score; The target agent is determined from the N candidate agents based on the selection weight of each candidate agent.
4. The method as described in claim 2, characterized in that, The method further includes: When the type identifier indicates that the message type of the target message is a broadcast message, obtain the health tag of each of the plurality of agents except the source agent; The agent whose health label indicates health is identified as the target agent.
5. The method as described in claim 1, characterized in that, The target message includes metadata, and caching the target message in a message queue includes: Extract the priority identifier of the target message from the metadata; Based on the priority identifier of the target message, the target message is cached in the message queue so that the target message can be extracted from the message queue according to the priority order of each message cached in the message queue.
6. The method as described in claim 5, characterized in that, Sending the target message to the target agent includes: Determine whether the cache duration of the target message in the message queue has reached the maximum cache duration limit; If the cache duration limit is not reached, a target message is sent to the target agent.
7. The method as described in claim 5, characterized in that, After sending the target message to the target agent, the method further includes: If it is determined that the target message failed to be sent, the number of times the target message was sent and the maximum number of times it could be sent are extracted from the metadata; If the number of times to send the message has not reached the upper limit, update the number of times to send the message and re-cachise the target message into the message queue.
8. The method as described in claim 5, characterized in that, The step of caching the target message in the message queue includes: Upon receiving the target message, the expiration time of the target message is extracted from the metadata; If it is determined that the target message has not expired based on the expiration time, the target message is cached in the message queue.
9. A readable storage medium, characterized in that, The readable storage medium stores executable program code that, when run on an electronic device, causes the electronic device to perform the method as described in any one of claims 1 to 8.
10. An electronic device, characterized in that, The electronic device includes: Memory, used to store executable program code; A processor for calling and running the executable program code from the memory, causing the electronic device to perform the method as described in any one of claims 1 to 8.