A memory-enhanced script generation agent system based on RAG

Through the RAG-based memory-enhanced script generation intelligent agent system, the problems of insufficient autonomy and originality in script generation in the existing technology are solved, high-quality and logically coherent script generation is achieved, and the professionalism and artistry of the script are improved.

CN120337981BActive Publication Date: 2025-09-19COMMUNICATION UNIVERSITY OF CHINA
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510839303.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-06-23
Publication Date
2025-09-19
Estimated Expiration
2045-06-23

AI Technical Summary

Technical Problem

Existing artificial intelligence technology for generating scripts has the disadvantages of low autonomy, originality, and scalability. It is difficult to understand the script format and generate high-quality, logically coherent scripts, and is prone to hallucinations.

Method used

A memory-enhanced script generation agent system based on RAG is adopted to achieve professional understanding, originality guidance and logical control of scripts through data collection and knowledge base construction, pre-learning and reinforcement training, self-learning script generation, long-term memory and knowledge tree management, as well as script evaluation and feedback closed-loop mechanism.

Benefits of technology

It improves the originality, logic and artistry of script generation, avoids plot disconnection and illusion, and ensures that the generated script meets professional requirements and user needs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120337981B_ABST
    Figure CN120337981B_ABST
Patent Text Reader

Abstract

The present invention discloses a memory-enhanced script generation intelligent agent system based on RAG, which belongs to the field of artificial intelligence technology and includes a data acquisition and knowledge base construction module; a pre-learning and reinforcement training module, which uses a professional terminology library, an ambiguous interpretation library and a script sample knowledge base as pre-learning modules, adopts a reinforcement learning algorithm to train the generation module, and at the same time, quantifies specific indicators to form script scoring rules; a self-learning script generation module to realize script generation; a long-term memory and knowledge tree management module to extract, encode and store key information layer by layer; a script evaluation and feedback closed-loop mechanism, which grades and scores the generated scripts through preset quantitative evaluation indicators, and feeds back to the self-learning script generation module; the memory-enhanced script generation intelligent agent system based on RAG provided by the present invention can realize the flexible generation of high-quality scripts through the collaborative cooperation of multiple agents, reduce the sense of patchwork, and improve usability and ease of use.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a memory-enhanced script generation intelligent agent system based on RAG. Background Art

[0002] Existing artificial intelligence technology for generating artistic works has problems such as low autonomy, weak originality, low degree of evolvability, simple imitation without a single artistic concept, and a lack of script scoring rules.

[0003] Specifically, first of all, the format of the script is rather special. The first problem faced by the current use of artificial intelligence technology to generate scripts is that AI without professional guidance cannot quickly understand a script. Similarly, it is impossible to directly generate a script work that can be used to guide actors' performances according to the script format. Secondly, when current generative artificial intelligence products directly generate script content, the generated content is of poor quality and lacks originality. It can be seen at a glance that the generated content has a serious "patchwork feel" and the plot is relatively bland, all within logical expectations, lacking fun, creativity and artistic value. In addition, it is difficult to avoid hallucinations when using generative artificial intelligence to generate scripts. Sometimes, some completely illogical content will be generated, and they cannot achieve long-term memory. Because scripts are long, highly continuous works of art, they require strong consistency and logical coherence. Current generative AI products fail to meet this requirement, resulting in disjointed plots, unclear protagonists, unclear logic, inconsistent characterizations, a lack of a core plotline, and overly simplistic and monotonous plots. They are also prone to misunderstandings. For example, when a user describes a scenario as "please give me a wonderful, beautiful scene," the generative AI might respond with a literally "beautiful" scene featuring many colors, flames, and flowers, which doesn't meet the user's actual needs. Furthermore, some technical terminology is incomprehensible, leading to misunderstandings. Finally, the content generated by generative AI is often of low quality, capable of only basic plot generation, but not ready for immediate use. The density, character placement, logic, ups and downs, and volume of the plot are all poorly considered. Furthermore, these products fail to fully understand the meaning of the uploaded scenario, the underlying metaphors or foreshadowing, or the deeper meaning of the plot, ultimately resulting in a hollow and superficial script. Summary of the Invention

