A NPC interaction optimization method based on large language model
By obtaining the NPC's future action sequence and perception experience, and using a large language model to generate dialogue sentences, it solves the problem in the existing technology that NPC cannot communicate remotely and chat with multiple groups, and realizes the simulation of NPC remote communication and multiple group chat scenarios. Enhanced the authenticity of interaction logic.
Patent Information
- Application Number
- CN202410844808.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-27
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2044-06-27
AI Technical Summary
Existing technology cannot fully simulate the minimum time unit of human behavior agents in interaction and multi-person group chat scenarios, resulting in NPCs being unable to communicate remotely and actively initiate conversations.
By obtaining the NPC's future action sequence and perception experience, using a large language model to generate dialogue sentences, and controlling the NPC's movement and dialogue in the map environment, remote/short-range dialogue and multi-person dialogue are realized.
It overcomes the problem of NPC path teleportation, realizes remote communication between NPCs and simulates multi-group chat scenarios, and enhances the authenticity of NPC interaction logic.
Smart Images

Figure CN118384503B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computer data processing, and in particular to an NPC interaction optimization method based on a large language model. Background Art
[0002] At present, the simulation of human behavior through large language models has great practical significance and application prospects. For example, interactive human behavior agents can appear in open world games as NPCs (non-player characters), bringing players more changes and a sense of immersion close to reality; these human behavior agents can also be used to conduct some psychological and sociological experiments that cannot be conducted on humans due to various reasons such as ethics; at the same time, interactive human behavior agents will also become the basis of general artificial intelligence. Therefore, how to use large language models to generate human behavior agents that can be used for interaction, and how to make these human behavior agents evolve in interaction, has become a topic worth exploring.
[0003] Stanford University's paper "Generative Agents: Interactive Simulacra of Human Behavior", in which researchers introduced generative agents into an interactive sandbox environment (such as a town). By initializing the character models, environmental variables and time dimensions in the town, these agents can make extensive inferences about themselves, other agents and the environment, act when appropriate, react or replan. In order to make the agent respond to events like a real person, the researchers used a large language model to store a framework. This framework consists of three main parts: memory, reflection and planning. The memory module records a comprehensive list of the agent's experience in natural language, combining relevance, recency and importance to show the required records and provide information for the agent's timely behavior. The reflection module synthesizes memory into reasoning that gradually improves over time, enabling the agent to reflect on itself and others when guiding its behavior. The planning module transforms these summaries into high-level action plans combined with the current environment, and then recursively transforms them into detailed behaviors and reactions. Finally, in the test part, the agent's performance in role-playing, memory, planning, reflection and other aspects can be evaluated.
[0004] In the simulation environment given in this paper, the map is stored in the form of a two-dimensional matrix. At the same time, in order to reduce the complexity of the model, it is impossible to fully simulate the minimum time unit in real life. The actions of the NPC are represented by the coordinate transformation in the two-dimensional matrix within each time unit. The NPC always teleports along its own path after making a plan, and will only try to initiate communication when it happens to appear in the same space at the same time as another NPC. This makes it impossible for the NPCs in the simulation scene to communicate remotely or to actively initiate a conversation. It is impossible to simulate the way and frequency of people communicating in real life. In the simulation environment given in this paper, only the communication method between two people is defined, and there is no definition of how each NPC expresses his or her own opinions when multiple people are present at the same time. This means that even if multiple NPCs are present at the same time, the NPCs in the simulation scene will only initiate a conversation with one of them, and it is impossible to simulate the scene of multi-person group chat in real life.
[0005] Therefore, a solution is urgently needed. Summary of the invention
[0006] One of the purposes of the present invention is to provide an NPC interaction optimization method based on a large language model, comprising:
[0007] Get the future action sequence of the NPC in the map environment;
[0008] Based on the future action sequence, determine the action guide for the smallest time unit of the NPC's current real life;
[0009] Get the NPC's perception experience in the map environment;
[0010] Based on the large language model, determine whether the action guidance should be executed according to the action guidance and perception experience;
[0011] When executing, the NPC is moved accordingly in the map environment based on the action instructions;
[0012] When NPCs initiate a long-distance / short-distance conversation, based on the large language model, the conversation sentences are generated according to the perception experience of the NPC initiating the long-distance / short-distance conversation;
[0013] Based on the dialogue statements, the NPCs initiating the long-range / short-range dialogue are controlled to conduct corresponding dialogues.
[0014] Optionally, the determining whether to execute the action guide based on the large language model according to the action guide and the perception experience includes:
[0015] Input action instructions and perception experiences into the large language model to obtain the first return result;
[0016] When the first returned result is execution, it is determined that the action guide is to be executed; otherwise, it is determined that the action guide is not to be executed.
[0017] Optionally, the generating of dialogue sentences based on the large language model and according to the perception experience of the NPC initiating the long-distance / short-distance dialogue includes:
[0018] Obtain the dialogue evaluation indicators between NPCs that initiate long-range / short-range dialogues;
[0019] Input the dialogue evaluation index into the large language model to obtain a second return result;
[0020] When the second return result is that the conversation is allowed, the perception experience of the NPC initiating the long-range / short-range conversation is input into the large language model to obtain a third return result;
[0021] The third returned result is used as the dialogue statement.
[0022] Optionally, the dialogue evaluation index includes: the last call time and familiarity of the NPC initiating the long-distance / short-distance dialogue.
[0023] Optionally, the action instructions include: action type, start time and end time;
[0024] The time difference between the start time and the end time is the minimum time unit.
[0025] The specific steps for initiating a long-range / short-range conversation between NPCs are as follows:
[0026] Get the NPC's simulated dialogue plan for the day;
[0027] When the simulated dialogue plan includes a dialogue simulation project, determining the dialogue partner based on the dialogue simulation project;
[0028] Identify other NPCs who are the conversation targets from the map environment;
[0029] Determine whether the current NPC status of the NPC and other NPCs are both idle;
[0030] When all are in idle state, determine the position distance between the NPC and other NPCs in the map environment;
[0031] When the location distance is greater than or equal to the distance threshold, a remote conversation is initiated between NPCs;
[0032] Otherwise, a short-range conversation is initiated between NPCs.
[0033] Optionally, the NPC interaction optimization method based on a large language model also includes:
[0034] Real-time recording of NPC's perception experience in the map environment.
[0035] Optionally, the large language model includes: Chat-GPT model.
[0036] The present invention has achieved the following beneficial effects:
[0037] Determine the NPC's current action guide for the smallest time unit. When the action guide is determined to be executable based on the big language, the NPC is controlled to move accordingly, overcoming the problem of NPC path teleportation caused by the inability to fully simulate the smallest time unit in real life in the existing technology. Secondly, NPCs in the map environment can communicate remotely, and NPCs can actively initiate remote / short-range conversations on their own. The dialogue sentences between NPCs that are conversing based on the big language are enriched, realizing the dialogue simulation in which multiple NPCs give their own opinions, truly simulating the multi-person group chat scene in real life.
[0038] Other features and advantages of the present invention will be described in the following description, and partly become apparent from the description, or understood by practicing the present invention. The purpose and other advantages of the present invention can be realized and obtained by the structures particularly pointed out in the written description, claims, and drawings.
[0039] The technical solution of the present invention is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings:
[0041] Figure 1 It is a flow chart of the NPC interaction optimization method based on the large language model in an embodiment of the present invention;
[0042] Figure 2 A schematic diagram of a process for implementing an NPC to actively initiate communication in an embodiment of the present invention;
[0043] Figure 3 A schematic diagram of a process for implementing remote communication between NPCs in an embodiment of the present invention;
[0044] Figure 4 The figure is a flow chart of realizing multi-person dialogue among NPCs in an embodiment of the present invention. DETAILED DESCRIPTION
[0045] The preferred embodiments of the present invention are described below in conjunction with the accompanying drawings. It should be understood that the preferred embodiments described herein are only used to illustrate and explain the present invention, and are not used to limit the present invention.
[0046] The embodiment of the present invention provides an NPC interaction optimization method based on a large language model, such as Figure 1 As shown, in one implementation, it includes:
[0047] S1. Obtain the future action sequence of the NPC in the map environment;
[0048] S2. Based on the future action sequence, determine the action guide for the minimum time unit of the NPC's current real life;
[0049] S3, obtain the NPC's perception experience in the map environment;
[0050] S4, based on the large language model, according to the action guidance and the perceived experience, determine whether the action guidance should be executed;
[0051] S5. When executing, based on the action instructions, the NPC is moved accordingly in the map environment;
[0052] S6. When a long-distance / short-distance conversation is initiated between NPCs, a conversation sentence is generated based on the large language model and the perception experience of the NPC initiating the long-distance / short-distance conversation;
[0053] S7. Based on the dialogue statements, control the NPCs that initiate the long-range / short-range dialogue to conduct corresponding dialogues.
[0054] The simulated map environment in the present invention is constructed using the Phaser web game development framework, including visualization information including NPCs, environmental maps, and collision maps; the map environment enables information in a virtual map to be used to generate NPCs through a server, and enables NPCs to move and affect the environment; the server maintains a JSON data structure containing information about each NPC in the virtual world, including their current location, descriptions of their current actions, and objects they are interacting with; in each time unit, the server parses any changed JSON data from the NPC, moves the NPC to their new location, and updates the status of any object the NPC is interacting with; the server also stores all other NPCs or environmental objects within the NPC's preset visual range into the NPC's memory in order to respond appropriately; the NPC continuously outputs behavior over time and then updates the JSON data, and repeats the process in each time unit.
[0055] The Phaser web game development framework can also describe the NPC's future action sequence, that is, simulate what the NPC should do in the map environment in the future. The future action sequence contains multiple action instructions in the smallest time unit sorted in order of action. The NPC's current action instruction in the smallest time unit is the action instruction in the last smallest time unit that is about to be executed. The smallest time unit is determined by the Phaser web game development framework and must meet the action requirement that the NPC will not teleport when moving. It can be set in advance by technical personnel according to actual needs.
[0056] NPCs will perceive the environment in a map environment and form perceptual experiences, such as experienced map scenes, conversations with other NPCs, etc. The large language model can determine whether to execute action instructions based on action instructions and perceptual experiences. For example, other NPCs guide the NPC to go to location A in a conversation, but the action instructions are also to go to location A, then the action instructions can be executed. When it is not executed, the NPC is moved accordingly in the map environment based on the action instructions. NPCs can actively initiate long-range / short-range conversations. The large language model can also generate dialogue sentences for them to simulate conversations based on the perceptual experience of the NPC who initiated the long-range / short-range conversation. For example, the perceptual experience of the NPC who initiated the long-range / short-range conversation is that they have been to location B together, so their dialogue sentences are generated to describe location B.
[0057] The present application determines the NPC's current action guide for the smallest time unit. When the action guide is determined to be executable based on the big language, the NPC is controlled to move accordingly, overcoming the problem of NPC path teleportation caused by the inability to fully simulate the smallest time unit in real life in the prior art. Secondly, NPCs in the map environment can communicate remotely, and NPCs can actively initiate remote / short-range conversations on their own. The dialogue sentences between NPCs that are conversing based on the big language are enriched, realizing the dialogue simulation in which multiple NPCs give their own opinions, truly simulating the multi-person group chat scene in real life.
[0058] The following examples illustrate how NPCs can have long-range and short-range conversations:
[0059] like Figure 2 As shown, when the NPC actively initiates communication, at the beginning of a new day in the simulated world, the NPC calls the planning module to independently make a plan for the day and recursively decomposes it into action instructions for each minimum time unit. The NPC can generate a plan for initiating a conversation through the planning module and break it down into specific time units. If the NPC's plan includes initiating a conversation with other NPCs, the active communication initiation method will be run at the beginning of the time corresponding to this plan; if there is no plan to initiate a conversation, the simulation of daily life will continue.
[0060] When the active communication method is run, NPC1 obtains the location of its communication target, that is, another NPC (NPC2), through the map module by calling the location query method, and determines whether NPC2 is idle. If the target location is successfully obtained and NPC2 is idle, NPC1 calls the search method and moves to the target location through the path finding mechanism. If the target location cannot be obtained or NPC2 is busy, NPC1 will temporarily cancel the conversation through the reaction module, update its own plan, and continue the simulation of daily life.
[0061] After reaching the target location, NPC1 will obtain the specific location of NPC2 through the perception mechanism, and comprehensively judge the various indicators between the two NPCs (such as the time since the last conversation, the degree of familiarity between the two people, etc.) through the large language model to decide whether to initiate a conversation. If a conversation can be initiated, the memory module will be used to obtain the summary memory of the two NPCs about each other, and the dialogue module will be called to generate sentences, and this process will be repeated to obtain a conversation.
[0062] like Figure 3 As shown, when remote communication between NPCs is realized, the NPC can generate a plan for initiating remote communication through the planning module and subdivide it into specific time units. If the NPC's plan includes initiating a remote communication with other NPCs, it will initiate remote communication with another NPC at the beginning of the time corresponding to this plan; if there is no plan to initiate remote communication, the simulation of daily life will continue.
[0063] When initiating remote communication, NPC1 obtains the status information of its communication target, that is, another NPC (NPC2), through the map module. If NPC2 is idle, NPC1 calls the remote communication method and generates an event that is perceived by NPC2 through the reaction mechanism. NPC2 decides whether to change the original plan and accept this remote communication. If accepted, the memory module is used to obtain the summary memory of the two NPCs about each other, and the dialogue module is called to generate sentences. This process is repeated to obtain a dialogue. If rejected, this event will be perceived by both parties through the reaction module, and the conversation will be temporarily canceled. At the same time, their own plans will be updated and the simulation of daily life will continue.
[0064] like Figure 4 As shown, when implementing multi-person dialogues between NPCs, when an NPC initiates a dialogue, if there are multiple other NPCs in the scene, the dialogue module will use the perception mechanism to find all NPCs in the scene that may participate in the dialogue, and comprehensively consider the relationship network of all NPCs present and the plans of each NPC to decide which NPCs can join the dialogue.
[0065] If the final result is a two-person dialogue, enter the two-person dialogue module.
[0066] If a multi-person dialogue is generated, a multi-person dialogue list is first initialized through the dialogue module, and a score list used to indicate the priority of NPC speeches is maintained, and the order of speeches is determined by the score. The score list is accessed every time a statement is generated, and the speaker with the highest score is the speaker of the current round, and the score is reset to zero after speaking. The score will comprehensively consider the time since the NPC's last speech, the repetitiveness of the preset speech content and context, the familiarity with the previous speaker, etc., and will change with the change of rounds.
[0067] NPCs can decide whether to continue the conversation. At the end of a round of conversation, the content of the conversation will be stored in the memory stream and perceived as an event by all NPCs present, asking them whether they need to update their plans. After re-integrating the relationship network of all NPCs present and the plans of each NPC, it is decided which NPCs can have a conversation.
[0068] In one embodiment, the determining whether to execute the action guideline based on the large language model according to the action guideline and the perceived experience includes:
[0069] Input action instructions and perception experiences into the large language model to obtain the first return result;
[0070] When the first returned result is execution, it is determined that the action guide is to be executed; otherwise, it is determined that the action guide is not to be executed.
[0071] The large language model is trained in advance so that the large language model can return a first return result for determining whether the action guideline is executed based on the action guideline and the perception experience.
[0072] In one embodiment, the generating of dialogue sentences based on the large language model and the perceived experience of the NPC initiating the remote / near dialogue includes:
[0073] Obtain the dialogue evaluation indicators between NPCs that initiate long-range / short-range dialogues;
[0074] Input the dialogue evaluation index into the large language model to obtain a second return result;
[0075] When the second return result is that the conversation is allowed, the perception experience of the NPC initiating the long-range / short-range conversation is input into the large language model to obtain a third return result;
[0076] The third returned result is used as the dialogue statement.
[0077] The dialogue evaluation indicators include: the last call time and familiarity of the NPC who initiated the long-distance / short-distance dialogue. Familiarity refers to the familiarity between the NPC and the speaker of the current round. The higher the familiarity, the higher the score. This indicator is used to represent the situation in real life where people are more willing to take over the conversation after a familiar friend speaks.
[0078] The large language model is trained in advance so that the large language model can determine the second return result of whether the dialogue between NPCs is allowed based on the dialogue evaluation index, and can determine the third return result of the dialogue sentence based on the perception experience of the NPC initiating the long-range / short-range dialogue.
[0079] Conversation evaluation indicators can also be relevance and timeliness.
[0080] Correlation is used to indicate the degree of repetition between the speech that the NPC is about to make and the dialogue that has already appeared in the previous text. The higher the repetition, the lower the score. This indicator is used to indicate that in real life, people generally agree with or further explain the same opinions as themselves, rather than simply repeating them.
[0081] Timeliness indicates the time since the last speech of an NPC. It is used to handle the status of NPCs who are in the conversation but have never had the opportunity to speak. The higher the timeliness, the higher the score. This indicator can prevent the situation where some people with low speaking priority never have the opportunity to express their opinions.
[0082] Before each speech, the large language model is used to obtain the scores of all NPCs on these three indicators, and then the scores of each indicator are normalized and mapped to the [0 - 1] interval for subsequent calculations. Since the values are relatively concentrated under the same evaluation criteria, the Min-Max normalization method is applicable to this scenario, and the conversion function is as follows:
[0083]
[0084] Among them, x new is the converted value, x max is the maximum value of the sample data, x min It is the minimum value of the sample data, that is, the maximum and minimum values of the score in a certain indicator.
[0085] After obtaining the normalized scores, the final score of each NPC is calculated by weighted average. The weighting method is as follows:
[0086]
[0087] in Indicates the weight of each score. In the implementation, different parameters are applied according to different simulation scenarios. Familiarity, relevance, and recency are the scores of familiarity, relevance, and timeliness, respectively. The scores of each indicator are multiplied by the weight and then added to get the final priority score of the NPC. Finally, the calculated scores are stored in the score list according to the scores. The speaker with the highest score is the speaker of the current round.
[0088] In real life, in addition to conversations between two people, there are also group conversations between multiple people. Compared with two-person conversations, group chats transmit information faster and contain more information. In order to better simulate this more important type of communication, the present invention adds an algorithm suitable for multi-person conversations to maintain speech priority. By comprehensively considering the time since the NPC’s last speech, the repeatability of the preset speech content and context, the familiarity with the previous NPC who spoke, and other factors, the present invention changes the speaking order of each NPC with an algorithm that is closer to reality, thereby better simulating the scenes that may occur in multi-person communication in real life.
[0089] In one embodiment, the action instructions include: action type, start time, and end time;
[0090] The time difference between the start time and the end time is the minimum time unit.
[0091] The action type is the movement type of the NPC, such as: going to the next destination, etc.; the start time and end time are the start and end times of the corresponding action for which the NPC provides action guidance.
[0092] In one embodiment, the specific steps of initiating a long-distance / short-distance conversation between NPCs are as follows:
[0093] Get the NPC's simulated dialogue plan for the day;
[0094] When the simulated dialogue plan includes a dialogue simulation project, determining the dialogue partner based on the dialogue simulation project;
[0095] Identify other NPCs who are the conversation targets from the map environment;
[0096] Determine whether the current NPC status of the NPC and other NPCs are both idle;
[0097] When all are in idle state, determine the position distance between the NPC and other NPCs in the map environment;
[0098] When the location distance is greater than or equal to the distance threshold, a remote conversation is initiated between NPCs;
[0099] Otherwise, a short-range conversation is initiated between NPCs.
[0100] The system will assign a simulated dialogue plan to the NPC on that day, that is, the plan for the NPC to have a dialogue on that day. When there is a dialogue simulation item in the simulated dialogue plan, it means that the NPC needs to have a dialogue on that day and determine the dialogue partner, that is, other NPCs. When the NPC and other NPCs are both idle, determine the position distance. When the position distance is greater than or equal to the distance, it means that the two are far away, and a long-distance dialogue is initiated between the NPCs. Otherwise, it means that the two are close, and a short-range dialogue is initiated between the NPCs. Short-range dialogue refers to a dialogue between NPCs in close proximity.
[0101] In one embodiment, the NPC interaction optimization method based on a large language model is characterized by further comprising:
[0102] Real-time recording of NPC's perception experience in the map environment.
[0103] In one embodiment, the large language model includes: a Chat-GPT model.
[0104] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.
Claims
1. A NPC interaction optimization method based on a large language model, characterized in that: include: Get the future action sequence of the NPC in the map environment; Based on the future action sequence, determine the action guide for the smallest time unit of the NPC's current real life; Get the NPC's perception experience in the map environment; Based on the large language model, determine whether the action guidance should be executed according to the action guidance and perception experience; When executing, the NPC is moved accordingly in the map environment based on the action instructions; When NPCs initiate a long-distance / short-distance conversation, based on the large language model, the conversation sentences are generated according to the perception experience of the NPC initiating the long-distance / short-distance conversation; Based on the dialogue statements, control the NPCs that initiate the long-range / short-range dialogue to conduct corresponding dialogues; The method generates dialogue sentences based on the large language model according to the perception experience of the NPC initiating the long-distance / short-distance dialogue, including: Obtain the dialogue evaluation indicators between NPCs that initiate long-range / short-range dialogues; Input the dialogue evaluation index into the large language model to obtain a second return result; When the second return result is that the conversation is allowed, the perception experience of the NPC initiating the long-range / short-range conversation is input into the large language model to obtain a third return result; The third returned result is used as the dialogue statement.
2. The NPC interaction optimization method based on a large language model as claimed in claim 1, characterized in that: The determining whether to execute the action guide based on the large language model according to the action guide and the perception experience includes: Input action instructions and perception experiences into the large language model to obtain the first return result; When the first returned result is execution, it is determined that the action guide is to be executed; otherwise, it is determined that the action guide is not to be executed.
3. The NPC interaction optimization method based on a large language model as claimed in claim 1, characterized in that: The dialogue evaluation index includes at least: the last call time and the familiarity of the NPC who initiates the long-distance / short-distance dialogue.
4. The NPC interaction optimization method based on a large language model as claimed in claim 1, characterized in that: The action instructions include: action type, start time and end time; The time difference between the start time and the end time is the minimum time unit.
5. The NPC interaction optimization method based on a large language model as claimed in claim 1, characterized in that: The specific steps to initiate a long-range / short-range conversation between NPCs are as follows: Get the NPC's simulated dialogue plan for the day; When the simulated dialogue plan includes a dialogue simulation project, determining the dialogue partner based on the dialogue simulation project; Identify other NPCs who are the conversation targets from the map environment; Determine whether the current NPC status of the NPC and other NPCs are both idle; When all are in idle state, determine the position distance between the NPC and other NPCs in the map environment; When the location distance is greater than or equal to the distance threshold, a remote conversation is initiated between NPCs; Otherwise, a short-range conversation is initiated between NPCs.
6. The NPC interaction optimization method based on a large language model as claimed in claim 1, characterized in that: Also includes: Real-time recording of NPC's perception experience in the map environment.
7. The NPC interaction optimization method based on a large language model as claimed in claim 1, characterized in that: The large language model includes at least: Chat-GPT model.
Citation Information
Patent Citations
Intelligent agent behavior determination method, computer equipment and storage medium
CN117828039A
Method for realizing personalized NPC (Non-Personalized Computer) based on memory enhancement algorithm in combination with large model driving
CN117828106A
