Chat method and device for multi-agent role playing
By configuring roles for users and agents and using large language models to train dialogues, the problem of single chat between users and agents in the existing technology is solved, and interaction and rich dialogue experience between multiple agents are achieved.
Patent Information
- Application Number
- CN202411738935.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-29
- Publication Date
- 2025-02-21
AI Technical Summary
In the prior art, chat between users and agents is usually limited to a single agent, resulting in the communication appearing single and lacking depth and fun.
By configuring roles for each participant to be chatted and training session samples using a large language model, the model learns dialogues that are consistent with character setting and plot development. The role of each participant is then input into the trained large language model to manage the actual conversation between multiple participants.
The dialogue and role-playing between multiple agents is realized, and new conversation information is generated to make the communication richer, more real and interesting.
Smart Images

Figure CN119494406A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a multi-agent role-playing chat method and device. Background Art
[0002] In the study of artificial intelligence, the concept of agents is widely used in various occasions. They can interact with the environment by sensing their surroundings and performing corresponding actions. These agents can be physical entities, such as autonomous robots, or software programs, such as the digital virtual assistants we use in our daily lives. However, most of the current user-agent chat technologies are usually limited to interactions with a single agent, which often makes the communication seem monotonous and lacks depth and interest. The existing user-agent chat technologies are often limited to a single agent, which inevitably makes the chat dialogue somewhat monotonous and lacks interest. Summary of the invention
[0003] In order to solve the above technical problems or at least partially solve the above technical problems, the present application provides a multi-agent role-playing chat method and device.
[0004] In a first aspect, the present application provides a multi-agent role-playing chat method, the method comprising:
[0005] According to preset role attributes, a role is configured for each participant to be chatted, wherein the participant includes at least two agents or includes at least one user and at least two agents;
[0006] Acquire a conversation sample containing the role attributes, wherein the conversation sample includes sample conversation contents between different roles;
[0007] The conversation samples are used to train a large language model, so that the large language model learns dialogues that are consistent with character settings and plot development;
[0008] The role configured by each participant is input into the trained large language model, and the actual conversation content between multiple participants is managed according to the trained large language model, wherein each participant conducts a conversation according to the role attributes of the configured role.
[0009] Optionally, obtaining a session sample including the role attribute includes:
[0010] Obtain interactive scenes and plots between multiple characters;
[0011] Based on the interaction scenario and the plot, the large language model is used to simulate multiple rounds of chats between multiple characters to generate original chat data;
[0012] Cleaning the original chat data, wherein the cleaning is used to remove the dialogue content whose relevance to the plot is less than a set relevance threshold;
[0013] The cleaned raw chat data is processed according to preset guidance information to generate target chat data, wherein the target chat data carries a label, and the label includes a role identifier of each conversation content and consistency of the conversation content and role attributes;
[0014] The target chat data is encoded and converted into a conversation sample that can be recognized by the large language model.
[0015] Optionally, processing the cleaned original chat data according to preset guidance information to generate target chat data includes:
[0016] Obtaining preset guidance information, wherein the guidance information includes task information, role attributes, plot information, output requirements, and format requirements;
[0017] The task information is used to instruct the generation of dialogues between characters according to the character attributes and plot information; the output requirements include that the first identifier is used in each dialogue content to represent the actions and expressions of the character to which it belongs, and the second identifier is used to represent the narration content that promotes the development of the plot, and the dialogue content of each character conforms to the corresponding character attributes and the dialogue content is coherent; the format requirements include that each dialogue content has a character identifier;
[0018] The cleaned original chat data is processed according to the guidance information to generate target chat data that meets the output requirements and the format requirements.
[0019] Optionally, using the conversation sample to train the large language model includes:
[0020] The large language model is fine-tuned or fully supervised using the conversation sample to obtain reply information of different qualities output by the large language model for the same conversation content;
[0021] Select the best quality reply information and the worst quality reply information to construct data pairs;
[0022] Based on the data pairs, a direct preference optimization algorithm is used to adjust the parameters of the large language model until the large language model outputs reply information that best matches the role setting.
[0023] Optionally, in the process of managing actual conversation content between multiple participants according to the trained large language model, the method further includes:
[0024] Identifying key conversation records in the actual conversation content;
[0025] The key conversation records are input into the large language model as memory content, wherein the memory content is used to assist the large language model in understanding the background and context information of the current conversation content.
[0026] Optionally, in the process of managing actual conversation content between multiple participants according to the trained large language model, the method further includes:
[0027] Get the role specified by the user for the next round of speaking;
[0028] Determine a role identifier corresponding to a role specified by a user, and switch the user to a new role based on the role identifier;
[0029] Generate conversation content based on the role the user switches to.
[0030] Optionally, in the process of managing actual conversation content between multiple participants according to the trained large language model, the method further includes:
[0031] Determining the number of the agents and the input length threshold of the large language model;
[0032] If the number of the agents exceeds a set number threshold, determining that the text information associated with the agents exceeds an input length threshold of the large language model;
[0033] Determine the first n roles that appeared in the historical conversation record and the next role that is about to speak, where n is a positive integer greater than 1;
[0034] The dialogue content that matches the next role is generated according to the dialogue content between the first n roles and the next role that is about to speak.
[0035] In a second aspect, the present application provides a multi-agent role-playing chat device, the device comprising:
[0036] A configuration module, configured to configure a role for each participant to be chatted with according to preset role attributes, wherein the participant includes at least two agents or includes at least one user and at least two agents;
[0037] An acquisition module, used to acquire a conversation sample containing the role attributes, wherein the conversation sample includes sample conversation contents between different roles;
[0038] A training module, used to train a large language model using the conversation samples, so that the large language model learns dialogues that are consistent with character settings and plot development;
[0039] The management module is used to input the role configured by each participant into the trained large language model, and manage the actual conversation content between multiple participants according to the trained large language model, wherein each participant conducts a conversation according to the role attributes of the configured role.
[0040] In a third aspect, an electronic device is provided, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;
[0041] Memory, used to store computer programs;
[0042] The processor is used to implement any of the steps of the multi-agent role-playing chat method when executing the program stored in the memory.
[0043] In a fourth aspect, a computer-readable storage medium is provided, wherein a computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, any of the steps of the multi-agent role-playing chat method is implemented.
[0044] The above technical solution provided by the embodiment of the present application has the following advantages compared with the prior art:
[0045] By training the large language model based on conversation samples, the large language model learns the dialogue that conforms to the role setting and plot development, and then inputs the role of each intelligent agent into the large language model. The large language model combines the unique role attributes of each role to accurately simulate the language style of each role and generate new conversation information. Compared with the dialogue between the user and a single intelligent agent in the prior art, this application realizes the dialogue between multiple intelligent agents, thereby realizing the interaction between multiple intelligent agent roles. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0047] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0048] Figure 1 A flowchart of a multi-agent role-playing chat method provided in an embodiment of the present application;
[0049] Figure 2 A schematic diagram of guidance information provided for an embodiment of the present application;
[0050] Figure 3 An overall flow chart of a multi-agent role-playing chat method provided in an embodiment of the present application;
[0051] Figure 4 A schematic diagram of the structure of a multi-agent role-playing chat device provided in an embodiment of the present application;
[0052] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0053] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0054] In the subsequent description, the suffixes such as "module", "component" or "unit" used to represent elements are only used to facilitate the description of the present application and have no specific meaning. Therefore, "module" and "component" can be used interchangeably.
[0055] In order to solve the problems mentioned in the background technology, an embodiment of the present application provides a multi-agent role-playing chat method, which can be applied to a server to realize chat between multiple agents.
[0056] The following will be combined with a specific implementation method to provide a multi-agent role-playing chat method in detail. Figure 1 As shown, the specific steps are as follows:
[0057] Step 101: configuring a role for each participant to chat according to preset role attributes, wherein the participant includes at least two agents or includes at least one user and at least two agents;
[0058] Step 102: Acquire a conversation sample containing role attributes, wherein the conversation sample includes sample conversation contents between different roles;
[0059] Step 103: Use conversation samples to train the large language model so that the large language model learns dialogues that are consistent with character settings and plot development;
[0060] Step 104: Input the role configured by each participant into the trained large language model, and manage the actual conversation content between multiple participants according to the trained large language model, wherein each participant conducts a conversation according to the role attributes of the configured role.
[0061] This application can be applied to a variety of interactive scenarios, such as exploration, puzzle solving, discussion, problem solving, etc.
[0062] In an embodiment of the present application, role setting information is collected based on website or film and television drama information, and then a corresponding role is configured for each participant according to the role attributes. The role configuration can ensure that each participant can maintain its specific identity and behavior pattern in the conversation. The server collects conversation samples containing these role attributes. These conversation samples should cover the interactive conversation content between different roles, and then use these conversation samples to train the large language model. The purpose is to let the model learn how to generate conversations that conform to the role settings and plot development, so that the model can accurately simulate the language style and behavioral reactions of each role. After the model is trained, the role configured by each participant is input into the trained large language model. The model generates new conversation information for each role. The new conversation information may contain new situations and user inputs. These contents may not appear directly in the conversation samples, but the model can generate appropriate responses through the learned patterns and rules, which means that the intelligent agent or user will naturally show their role characteristics when communicating, thereby providing a richer and more realistic interactive experience.
[0063] Optionally, the participants to be chatted include at least two intelligent agents, for example, to realize chat between multiple intelligent agents, and on this basis, users can also be added to realize chat between users and multiple intelligent agents.
[0064] Optionally, the role attributes include, but are not limited to: the role's name, gender, age, occupation, personality, hobbies, character relationships or background information, etc.
[0065] For example, in an adventure game, role A can be a brave explorer, role B can be a wise librarian, and role C can be a mysterious ancient book expert. The sample conversation is: <Role A>: Hello, I heard that there is a precious book about ancient civilization hidden here. <Role B>: Yes, the book is indeed here. But it is protected by a puzzle. <Role C>: If you can solve this puzzle, I can help you find the book. After training the large language model based on this sample, the model generates new conversation content: <Role A>: You have another treasure book here, right? <Role B>: You need to find it yourself. <Role C>: I hope you can find this treasure book, and I am looking forward to seeing it.
[0066] This application trains a large language model based on conversation samples so that the large language model learns dialogues that are consistent with character settings and plot development, and then inputs the role of each agent into the large language model. The large language model combines the unique role attributes of each character to accurately simulate the language style of each character and generate new conversation information. Compared with the dialogue between a user and a single agent in the prior art, this application realizes dialogue between multiple agents, thereby realizing interaction between multiple agent characters. In addition, users can also join the role, and users can experience the development of the story from different angles, chat immersively with multiple agents, and enjoy richer and more interesting social interactions.
[0067] As an optional implementation, in step 102, obtaining a session sample including role attributes includes the following steps:
[0068] Step 1021: Obtain interaction scenes and plots between multiple characters.
[0069] In the embodiments of the present application, interaction scenes and plots are manually written, or a large language model is used to generate chat scenes and plots between multiple characters based on role setting information and examples. The interaction scenes include interactive situations between characters, such as adventure, puzzle solving, discussion, etc., and the plot provides the background story or specific situation in which the conversation occurs.
[0070] For example, interactive scenario: The explorer (character A) enters a mysterious library full of ancient books to find an ancient book that can guide his next adventure. Plot: The librarian (character B) knows the existence of the book and it is protected by a puzzle. The ancient book expert (character C) has in-depth research on ancient books and can provide additional help.
[0071] Step 1022: Based on the interaction scenario and plot, a large language model is used to simulate multiple rounds of chats between multiple characters to generate raw chat data.
[0072] The server inputs the interaction scene and plot information into the large language model, which generates multiple rounds of dialogue between multiple characters based on this information to form the original chat data. The original chat data needs to include complex dialogues between multiple agents, and ensure that each agent meets its own role settings. In addition, for role-playing, a plot content describing the chat background needs to be generated.
[0073] Step 1023: Clean the original chat data, wherein the cleaning is used to remove the dialogue content whose relevance to the plot is less than a set relevance threshold.
[0074] The server uses natural language processing technology or manual review to evaluate the relevance of each conversation content to the plot and sets a relevance threshold. Conversation content below this threshold will be eliminated. By removing irrelevant conversation content, high-quality conversation data can be retained.
[0075] The server labels the cleaned target chat data, including adding role identifiers and consistency labels between conversation content and role attributes. This structured data input method simplifies the model training process and helps the model better understand and imitate complex role behaviors and conversation logic.
[0076] Step 1024: Process the cleaned original chat data according to preset guidance information to generate target chat data, wherein the target chat data carries a label, and the label includes a role identifier of each conversation content and the consistency of the conversation content and role attributes.
[0077] The data structure of the original chat data is relatively random. In order to format the data structure, the original chat data with preset guidance information can be processed to generate target chat data in a standard format for subsequent model training. In addition, in order to train the model, it is necessary to add a role identifier to each conversation content in the target chat data, as well as a consistency label between the conversation content and the role attributes. The role identifier is used to uniquely identify each role.
[0078] Step 1025: Encode the target chat data and convert it into a conversation sample that can be recognized by the large language model.
[0079] The server uses a tokenizer to split the text into words or subwords and assigns a unique number to each word or subword. The tokenizer converts the text data into a digital sequence, and then converts each conversation content and its label in the target chat data into a corresponding digital sequence to ensure that the encoded data format meets the input requirements of the large language model.
[0080] As an optional implementation, in step 1024, the cleaned raw chat data is processed according to preset guidance information, and generating target chat data includes: obtaining preset guidance information, wherein the guidance information includes task information, role attributes, plot information, output requirements and format requirements; wherein the task information is used to indicate the generation of dialogues between characters according to the role attributes and plot information; the output requirements include using a first identifier in each dialogue content to represent the actions and expressions of the character to which it belongs, and using a second identifier to represent the narration content that promotes the development of the plot, and the dialogue content of each character conforms to the corresponding role attributes and the dialogue content is coherent; the format requirements include each dialogue content having a role identifier; the cleaned raw chat data is processed according to the guidance information to generate target chat data that meets the output requirements and format requirements.
[0081] Guidance information includes task information, role attributes, plot information, output requirements, and format requirements. Guidance information such as Figure 2 As shown, the following is a detailed explanation of each content in the guidance information.
[0082] Mission information: Explicit instructions for generating dialogues between characters based on character attributes and plot information, including the topic, goal, and expected flow of the dialogue.
[0083] Character attributes: basic attributes and background information of each character, such as name, gender, age, occupation, personality traits, etc. This information helps define the character's behavior patterns and language style.
[0084] Plot information: The backstory or situation in which the dialogue takes place, providing context for the dialogue. This helps ensure that the dialogue fits into the overall storyline.
[0085] Output requirements:
[0086] First identification: Use brackets () to indicate the character's actions and expressions to enhance the authenticity and expressiveness of the dialogue.
[0087] Second identifier: Use square brackets [] to indicate narration that drives the plot forward, supplements the scene description or advances the storyline, and enriches the context and background information of the dialogue.
[0088] Character consistency: The dialogue content of each character should be consistent with its set character attributes, and the entire dialogue content should be coherent.
[0089] Format requirements: Each conversation content must contain a role identifier for easy identification and management in subsequent processing.
[0090] The following is an explanation with examples.
[0091] 1. Interactive scene: The explorer (character A) enters a mysterious library full of ancient books to find an ancient book that can guide his next adventure. Plot: The librarian (character B) knows the existence of this book and it is protected by a puzzle. The ancient book expert (character C) has in-depth research on ancient books and can provide additional help.
[0092] 2. The process of generating a sample session based on the guidance information is as follows:
[0093] <system>#
[0094] Task
[0095] Please generate a dialogue between the character and the player based on the following character and plot information.
[0096] ##Character Settings
[0097] <Character A>
[0098] A brave explorer with a knack for solving puzzles.
[0099] <Character B>
[0100] A wise librarian with extensive knowledge.
[0101] ##Plot Information
[0102] Character A enters a mysterious library full of ancient books in search of an ancient book that can guide his next adventure.
[0103] ##beginning
[0104] Character A: Hello, I heard that there is a valuable book about ancient civilization hidden here.
[0105] Character B: Yes, the book is indeed here. But it's protected by a puzzle.
[0106] ##Output requirements 1) Output the character dialogue content, where () is the character's actions and expressions, and [] is the narration content that promotes the development of the plot;
[0107] 2) The narration appears every 2 to 3 rounds. The narration appears in the form of []. It continues and expands on the plot information and promotes the development of the plot.
[0108] 3) The dialogue content of different characters needs to be consistent with the personality reflected in the character information, and the dialogue content must be coherent.
[0109] < / system>
[0110] <user>
[0111] {History Chat}
[0112] You (referring to the user): ...
[0113] <Character A>: …
[0114] <Character B>: …
[0115] <assistant>
[0116] {Specify output role}
[0117] <Character A>: Character A (curiously): Can you tell me what this puzzle is?
[0118] <Character B>: Character B (smiles): Of course. The puzzle is this: What gets dirtier the more you wash it?
[0119] [Character A is lost in thought]
[0120] <Character A>: Character A (thinking): This is a classic puzzle. The answer is water, right?
[0121] <Character B>: Character B (nods): That's right! It seems you are really smart.
[0122] [Character A breathes a sigh of relief]
[0123] <Character A>: Character A (excitedly): Great, now can you tell me where the book is?
[0124] <Character B>: Character B (pointing to bookshelf): It's on the top shelf of that bookshelf.
[0125] < / assistant>
[0126] 3. The generated sample session is:
[0127] Character A>: Hello, I heard that there is a precious book about the ancient Jiao Ming hidden here.
[0128] Character B: Yes, the book is here. But it's protected by a puzzle. [Character A is lost in thought]
[0129] <Character A> (curiously): Can you tell me what this puzzle is?
[0130] Character B> (smiles): Of course. The puzzle is this: What gets dirtier the more you wash it? [Character A thinks for a while]
[0131] <Character A> (thinking): This is a classic puzzle. The answer is water, right?
[0132] <Character B> (nods): That's right! It seems you are really smart. [Character A breathes a sigh of relief].
[0133] <Character A> (excitedly): Great, now can you tell me where the book is?
[0134] <Character B>(points to bookshelf): It's on the top shelf of that bookshelf.
[0135] Through the above steps, this application can generate high-quality dialogue data that conforms to the role setting and plot development based on the detailed guidance information of the content. The dialogue content of each character is consistent with the role attributes set by the character, ensuring the consistency of the character's behavior and language style, and the dialogue content is consistent with the overall storyline to promote the development of the plot. The dialogue content is coherent, the logic is clear, and there are no abrupt or unreasonable turns; the contextual coherence of the dialogue is enhanced through the narration content and the character's actions and expressions.
[0136] As an optional implementation, in step 103, training the large language model using the conversation sample includes:
[0137] Step 1031: fine-tune or fully supervise the large language model using the conversation samples to obtain reply information of different qualities output by the large language model for the same conversation content;
[0138] Step 1032: Select the reply information with the best quality and the reply information with the worst quality to construct a data pair;
[0139] Step 1033: Based on the data pairs, the parameters of the large language model are adjusted using a direct preference optimization algorithm until the large language model outputs a reply message that best matches the role setting.
[0140] The server uses the prepared conversation samples to fine-tune or fully supervise the large language model. The training goal is to make the generated user responses as consistent as possible with the conversation samples, so the loss function is the cross-entropy loss function. Based on the original large language model, this application introduces the DPO (Direct Preference Optimization) algorithm, using the self-developed model after supervised training and different model generation parameters. For the same conversation content, the large language model generates multiple different responses, which may differ in quality, including grammar, coherence, role consistency, etc.
[0141] Through manual evaluation or automatic evaluation methods (such as rule-based evaluation, model-based evaluation, etc.), the quality of the generated replies is evaluated to distinguish the best quality replies from the worst quality replies. The best quality replies and the worst quality replies are then paired to form data pairs, so that each data pair contains different quality replies to the same conversation content. The server inputs the data pairs into the DPO algorithm. The DPO algorithm calculates a reward signal by comparing the quality of each pair of replies, and adjusts the model parameters based on the reward signal so that the model is more inclined to generate better quality replies. The above process is repeated until the reply information output by the model best matches the role setting.
[0142] Among them, fine-tuning refers to further adjusting the model parameters based on the pre-trained model using the data of specific tasks to make it better suited to specific tasks, and full supervision refers to training the model from scratch.
[0143] DPO is a reinforcement learning algorithm that adjusts model parameters by comparing the quality of different responses, making the model more inclined to generate responses with higher quality.
[0144] This application introduces DPO technology to adjust model parameters by comparing the quality of different responses, so that the model can generate high-quality responses that better meet user needs.
[0145] As an optional implementation, the method also includes: identifying key conversation records in the actual conversation content; inputting the key conversation records as memory content into the large language model, wherein the memory content is used to assist the large language model in understanding the background and context information of the current conversation content.
[0146] The server obtains the actual conversation content and searches for key conversation records through the complete historical conversation records. Key conversation records refer to conversation contents that have important information in the current conversation or have a significant impact on subsequent conversations. These records may include important decision points, key interactions between characters, important plot developments, etc. Among them, the methods used to identify key conversation records include but are not limited to: identifying key conversation records through predefined rules and keywords, for example, certain specific words or phrases (such as puzzles, clues, next steps, etc.) can be set as trigger words; using natural language processing technology, such as named entity recognition), sentiment analysis, key sentence extraction, etc., to automatically identify key conversation records; identifying key conversation records through manual annotation.
[0147] The server organizes the identified key conversation records into memory content in a specific format. Usually, the memory content contains the historical background and contextual information of the conversation so that the model can better understand the content of the current conversation. The server inputs the memory content into the large language model as additional information, which can be achieved by adding special tags to the conversation text or using the model's context window. The memory content helps the model understand the background and contextual information of the current conversation, so as to generate more situational and coherent responses.
[0148] In this application, the memory content provides the historical background of the conversation, helping the model to better understand the context of the current conversation. The model can generate more coherent and consistent responses based on the memory content, avoiding abrupt or unreasonable turns in the conversation. The memory content helps the model maintain the consistency and coherence of the conversation and improves the quality of the conversation. By identifying and utilizing key conversation records, limited conversation data is effectively utilized, improving data utilization efficiency. In a conversation involving multiple agents, the memory content helps each agent better understand the behavior and intentions of other agents, thereby promoting collaboration between agents.
[0149] As an optional implementation, the method also includes: obtaining the role specified by the user for the next round of speech; determining the role identifier corresponding to the role specified by the user, and switching the user to a new role based on the role identifier; and generating dialogue content based on the role after the user switches.
[0150] During the conversation, the user explicitly specifies the role to be played in the next round of speaking. This can be achieved by the user inputting specific instructions or selections. The system identifies the new role that the user wants to switch to by parsing the user's input. Each role has a unique identifier for identification and management in the conversation. These identifiers can be predefined tags, such as <role A>, <role B>, etc. The system switches the user to the new role based on the determined role identifier, which means that the user will speak as the new role in the next conversation. The system can also send a confirmation message to the user to inform him that he has successfully switched to the new role and prompt the user to start speaking as the new role. The system generates the conversation content based on the role that the user has switched to, and the generated response should be consistent with the setting of the role and the context of the current conversation.
[0151] For example, user input: I want to play the role of librarian. System output: OK, you are now a librarian. How can I help you? User (as librarian): This book is very precious, please handle it with care. System generated response (explorer, role A): I will be very careful, thank you for your reminder.
[0152] In addition, the large language model can also automatically determine the role the user should play in the next round based on the chat history. This is usually based on the context of the conversation content, a set story line, or a preset character development path.
[0153] In this application, users can freely switch between different roles in the dialogue. These two role switching mechanisms not only increase the playability and interactivity of the game, but also enable users to experience the story from different angles, deepening the user experience and satisfaction.
[0154] As an optional implementation, the method also includes: in the process of managing the actual conversation content between multiple participants according to the trained large language model, the method also includes: determining the number of intelligent agents and the input length threshold of the large language model; if the number of intelligent agents exceeds the set number threshold, determining that the text information associated with the intelligent agent exceeds the input length threshold of the large language model; determining the first n roles that appear in the historical conversation record and the next role to speak, where n is a positive integer greater than 1; generating conversation content that conforms to the next role based on the conversation content of the first n roles and the next role to speak.
[0155] The server determines the number of agents participating in the current conversation by counting the role identifiers in the current conversation. Each large language model has an input length limit, that is, the maximum text length that the model can process. This threshold is usually fixed and depends on the model architecture and training parameters. The server calculates the total length of the associated text information of all agents (including role settings, historical conversation content, etc.). If the total text information length exceeds the input length threshold of the large language model, measures need to be taken to reduce the input length. In order to ensure that the model can handle multi-agent conversations while maintaining the consistency and coherence of the context, the server selects the first n roles (n is a positive integer greater than 1) that appear in the historical conversation records and the next role to speak, and extracts the identifiers and related text information of these roles. The server inputs the relevant text information of the first n roles and the next role to speak into the large language model, and the model generates conversation content that conforms to the next role setting based on the input information.
[0156] This application can effectively manage the actual conversation content between multiple participants, and when there are a large number of intelligent agents and the model input length is limited, by selecting the text information of key roles, the length of text input to the model is reduced, thereby improving processing efficiency; and by selecting the first n roles that appear in the historical conversation records and the next role that is about to speak, it is ensured that the model can obtain the most important role information in the current conversation context, thereby making the generated conversation content more coherent, logically clear, and without abrupt or unreasonable turns.
[0157] For example, in a simulated social gathering scenario, there are four intelligent agents: A (cheerful artist), B (serious scientist), C (humorous writer) and D (smart doctor). The user is discussing the comparison between art and science with A and B.
[0158] Dialogue history: User: How do you view the relationship between art and science? A: I think art is an expression of emotion, while science is a manifestation of logic. The two complement each other! B: Indeed, science needs the innovative thinking of art, and art can gain inspiration from scientific discoveries.
[0159] Agent Interaction: In this conversation, the system will input the role setting information of A and B because they are the first two roles to answer. Assuming that it is C's turn to answer next, the system will also input C's role setting information. For the model, it now has the key information of A (cheerful artist), B (serious scientist), and C (humorous writer). Even if D's information is not input, the model can generate appropriate responses based on the information of the current three roles. C might answer: Haha, it sounds like you two have already said the most important points. I will only add that whether it is art or science, the ultimate goal is to explore the mysteries of human nature and the universe.
[0160] In addition, the present application also provides another embodiment. If it is detected that the length of the historical conversation content in the large language model exceeds the set length threshold, it indicates that the historical conversation content is sufficient. In order to prevent the input content from exceeding the input length limit of the model, it is necessary to limit the input conversation content to no more than a few rounds in subsequent input, that is, to limit the number of rounds of the conversation content.
[0161] This application provides a multi-agent role-playing chat flow chart, such as Figure 3 As shown, the following steps are included:
[0162] Step 1: Character setting.
[0163] Define the role attributes of each participant, including the role's name, gender, age, occupation, personality, hobbies, character relationships, and background information.
[0164] Step 2: Data preprocessing.
[0165] Manually write or use a large language model to generate chat scenes and plots between multiple characters. Based on this content, use a large language model to simulate multiple rounds of chats between multiple characters to generate raw chat data, clean the raw chat data, remove irrelevant conversation content, retain high-quality conversation data, process the raw chat data according to the guidance information, generate target chat data in a standard format, and add a role identifier to each conversation content in the target chat data, as well as a consistency label between the conversation content and the role attributes, and convert the target chat data into a conversation sample that can be recognized by the large language model. Use a tokenizer to encode the text and input it into the model for training.
[0166] Step 3: Model training.
[0167] Use conversation samples to fine-tune or fully supervise the large language model to obtain response information of different qualities for the same conversation content. Select the response information with the best quality and the response information with the worst quality to construct data pairs. Combined with the DPO algorithm, adjust the model parameters according to the data pairs until the large language model outputs the response information that best matches the role setting, and the model training is completed.
[0168] Step 4: Dialogue management.
[0169] Dialogue state tracking: Record the history of the dialogue to ensure that the agent understands the current state of the dialogue. In addition, in order to better record important information in the chat history, the interaction events can be extracted through a large model or extraction algorithm as memory content and input into the dialogue model.
[0170] Role switching mechanism: allows users to switch between multiple roles. The switching mechanism can be completed by the user specifying the output role for the next round and then inputting the role identifier into the model; it can also be generated by the model based on the chat history.
[0171] Agent interaction: In order to achieve interaction between multiple agents and avoid inconsistencies with the personalities, multiple role setting information needs to be input into the model in a multi-person chat state. When the number of agents is large and the model input length is limited, at least the first two roles that appeared in the historical conversation and the next chat role need to be input.
[0172] This application can effectively configure role attributes, obtain conversation samples, train large language models, and manage the conversation content between multiple participants in actual conversations. This not only ensures that the behavior and language style of each participant is consistent with their role settings, but also maintains the consistency and coherence of the conversation.
[0173] Based on the same technical concept, the present application embodiment also provides a multi-agent role-playing chat device, such as Figure 4 As shown, the device comprises:
[0174] Configuration module 401, configured to configure a role for each participant to be chatted according to preset role attributes, wherein the participant includes at least two agents or includes at least one user and at least two agents;
[0175] An acquisition module 402 is used to acquire a conversation sample containing role attributes, wherein the conversation sample includes sample conversation contents between different roles;
[0176] A training module 403 is used to train the large language model using conversation samples so that the large language model learns dialogues that are consistent with character settings and plot development;
[0177] The management module 404 is used to input the role configured by each participant into the trained large language model, and manage the actual conversation content between multiple participants according to the trained large language model, wherein each participant conducts a conversation according to the role attributes of the configured role.
[0178] Optionally, the acquisition module 402 is used to:
[0179] Obtain interactive scenes and plots between multiple characters;
[0180] Based on the interaction scenarios and plots, a large language model is used to simulate multiple rounds of chats between multiple characters to generate raw chat data;
[0181] Cleaning the original chat data, wherein the cleaning is used to remove the conversation content whose relevance to the plot is less than a set relevance threshold;
[0182] The cleaned raw chat data is processed according to preset guidance information to generate target chat data, wherein the target chat data carries a label, and the label includes a role identifier of each conversation content and consistency of the conversation content and role attributes;
[0183] Encode the target chat data and convert it into conversation samples that can be recognized by the large language model.
[0184] Optionally, the acquisition module 402 is used to:
[0185] Obtaining preset guidance information, wherein the guidance information includes task information, role attributes, plot information, output requirements, and format requirements;
[0186] Among them, the task information is used to instruct the generation of dialogues between various characters according to the character attributes and plot information; the output requirements include that the first identifier is used in each dialogue content to represent the actions and expressions of the corresponding character, and the second identifier is used to represent the narration content that promotes the development of the plot, and the dialogue content of each character conforms to the corresponding character attributes and the dialogue content is coherent; the format requirements include that each dialogue content has a character identifier;
[0187] The cleaned raw chat data is processed according to the guidance information to generate target chat data that meets the output requirements and format requirements.
[0188] Optionally, the training module 403 is used to:
[0189] Use conversation samples to fine-tune or fully supervise the large language model, and obtain response information of different qualities for the same conversation content output by the large language model;
[0190] Select the best quality reply information and the worst quality reply information to construct data pairs;
[0191] Based on the data pairs, the direct preference optimization algorithm is used to adjust the parameters of the large language model until the large language model outputs the reply information that best matches the role setting.
[0192] Optionally, the device is also used for:
[0193] Identify key conversation records from actual conversation content;
[0194] The key conversation records are input into the large language model as memory content, where the memory content is used to assist the large language model in understanding the background and context information of the current conversation content.
[0195] Optionally, the device is also used for:
[0196] Get the role specified by the user for the next round of speaking;
[0197] Determine the role identifier corresponding to the role specified by the user, and switch the user to a new role based on the role identifier;
[0198] Generate conversation content based on the role the user switches to.
[0199] Optionally, the device is also used for:
[0200] Determine the number of agents and the input length threshold for large language models;
[0201] If the number of agents exceeds a set number threshold, determining that the text information associated with the agents exceeds an input length threshold of the large language model;
[0202] Determine the first n roles that appeared in the historical conversation record and the next role that is about to speak, where n is a positive integer greater than 1;
[0203] Generate the dialogue content that suits the next role based on the dialogue content between the first n roles and the next role that is about to speak.
[0204] Based on the same technical concept, an embodiment of the present invention further provides an electronic device, such as Figure 5 As shown, it includes a processor 501, a communication interface 502, a memory 503 and a communication bus 504, wherein the processor 501, the communication interface 502, and the memory 503 communicate with each other through the communication bus 504.
[0205] Memory 503, used for storing computer programs;
[0206] The processor 501 is used to implement the above steps when executing the program stored in the memory 503.
[0207] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0208] The communication interface is used for communication between the above electronic device and other devices.
[0209] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0210] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0211] In another embodiment of the present invention, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above methods are implemented.
[0212] In another embodiment of the present invention, a computer program product including instructions is provided, which enables the computer to execute any one of the methods in the above embodiments when the computer program product is executed on the computer.
[0213] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk Solid State Disk (SSD)), etc.
[0214] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "includes a..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0215] The foregoing is merely a specific embodiment of the present invention, which enables those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features claimed herein.< / user>
Claims
1. A multi-agent role-playing chat method, characterized in that: The method comprises: According to preset role attributes, a role is configured for each participant to be chatted, wherein the participant includes at least two agents or includes at least one user and at least two agents; Acquire a conversation sample containing the role attributes, wherein the conversation sample includes sample conversation contents between different roles; The conversation samples are used to train a large language model, so that the large language model learns dialogues that are consistent with character settings and plot development; The role configured by each participant is input into the trained large language model, and the actual conversation content between multiple participants is managed according to the trained large language model, wherein each participant conducts a conversation according to the role attributes of the configured role.
2. The method according to claim 1, characterized in that Obtaining a session sample containing the role attributes includes: Obtain interactive scenes and plots between multiple characters; Based on the interaction scenario and the plot, the large language model is used to simulate multiple rounds of chats between multiple characters to generate original chat data; Cleaning the original chat data, wherein the cleaning is used to remove the dialogue content whose relevance to the plot is less than a set relevance threshold; The cleaned raw chat data is processed according to preset guidance information to generate target chat data, wherein the target chat data carries a label, and the label includes a role identifier of each conversation content and consistency of the conversation content and role attributes; The target chat data is encoded and converted into a conversation sample that can be recognized by the large language model.
3. The method according to claim 2, characterized in that The cleaned raw chat data is processed according to the preset guidance information to generate target chat data including: Obtaining preset guidance information, wherein the guidance information includes task information, role attributes, plot information, output requirements, and format requirements; The task information is used to instruct the generation of dialogues between characters according to the character attributes and plot information; the output requirements include that the first identifier is used in each dialogue content to represent the actions and expressions of the character to which it belongs, and the second identifier is used to represent the narration content that promotes the development of the plot, and the dialogue content of each character conforms to the corresponding character attributes and the dialogue content is coherent; the format requirements include that each dialogue content has a character identifier; The cleaned original chat data is processed according to the guidance information to generate target chat data that meets the output requirements and the format requirements.
4. The method according to claim 1, characterized in that Using the conversation sample to train the large language model includes: The large language model is fine-tuned or fully supervised using the conversation sample to obtain reply information of different qualities output by the large language model for the same conversation content; Select the best quality reply information and the worst quality reply information to construct data pairs; Based on the data pairs, a direct preference optimization algorithm is used to adjust the parameters of the large language model until the large language model outputs reply information that best matches the role setting.
5. The method according to claim 1, characterized in that In the process of managing actual conversation content between multiple participants according to the trained large language model, the method further includes: Identifying key conversation records in the actual conversation content; The key conversation records are input into the large language model as memory content, wherein the memory content is used to assist the large language model in understanding the background and context information of the current conversation content.
6. The method according to claim 1, characterized in that In the process of managing actual conversation content between multiple participants according to the trained large language model, the method further includes: Get the role specified by the user for the next round of speaking; Determine a role identifier corresponding to a role specified by a user, and switch the user to a new role based on the role identifier; Generate conversation content based on the role the user switches to.
7. The method according to claim 1, characterized in that In the process of managing actual conversation content between multiple participants according to the trained large language model, the method further includes: Determining the number of the agents and the input length threshold of the large language model; If the number of the agents exceeds a set number threshold, determining that the text information associated with the agents exceeds an input length threshold of the large language model; Determine the first n roles that appeared in the historical conversation record and the next role that is about to speak, where n is a positive integer greater than 1; The dialogue content that matches the next role is generated according to the dialogue content between the first n roles and the next role that is about to speak.
8. A multi-agent role-playing chat device, characterized in that: The device comprises: A configuration module, configured to configure a role for each participant to be chatted with according to preset role attributes, wherein the participant includes at least two agents or includes at least one user and at least two agents; An acquisition module, used to acquire a conversation sample containing the role attributes, wherein the conversation sample includes sample conversation contents between different roles; A training module, used to train a large language model using the conversation samples, so that the large language model learns dialogues that are consistent with character settings and plot development; The management module is used to input the role configured by each participant into the trained large language model, and manage the actual conversation content between multiple participants according to the trained large language model, wherein each participant conducts a conversation according to the role attributes of the configured role.
9. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, for implementing the method steps described in any one of claims 1 to 7 when executing a program stored in a memory.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method steps described in any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Intention understanding driven large model AI multi-role cooperative interaction method and device
CN120704636A
Large language model role interaction system based on plot driving and tool calling
CN121598807A
Multi-device cooperation method and device, electronic device and storage medium
CN121687031A