[0004] The purpose of the present invention is to provide a memory-enhanced script generation intelligent agent system based on RAG to solve the problems existing in the above-mentioned background technology.

[0005] To achieve the above objectives, the present invention provides a memory-enhanced script generation agent system based on RAG, a data collection and knowledge base construction module, which collects relevant professional terms, common expressions and polysemous words, and constructs a professional term dictionary, an ambiguous interpretation library and a script sample knowledge base;

[0006] The pre-learning and reinforcement training module uses a professional terminology library, an ambiguous interpretation library, and a script sample knowledge base as pre-learning modules, and uses a reinforcement learning algorithm to train the generation module. At the same time, the editor's requirements for the script are quantified into specific indicators to form a script scoring rule;

[0007] Self-learning script generation module, a generation system composed of multiple intelligent agents, which jointly realizes script generation;

[0008] The long-term memory and knowledge tree management module extracts, encodes, and stores key information layer by layer to form a high-density representation of condensed data;

[0009] The script evaluation and feedback closed-loop mechanism uses preset quantitative evaluation indicators to grade and score the generated scripts, and feeds back to the self-learning script generation module.

[0010] Preferably, the data collection and knowledge base construction module uses crawler technology to automatically collect professional terms, common expressions and polysemous words related to the script, and establish a professional term dictionary and ambiguous interpretation library. Specifically, the crawler uses Python's beautifulsoup library to implement it.

[0011] Preferably, the script sample knowledge base is a sample library containing multiple script types. By extracting the key information of the script, the format and style specifications are provided for subsequent generation. When extracting the key information, a text analysis algorithm is used to perform word segmentation on the sample script and calculate the word frequency-inverse document frequency value of each keyword. The formula is:

[0012] ;

[0013] in, Expressive words In the documentation word frequency in ; Expressive words In the documentation The inverse document frequency in will be saved according to the importance of the word segmentation;

[0014] The script sample knowledge base uses the Redis database for distributed storage.

[0015] Preferably, in the pre-learning and reinforcement training modules, the reinforcement learning algorithm guides the agent to continuously optimize its strategy by setting a specific reward function. In the scenario generation task, the reward function is set as:

[0016] ;

[0017] in, is the total reward; Reward for the format; Reward for style; For content rewards, 、 、 are the weight coefficients of the three rewards, and ;

[0018] Content Rewards Expressed as:

[0019] ;

[0020] in, Score for high quality; Score for high originality; is an adjustable weight coefficient, set to , indicating that quality and originality are equally important for content;

[0021] High quality score It is divided into three parts:

[0022] ;

[0023] in, Score for the number of characters; score for the number of episodes; score plot density; 、 、 All represent weight coefficients, which are 0.3, 0.3, and 0.4 respectively;

[0024] ;

[0025] ;

[0026] ;

[0027] in, For the density of the plot; is the number of major plots; is the total number of episodes; is the penalty coefficient; Indicates the The number of characters in each plot; Indicates the maximum number of characters in all plots; Indicates the maximum number of plots specified;

[0028] High originality score This section is the originality score generated by the evaluation model:

[0029] ;

[0030] The score is obtained through the following prompt: Please evaluate the plot of the following script from the perspective of originality. Novel but logically reasonable is high originality, and completely repeating the template is low originality. The score range is 0-1.

[0031] Preferably, in the script generation task, the self-learning script generation module regards the generated script content as a trajectory of the intelligent agent in the environment, and each node To maximize the quality of its story units, the objective function is:

[0032] ;

[0033] in, Indicates the The strategy parameters of each node; Indicates that according to the parameters Generate trajectories The probability distribution of Represents the reward score of the generated short story unit;

[0034] Through the policy gradient theorem, the agent gradually optimizes the script generation strategy. The policy gradient formula for a single generation node is:

[0035] ;

[0036] in, represents the expected cumulative reward; Indicates the parameters Find the gradient; Indicates about parameters Function gradient; Indicates that in the strategy Among all the trajectories, calculate the weighted average of the contents according to the probability of the trajectory appearing; It is expectation; Represents trajectory According to the current policy parameters The probability distribution of the trajectory generated under obtained by sampling;

[0037] Distributed computing is used to split the long script generation task into multiple small task units, each of which is completed independently. Then, a synthesis algorithm is used to ensure the logical consistency and narrative coherence of the entire script. Specifically:

[0038] Initialization: Each node randomly initializes its own strategy parameters:

[0039] ;

[0040] Single-step training loop: For each node , repeat the following process until local convergence:

[0041] A. Sampling trajectory:

[0042] ;

[0043] B. Evaluation Rewards:

[0044] ;

[0045] C. Introducing penalty terms for distributed computing:

[0046] Remember each node The generated trajectory is , the track contains several text fragments , then the penalty function is defined as follows:

[0047] ;

[0048] in, More sensitive to repeated punishment; The semantic jump has a greater impact; Length only assists control; repetition penalty :

[0049] ;

[0050] Story skip penalty , based on BERT semantic similarity calculation:

[0051] ;

[0052] in, is BERT or sentence vector cosine similarity;

[0053] Length penalty :

[0054] ;

[0055] in, is the ideal length of a script segment; For the Generated script snippets length;

[0056] Modify the scoring function of the final node of the reward function to become:

[0057] ;

[0058] Gradient strategy formula:

[0059] ;

[0060] Update parameters asynchronously:

[0061] ;

[0062] in, is the learning rate, which is used to control the update step size and is set to 0.0005.

[0063] Preferably, the knowledge tree is constructed using a hierarchical coding mechanism, and the relationship between nodes in each layer is represented by the links between parent and child nodes. The information transmission formula between parent and child nodes is:

[0064] ;

[0065] in, Represents the information vector of the parent node, represents the information vector of the child node, To represent the information transfer function, a linear transformation function is selected. Through the above method, the key information can be extracted and encoded layer by layer.

[0066] Preferably, the script evaluation and feedback closed-loop mechanism grades and scores the generated scripts through preset quantitative evaluation indicators, specifically:

[0067] In terms of originality assessment, a text similarity algorithm is used to compare the generated script with a massive script database to detect the uniqueness and novelty of the script content. For logical considerations, the causal chain of the script plot is deeply analyzed with the help of causal relationship graph construction technology to ensure that the plot development is reasonable and coherent. In terms of artistic evaluation, an emotional dictionary is used to analyze the emotional tendency of the script text and calculate the emotional score of the text. Assuming that the emotional dictionary contains positive and negative emotional words, each word has a corresponding emotional weight. The emotional score calculation formula of the script text is:

[0068] ;

[0069] in, Indicates the words; Indicates the total number of words; Indicates the sentiment score of the word;

[0070] The evaluation results are fed back to the self-learning script generation module in the form of environmental variables to form a closed-loop learning mechanism.

[0071] Therefore, the present invention adopts the above-mentioned RAG-based memory-enhanced script generation agent system, which has the following beneficial effects:

[0072] (1) Using a dictionary of professional terms, a library of ambiguous interpretations, and a knowledge base of script examples, we can achieve a precise understanding of the specific format and structure of the script, ensuring that the generated script meets professional requirements in terms of format, style, and content. Through reinforcement learning and guidance from a quantitative indicator system (such as the number of characters, plot density, etc.), we can effectively improve the originality, logic, and artistry of the script;

[0073] (2) Distributed task decomposition and multi-agent collaboration ensure the effective transfer of information between the various script generation modules, avoiding the problems of plot disconnection and logical confusion that are common in existing technologies. Multi-layer knowledge tree management and long memory storage technology can maintain the coherence of the overall narrative when generating long texts, preventing inconsistencies;

[0074] (3) Adopting adaptive RAG and evaluation feedback mechanisms, the system monitors and adjusts unreasonable content in the generation process in real time, significantly reducing the risk of hallucinations and misunderstandings during the generation process. Coding and data representation technology efficiently condenses key information, enabling the system to more accurately capture user needs and the implicit meaning of the script in long text generation;

[0075] (4) The collaborative work of multiple agents not only improves the efficiency of script generation, but also provides conditions for the system to perform adaptive optimization based on the actual generation results.

[0076] The technical solution of the present invention is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS

[0077] Figure 1 This is a schematic diagram of the structure of the RAG-based memory-enhanced script generation agent system of the present invention;

[0078] Figure 2 This is an overall flow chart of the RAG-based memory-enhanced script generation intelligent agent system of the present invention. DETAILED DESCRIPTION

[0079] The following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but rather merely represents selected embodiments of the present invention. All other embodiments derived by persons of ordinary skill in the art based on the embodiments of the present invention without inventive effort shall fall within the scope of protection of the present invention.

[0080] See also Figure 1-Figure 2 , a memory-enhanced script generation agent system based on RAG, including:

[0081] Data collection and knowledge base construction module, including:

[0082] Construction of a professional terminology dictionary and ambiguous interpretation library: Using web crawler technology, we automatically collect professional terminology, common expressions, and polysemous words related to the script field and establish a standardized interpretation library. This library provides detailed definitions for terms such as "viewpoint," "plot," and "dramatic tension," ensuring the generation module's accurate understanding of professional terminology. It also includes examples of common misreadings found in user feedback to ensure precise word meaning verification.

[0083] For example, "point of view" is defined as the angle and perspective of the storytelling, including first-person, second-person, third-person limited perspective, and third-person omniscient perspective. "Plot" is defined as the series of events in the script connected by causal logic. "Drama tension" is defined as the intrigue and tension created by the conflicts within the plot. Common misreading examples from user feedback are also included to ensure accurate word meaning proofreading. The crawler is implemented using the Python library "BeautifulSoup."

[0084] Script Sample Knowledge Base: This database builds a sample library covering various script types (dramas, films, TV series, etc.), extracting key information such as script format, structure, character settings, and plot development, providing format and style standards for subsequent generation. For example, for a film script, the format includes elements such as scene description, character dialogue, and action instructions; the structure is generally divided into sections such as introduction, development, climax, and conclusion; the character settings include the personality traits and relationships of the protagonist and supporting characters; and the plot development includes key nodes such as the cause, conflict, turning point, and ending.

[0085] When extracting key information, we use a text analysis algorithm to segment the sample script and calculate the term frequency-inverse document frequency (TF-IDF) value of each keyword. The formula is:

[0086] ;

[0087] in, Expressive words In the documentation word frequency in ; Expressive words In the documentation The inverse document frequency in will be saved according to the importance of the word segmentation; the importance is determined according to the TF-IDF value and stored in the knowledge base for the script generation agent to understand and generate the script.

[0088] The script sample knowledge base uses the Redis database for distributed storage.

[0089] Preprocessing: By integrating multi-source knowledge, a comprehensive database of editing experts is constructed to guide the intelligent agent in generating high-quality scripts. Key information extraction is used to condense the data into key points, while data refinement can provide more information.

[0090] Pre-learning and intensive training modules include:

[0091] Multi-knowledge base reinforcement learning: The professional terminology library, ambiguous interpretation library and script sample knowledge base are used as pre-learning modules, and the reinforcement learning algorithm is used to train the generation module. The reinforcement learning algorithm guides the intelligent agent to continuously optimize the strategy by designing a specific reward function, enabling the system to "understand" the specific format and deep structure of the script, solving the problems of existing AI's insufficient understanding of the script format, single generation style, non-standard generated content, and easy misreading and hallucination.

[0092] The design of the reward function is the key to reinforcement learning. The reward function for the script generation task is as follows:

[0093] ;

[0094] in, is the total reward; Reward for the format; Reward for style; For content rewards, 、 、 are the weight coefficients of the three rewards, and ;

[0095] Content Rewards Expressed as:

[0096] ;

[0097] in, Score for high quality; Score for high originality; is an adjustable weight coefficient, set to , indicating that quality and originality are equally important for content;

[0098] High quality score It is divided into three parts:

[0099] ;

[0100] in, is the score of the number of characters (normalized); score for the number of episodes (normalized); score plot density; 、 、 All represent weight coefficients, which are 0.3, 0.3, and 0.4 respectively;

[0101] ;

[0102] ;

[0103] ;

[0104] in, For the density of the plot; the number of major episodes (≥5 people); is the total number of episodes; is the penalty coefficient (set to ); Indicates the The number of characters in each plot; Indicates the maximum number of characters in all plots; Indicates the maximum number of plots specified;

[0105] High originality score This section is the originality score generated by the evaluation model:

[0106] ;

[0107] This score is obtained using the following prompt: Please rate the following script's plot based on its originality. High originality is assigned to novel but logically sound plots, while low originality is assigned to completely repetitive plots. The score ranges from 0 to 1. A relatively innovative example is as follows: ... (script content): Please rate the originality.

[0108] Quantitative indicator design: Editors' requirements for script "high quality" and "high originality" are quantified into specific indicators (such as the number of characters, plot density, and plot point settings). A plot is defined as an independent short story or a dialogue within a small scene. The plot volume is divided into major plots and minor plots based on the number of characters appearing in the plot. A plot is considered a major plot when the number of characters is 5 or more. High quality is quantified by the number of characters, the number of plots, and the density of the plot arrangement (plot density is defined as the number of major plots divided by the number of plots, with a plot density requirement between 0.4 and 0.6). High originality is defined as the originality score of the plot in the evaluation agent. The prompt "Script originality refers to the novelty of the plot. It should be novel but logical. Innovative plots are as follows: xxx (examples from the knowledge base). Please evaluate the innovation" is used to form a script scoring rule, which serves as a goal guide for the subsequent generation process.

[0109] Self-learning script generation module, specifically including:

[0110] Multi-agent Collaborative Generation: Build a generation system composed of multiple agents, each responsible for different script modules (such as character design, plot construction, and scene description). The character design agent uses a personality trait model to assign distinct and coherent personality traits to each character, ensuring consistent behavior. The plot construction agent, based on the plot's logical chain, skillfully sets the plot's beginnings, middles, and endings, precisely controlling the plot's direction. The scene description agent, relying on a spatial environment feature library, renders detailed scenes that fit the plot's atmosphere. Intelligent communication enables information exchange and collaborative work, ensuring the overall script's coherence.

[0111] The multi-module intelligent agent system, comprising a script generation module, a script evaluation module, a multi-source knowledge integration pre-learning module, and a long-term memory storage module, collaborates and communicates with each other to achieve high-quality, standard script generation. During the creative process, the script generation module accesses key information from the long-term memory storage module in real time and sends the generated content to the script evaluation module for evaluation. Feedback from the script evaluation module is then promptly transmitted to the script generation module to guide its creative strategy optimization.

[0112] In the script generation task, we regard the generated script content as a trajectory of the agent in the environment (a sequence of states and actions), and each node To maximize the quality of its story units, the objective function is:

[0113] ;

[0114] in, Indicates the Strategy parameters of each node (used to control the parameters of the model generated by the unit, such as LLM); Indicates that according to the parameters Generate trajectories (i.e., unit story) probability distribution; Reward score of the generated short story unit (such as coherence and creativity score);

[0115] Through the policy gradient theorem, the agent gradually optimizes the script generation strategy. The policy gradient formula for a single generation node is:

[0116] ;

[0117] in, represents the expected cumulative reward, the goal is to make it as large as possible; Indicates the parameters Find the gradient; Indicates about parameters Function gradient; Indicates that in the strategy Among all the trajectories, calculate the weighted average of the contents according to the probability of the trajectory appearing; It is expectation; Represents trajectory According to the current policy parameters The probability distribution of the trajectory generated under obtained by sampling;

[0118] Distributed computing is used to split the long script generation task into multiple small task units, each of which is completed independently. Then, a synthesis algorithm is used to ensure the logical consistency and narrative coherence of the entire script. Specifically:

[0119] Initialization: Each node randomly initializes its own policy parameters (initialization parameters are slightly randomly perturbed to prevent all nodes from being generated identically in the initial stage):

[0120] ;

[0121] Single-step training loop: For each node , repeat the following process until local convergence:

[0122] A. Sampling trajectory (generate a small story unit and generate story content from the strategy by probability):

[0123] ;

[0124] B. Evaluation Rewards (Scores):

[0125] ;

[0126] C. Introducing penalty terms for distributed computing:

[0127] Remember each node The generated trajectory is , the track contains several text fragments , then the penalty function is defined as follows:

[0128] ;

[0129] in, More sensitive to repeated punishment; The semantic jump has a greater impact; Length only assists control; repetition penalty (Text fragments are highly repetitive):

[0130] ;

[0131] Story skip penalty (Semantic discontinuity between front and back), calculated based on BERT semantic similarity:

[0132] ;

[0133] in, is BERT or sentence vector cosine similarity;

[0134] Length penalty (Too short or too long):

[0135] ;

[0136] in, is the ideal script segment length (set at 80-100 words); For the Generated script snippets length;

[0137] Modify the reward function (combined with the penalty term) and the scoring function of the final node becomes:

[0138] ;

[0139] Gradient strategy formula:

[0140] ;

[0141] Parameter updates are performed asynchronously, with each node updating its strategy independently:

[0142] ;

[0143] in, is the learning rate, which is used to control the update step size and is set to 0.0005.

[0144] Long-term memory and knowledge tree management module, specifically including:

[0145] Multi-layer knowledge tree construction: To address the difficulties in generating long scripts and modifying details, a multi-level knowledge tree structure is designed to extract, encode, and store key information layer by layer to form a high-density representation of condensed data. This not only solves the problem of long-term memory storage, but also avoids the illusion phenomenon that occurs during the generation process to a certain extent.

[0146] The knowledge tree is constructed using a hierarchical encoding mechanism. For example, the first-level knowledge tree nodes store the script's macro information, such as theme, genre, and main characters. The second-level nodes store key information for each major plot unit, such as plot objectives and main conflicts. The third-level nodes store detailed information such as specific scene descriptions and character dialogues. The relationship between nodes at each level is represented by links between parent and child nodes. The information transfer formula between parent and child nodes is:

[0147] ;

[0148] in, Represents the information vector of the parent node, represents the information vector of the child node, To represent the information transfer function, a linear transformation function is selected. Through the above method, the key information can be extracted and encoded layer by layer.

[0149] Encoding and Data Representation: The system utilizes advanced encoding technology based on deep neural networks. It converts key script information, such as character traits, plot development clues, and scene descriptions, into high-dimensional data vectors. These data vectors act as the script's "digital fingerprint," preserving the core characteristics of the original information while facilitating rapid retrieval and computation. Advanced encoding technology converts key information into data vectors, enabling the invocation of long-term memory during the generation process and real-time adjustments based on context, ensuring continuity of characters, plot, and narrative.

[0150] The script evaluation and feedback closed-loop mechanism includes:

[0151] Dynamic script scoring system: The generated scripts are graded and scored using preset quantitative evaluation indicators, and the performance of the generated scripts in terms of originality, logic, artistry, etc. is detected in real time. In terms of originality assessment, the system uses advanced text similarity algorithms to compare the generated scripts with massive script databases to accurately detect the uniqueness and novelty of the script content; for logical considerations, the system uses causal relationship graph construction technology to conduct in-depth analysis of the causal chain of the script plot to ensure that the plot development is reasonable and coherent. In terms of artistic judgment, the system uses sentiment analysis algorithms and aesthetic feature extraction models to quantitatively score the depth of emotional expression, the fullness of character creation, and the artistic appeal of dialogues in the script. The sentiment dictionary is used to analyze the sentiment tendency of the script text and calculate the sentiment score of the text. Assume that the sentiment dictionary contains positive sentiment words and negative sentiment words, and each word has a corresponding sentiment weight. The sentiment score calculation formula for the script text is:

[0152] ;

[0153] in, Indicates the words; Indicates the total number of words; Indicates the sentiment score of the word;

[0154] Feedback and Autonomous Evolution: Evaluation results are fed back to the self-learning script generation module in the form of environmental variables. This process goes beyond simply passing scores; rather, the scoring results are deeply analyzed to extract specific improvement suggestions, such as identifying specific deficiencies in plot coherence, reasonable character motivations, or depth of emotional expression. Upon receiving this feedback, the self-learning script generation module deeply integrates it with its previous generation experience and historical memory. This combination of prior generation experience and memory forms a closed-loop learning mechanism, enabling the system to continuously evolve autonomously and improve script quality and creative capabilities.

[0155] Therefore, the present invention utilizes the aforementioned RAG-based memory-enhanced script generation agent system. This not only addresses the existing script generation issues of insufficient format understanding, poor originality, logical incoherence, and illusions, but also achieves intelligent and efficient generation of high-quality scripts through an autonomous evolutionary mechanism and multi-layer memory management, providing strong technical support for guiding actors' performances and further creative work. Furthermore, the present invention independently designs quality assessment dimensions, transforming professional script measurement indicators into quantifiable learning indicators based on the actual needs of editors.

[0156] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit the same. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that they can still modify or replace the technical solutions of the present invention with equivalents, and these modifications or equivalent replacements cannot cause the modified technical solutions to deviate from the spirit and scope of the technical solutions of the present invention.

Claims

1. A memory-enhanced script generation agent system based on RAG, characterized by: include: The data collection and knowledge base construction module collects relevant professional terms, common expressions and polysemous words, and builds a professional term dictionary, an ambiguous interpretation library and a script sample knowledge base; The pre-learning and reinforcement training module uses a professional terminology library, an ambiguous interpretation library, and a script sample knowledge base as pre-learning modules, and uses a reinforcement learning algorithm to train the generation module. At the same time, the editor's requirements for the script are quantified into specific indicators to form a script scoring rule. The reinforcement learning algorithm guides the agent to continuously optimize its strategy by setting a specific reward function. In the script generation task, the reward function is set as: ; in, is the total reward; Reward for the format; Reward for style; For content rewards, 、 、 are the weight coefficients of the three rewards, and ; Self-learning script generation module, a generation system composed of multiple intelligent agents, which jointly realizes script generation; The long-term memory and knowledge tree management module addresses the challenges of generating long scripts and modifying details. A multi-level knowledge tree structure is designed. The knowledge tree is constructed using a hierarchical coding mechanism, extracting, encoding, and storing key information layer by layer to form a high-density representation of condensed data. Advanced coding technology based on deep neural networks is used to convert key information in the script into high-dimensional data vectors. This allows for the invocation of long-term memory during the generation process and allows for real-time adjustments based on context to ensure the continuity of characters, plot, and narrative. The script evaluation and feedback closed-loop mechanism uses preset quantitative evaluation indicators to grade and score the generated scripts, and feeds back to the self-learning script generation module.

2. The RAG-based memory-enhanced scenario generation agent system according to claim 1, characterized in that: The data collection and knowledge base construction module uses crawler technology to automatically collect professional terms, common expressions and polysemous words related to the script, and establish a professional term dictionary and ambiguous interpretation library. Specifically, the crawler uses Python's beautifulsoup library to implement it.

3. The RAG-based memory-enhanced scenario generation agent system according to claim 1, characterized in that: The script sample knowledge base contains a variety of script types. By extracting key information from the script, it provides format and style specifications for subsequent generation. When extracting key information, a text analysis algorithm is used to segment the sample scripts and calculate the word frequency-inverse document frequency value of each keyword. The formula is: ; in, Expressive words In the documentation word frequency in ; Expressive words In the documentation The inverse document frequency in will be saved according to the importance of the word segmentation; The script sample knowledge base uses the Redis database for distributed storage.

4. The RAG-based memory-enhanced scenario generation agent system according to claim 1, characterized in that: The reward functions in the pre-learning and reinforcement training modules include: Content Rewards Expressed as: ; in, Score for high quality; Score for high originality; is an adjustable weight coefficient, set to = =0.5, indicating that quality and originality are equally important for content; High quality score It is divided into three parts: ; in, Score for the number of characters; score for the number of episodes; score plot density; 、 、 All represent weight coefficients, which are 0.3, 0.3, and 0.4 respectively; ; ; ; in, For the density of the plot; is the number of major plots; is the total number of episodes; is the penalty coefficient; Indicates the The number of characters in each plot; Indicates the maximum number of characters in all plots; Indicates the maximum number of plots specified; High originality score This section is the originality score generated by the evaluation model: ; The score is obtained through the following prompt: Please evaluate the plot of the following script from the perspective of originality. Novel but logically reasonable is high originality, and completely repeating the template is low originality. The score range is 0-1.

5. The RAG-based memory-enhanced scenario generation agent system according to claim 1, characterized in that: In the script generation task, the self-learning script generation module regards the generated script content as a trajectory of the intelligent agent in the environment. To maximize the quality of its story units, the objective function is: ; in, Indicates the The strategy parameters of each node; Indicates that according to the parameters Generate trajectories The probability distribution of Represents the reward score of the generated short story unit; Through the policy gradient theorem, the agent gradually optimizes its script generation strategy. The policy gradient formula for a single generation node is: ; in, represents the expected cumulative reward; Indicates the parameters Find the gradient; Indicates about parameters Function gradient; Indicates that in the strategy Among all the trajectories, calculate the weighted average of the contents according to the probability of the trajectory appearing; It is expectation; Represents trajectory According to the current policy parameters The probability distribution of the trajectory generated under obtained by sampling; Distributed computing is used to split the long script generation task into multiple small task units, each of which is completed independently. Then, a synthesis algorithm is used to ensure the logical consistency and narrative coherence of the entire script. Specifically: Initialization: Each node randomly initializes its own strategy parameters: ; Single-step training loop: For each node , repeat the following process until local convergence: A. Sampling trajectory: ; B. Evaluation Rewards: ; C. Introducing penalty terms for distributed computing: Remember each node The generated trajectory is , the trajectory contains several text fragments , then the penalty function is defined as follows: ; in, More sensitive to repeated punishment; The semantic jump has a greater impact; Length only assists control; repetition penalty : ; Story skip penalty , based on BERT semantic similarity calculation: ; in, is BERT or sentence vector cosine similarity; Length penalty : ; in, is the ideal length of a script segment; For the Generated script snippets length; Modify the scoring function of the final node of the reward function to become: ; Gradient strategy formula: ; Update parameters asynchronously: ; in, is the learning rate, which is used to control the update step size and is set to 0.0005.

6. The RAG-based memory-enhanced scenario generation agent system according to claim 1, characterized in that: The knowledge tree is constructed using a hierarchical coding mechanism. The relationship between nodes in each layer is represented by the links between parent and child nodes. The information transmission formula between parent and child nodes is: ; in, Represents the information vector of the parent node, represents the information vector of the child node, To represent the information transfer function, a linear transformation function is selected. Through the above method, the key information can be extracted and encoded layer by layer.

7. The RAG-based memory-enhanced scenario generation agent system according to claim 1, characterized in that: The script evaluation and feedback closed-loop mechanism uses preset quantitative evaluation indicators to grade and score the generated scripts. Specifically: In terms of originality assessment, a text similarity algorithm is used to compare the generated script with a massive script database to detect the uniqueness and novelty of the script content. For logical considerations, the causal chain of the script plot is deeply analyzed with the help of causal relationship graph construction technology to ensure that the plot development is reasonable and coherent. In terms of artistic evaluation, an emotional dictionary is used to analyze the emotional tendency of the script text and calculate the emotional score of the text. Assuming that the emotional dictionary contains positive and negative emotional words, each word has a corresponding emotional weight. The emotional score calculation formula of the script text is: ; in, Indicates the words; Indicates the total number of words; Indicates the sentiment score of the word; The evaluation results are fed back to the self-learning script generation module in the form of environmental variables to form a closed-loop learning mechanism.

Citation Information

Patent Citations

  • Document knowledge question-answering method, document knowledge storage method and document knowledge question-answering device

    CN119669429A

  • Text generation method and device, equipment and storage medium

    CN119719334A