Automatic novel generation system and method based on multi-agent cooperation and dynamic memory updating
By employing a multi-agent collaboration and dynamic memory update approach, the problem of contextual forgetting in the generation of long narrative texts using large language models was solved, achieving high consistency, structure, and controllability in the generation of long novels, thus improving the generation quality and automation level.
Patent Information
- Application Number
- CN202511038739.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-28
- Publication Date
- 2025-11-11
AI Technical Summary
Existing large language models suffer from problems such as inconsistent plot logic, character and setting drift, flattened narrative structure, and uncontrollable content quality when generating long narrative texts due to context window limitations.
By employing a multi-agent collaboration and dynamic memory update approach, and through a persistent memory database and agent collaboration, including planning agents, execution agents, and memory-stabilizing agents, the structured planning, memory update, and text generation of long stories can be achieved.
It achieves consistency between long-term memory and narrative, enhances the structure and depth of the narrative, ensures the controllability and high quality of generated content, and realizes end-to-end automated generation from idea to novel.
Smart Images

Figure CN120930622A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of artificial intelligence and natural language processing technology, and more specifically, to an automated generation system and related methods for generating long, highly consistent, and highly readable narrative texts (such as online novels and scripts). Background Technology
[0002] In recent years, large language models (LLMs) based on the Transformer architecture, such as the GPT (Generative Pre-trained Transformer) series of models, have made groundbreaking progress in natural language understanding and generation tasks. They are able to understand and generate text similar to human writing, demonstrating powerful capabilities in question answering, translation, summarization, and short essay writing.
[0003] However, when these advanced models are directly applied to the creation of long narrative texts that require long-term memory and logical coherence, their inherent limitations become apparent. The core technical challenge stems from the model's "context window" limitation. Current LLM models can only process text sequences of limited length at a time (e.g., thousands to tens of thousands of tokens). For novels of hundreds of thousands or even millions of words, this means that when generating new chapters, the model cannot access and remember earlier plot points, character settings, world-building rules, and foreshadowing that lie outside the context window. This phenomenon can be called "contextual amnesia."
[0004] This forgetting effect leads to a series of problems that seriously affect the quality of the novel:
[0005] (1) Inconsistent plot logic: There may be logical contradictions in the plot. For example, a character who died in the first volume may be "resurrected" and mentioned again in the fifth volume. Carefully laid foreshadowing in the early stages may be completely forgotten in the later stages, and may not be addressed or revealed, resulting in interruption of the narrative thread and loose story structure.
[0006] (2) Setting Drift: A character’s personality, abilities or core motivations change without a reasonable explanation in the plot; the basic physical laws, social structures or power relationships in the world view may also be described inconsistently in the writing, which destroys the internal unity and immersion of the story world.
[0007] (3) Flat narrative structure: Due to the lack of long-term planning ability for the overall structure of the story, the long content generated by LLM often presents itself as a linear account of a series of events. Although the writing is smooth in some parts, it lacks profound thematic evolution, complex character growth arcs and long-term narrative tension.
[0008] (4) The quality of the generated content is difficult to control: Existing methods usually have difficulty in maintaining stable control over the artistic style and narrative rhythm of the generated content, resulting in inconsistent writing quality or a lack of necessary details and emotional rendering at key plot points.
[0009] To alleviate this problem, existing technologies have attempted to employ methods such as sliding windows and text summarization, but these are merely stopgap measures. Sliding windows still lose a significant amount of early information; while simple summarization loses too many details crucial to the plot, failing to meet the high-fidelity memory requirements of complex narratives. Therefore, there is an urgent need in this field for a novel technical solution that fundamentally addresses the issues of memory, consistency, structure, and controllability in the generation of long narrative texts. Summary of the Invention
[0010] The main objective of this invention is to provide an automated novel generation system and method based on multi-agent collaboration and dynamic memory updates, in order to solve the core technical problems of inconsistent plot logic, character and setting drift, flattened narrative structure, and uncontrollable content quality caused by the context window limitation when existing large language models generate long narrative texts.
[0011] To achieve the above objectives, the present invention provides an automated novel generation method, characterized by being implemented through a system comprising a persistent memory database (MDB) and a set of specialized agents, the method comprising the following steps:
[0012] a) Foundation Phase: At least one planning agent generates structured worldview data and a macro-level story outline containing multiple story chapters based on the story ideas input by the user, and stores them in the Memory Database (MDB).
[0013] b) Iterative generation phase: For each chapter to be generated, one or more executing agents, based on context information aggregated from the memory database,
[0014] Generate the text for this chapter.
[0015] c) Memory solidification stage: After the text of each chapter is generated, a historian agent analyzes the newly generated chapter text, extracts structured key intelligence from it, and updates the data in the memory database based on the intelligence to form an updated context containing the new chapter information for use in the generation of subsequent chapters.
[0016] In a preferred embodiment, the memory consolidation stage in step c) further includes: the historian agent calling a Large Language Model (LLM) to parse the chapter text into a structured intelligence data containing a summary of core events, changes in character status, or new conflicts; then, updating the intelligence data to the database, and specifically calling the LLM to integrate the summary of core events into a "World History" entry that summarizes the accumulated plot, so as to generate an updated "World History".
[0017] In a preferred embodiment, the iterative generation stage in step b) further includes: before generating the text, a chief writer agent aggregates a contextual information package from the database that contains at least the current chapter objective, the latest "world history", and the character's state, and generates a structured chapter plan based on this.
[0018] In a preferred embodiment, the iterative generation phase further includes: a writer agent invoking the LLM to generate chapter text based on a chapter plan and via a prompt containing mandatory writing skill instructions.
[0019] In a preferred embodiment, in the foundational stage of step a), an architect agent generates a macro-story outline, wherein each story chapter contains a preset core theme and character development goals.
[0020] The present invention also provides an automated novel generation system, comprising: a persistent memory database (MDB); one or more processors; and instructions stored in processor-accessible memory, which, when executed, cause the processor to implement a set of functionally specialized agents configured to perform the methods described above.
[0021] Compared with the prior art, the present invention has the following significant advantages:
[0022] (1) Achieved true long-term memory and narrative consistency: By introducing a persistent memory database (MDB) and a memory solidification mechanism for the historian's intelligent agent, the system can dynamically and losslessly "remember" all historical plots and settings, fundamentally solving the problem of contextual forgetting and ensuring the high coherence of long narratives.
[0023] (2) Enhanced the structure and depth of the narrative: The architect agent ensured that the development of the story had a clear structure and profound connotation, rather than a simple accumulation of events, by conducting top-down macro planning of the story, which included themes and character arcs.
[0024] (3) Achieved high controllability and high quality in content generation: The writer agent, through specific stylized instructions, made the artistic style, narrative rhythm and quality of detailed descriptions of the generated text highly controllable and stable.
[0025] (4) High degree of automation and modularity: The system decomposes the complex creative process into independent, clearly defined intelligent agent modules, realizing end-to-end automated generation from a high-level idea to a complete novel, and the system is easy to maintain, expand and optimize. Attached Figure Description
[0026] Figure 1 This is a system architecture and workflow diagram of the automated novel generation system proposed in this invention.
[0027] Figure 2 This is a schematic diagram of the context information flow and memory database update in the core loop of this invention, which shows in detail the collaborative relationship and data flow closed loop between the chief screenwriter agent, the writer agent, and the historian agent. Detailed Implementation
[0028] To make the objectives, technical solutions, and advantages of the present invention clearer, the technical solutions of the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0029] System Environment
[0030] In a preferred embodiment of the present invention, the system hardware environment can be a PC, server, or workstation. The software environment is based on Python 3.7 or later, using the SQLAlchemy library as the ORM (Object-Relational Mapping) tool for the Memory Database (MDB), with the underlying database being SQLite or PostgreSQL. Interaction with Large Language Models (LLMs) is performed through their provided APIs, such as OpenAI's GPT-4 or Google's Gemini series models.
[0031] Core data structure definition
[0032] In the Memory Database (MDB), the core table schema is designed to store all the key information from the creation process, as shown in the example below:
[0033] • WorldSettings: (setting_id, category, key, value) - Used to store world settings, such as category = 'Cultivation System', key = 'Realm Level', value = 'Qi Refining, Foundation Establishment, Golden Core'.
[0034] •StoryArcs: (arc_id,arc_name,description,theme,character_goal,turning_point) - Stores macro-level story chapter planning.
[0035] • ForeshadowingTrackers: (tracker_id, description, setup_chapter, expected_reveal_chapter, status) - Stores foreshadowing information.
[0036] The status can be 'to be installed', 'installed', or 'disclosed'.
[0037] •Characters: (character_id, name, description, motivation, current_state_json) - Stores character profiles, where the current_state_json field is used to record the dynamic changes in the character's state.
[0038] CanonicalHistory: (version_id, chapter_number, history_text) - Stores a "world history", where history_text is a continuously updated summary of the cumulative episodes.
[0039] Detailed Workflow Examples
[0040] Reference Figure 1 and Figure 2 Taking the generation of a cultivation novel titled "I Became an Immortal by 'Playing' It" as an example, the workflow of the method provided by this invention is explained.
[0041] Step 1: Foundation Laying Stage (Refer to...) Figure 1 )
[0042] (1) S1.1 - World Building: The user provides a story idea 102 to the system. The WorldBuilderAgent 103 is activated. It sends a series of structured requests to the LLM, such as: "Please generate a 'cultivation system' for this idea, returned in JSON format, containing the levels and breakthrough_conditions fields." The LLM returns {"levels":["Qi Refining","Foundation Building","Golden Core"],
[0043] "breakthrough_conditions":["abundant spiritual energy","flawless state of mind"]}.
[0044] WorldBuilderAgent 103 writes this data to the Memory Database (MDB) 101.
[0045] The WorldSettings table.
[0046] (2) S1.2 - Macro Planning: Architect Agent
[0047] 104 is activated. It reads the worldview from MDB 101 and then instructs the LLM to generate JSON containing StoryArcs and ForeshadowingTrackers. In the outline returned by the LLM, the character_goal of the first chapter, Arc_1, is defined as...
[0048] "From passively accepting fate to initially recognizing one's own abilities and responsibilities," at the same time
[0049] The ForeshadowingTrackers database contains a record: "The pendant the protagonist has worn since childhood seems to be related to the lost 'Origin Civilization,' and its status is 'Pending Installation.'" This data is written into the corresponding table in MDB 101.
[0050] Step 2: Core Loop (Refer to...) Figure 2 (Taking the generation of Chapter 10 as an example)
[0051] Assuming the system has already generated the first 9 chapters, it is about to generate the 10th chapter. Core loop 105 is started.
[0052] (1) S2.1 - Context aggregation and chapter planning: The chief screenwriter agent (ScenaristAgent) 106 is started.
[0053] – It aggregates context information packet C_10 201 from MDB 101. This process includes:
[0054] • Read the target G_arc of Arc_1 from the StoryArcs table.
[0055] • Read the latest “World History” H_9 with version_id 9 from the CanonicalHistory table.
[0056] • Read the current_state_json of the protagonist Li Gou from the Characters table to obtain his latest state S_{char,9}.
[0057] The mystery of the pendant was discovered from the ForeshadowingTrackers table.
[0058] This needs to be processed near this chapter, creating a pending task F_10.
[0059] –ScenaristAgent 106 integrates C_10 201 and issues an instruction to LLM to generate a detailed plan for Chapter 10, P_10 202. This plan will revolve around “the protagonist using a new elixir to save his fellow disciples and sensing the pendant’s unusual activity again.”
[0060] (2) S2.2 - Stylized Chapter Writing: WriterAgent 107 is launched.
[0061] It receives plan P_10 202 and reads the complete worldview knowledge base from MDB 101.
[0062] In the prompt it sends to the LLM, in addition to P_10, there is also a stylization instruction I_style: "When the protagonist senses the pendant's unusual movement, a detailed inner monologue and sensory description of at least 50 words must be used."
[0063] –LLM generates the text T_10 203 for Chapter 10 based on this compound instruction.
[0065] (3) S2.3 - Intelligence extraction and memory solidification: Chronicler Agent 108 is started.
[0066] – Intelligence Extraction: It receives text T_10 203 and requests the LLM to extract intelligence in JSON format J_n = {O_n, ΔS_char, U_n}. The LLM returns J_10 204, where:
[0067] ·O_n: "Li Gou used a pill to save his fellow disciple Zhang San, and in the process, he once again felt the warmth and strange movement of the mysterious pendant."
[0068] ·ΔS_char:[{"character_id":1,"state_change":"
[0069] Mental strength fully restored..."}
[0070] U_n: ["The pendant's unusual behavior is related to the frequency of its spiritual energy usage..."]
[0071] – Memory Update: ChroniclerAgent 108 performs database write operation 205. It updates the current_state_json field of the role in the Characters table based on ΔS_char. Then, it performs the critical history update operation H_10 = f_update(H_9, O_10). It issues an instruction to the LLM: "You are a historian. Please incorporate the following new event '{O_10}' into the end of this history '{H_9}' in an objective and concise manner to form a new complete history." The LLM returns the updated history H_10, which ChroniclerAgent uses to overwrite the record in the CanonicalHistory table in MDB 101. At the same time, the status of "The Mystery of the Pendant" in ForeshadowingTrackers is updated to "Mentioned".
[0072] At this point, the creation and memory solidification of Chapter 10 are complete. When the system begins creating Chapter 11, ScenaristAgent106 will read H_10, which contains all the information from Chapter 10, and the new character status, thus ensuring a seamless transition in the story.
[0073] Other implementation methods
[0074] This invention is not limited to the embodiments described above. For example:
[0075] • Alternative Database Implementation: In another embodiment, the memory database (MDB) can be a graph database (such as Neo4j). This allows for more efficient storage and querying of complex relationships between characters and between characters and factions. When aggregating contexts, the ScenaristAgent can perform graph traversal queries to uncover deeper character relationships and potential conflicts.
[0076] • Alternative implementation of the intelligent agent: In another embodiment, the intelligence extraction module of ChroniclerAgent can adopt a hybrid approach. First, it uses traditional NLP techniques (such as Named Entity Recognition, NER) to quickly extract names of people and places, and then uses LLM for in-depth analysis of relationships and events to improve efficiency and accuracy.
[0077] The present invention also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor on a computer, implements the method described above.
[0078] The above description is merely a preferred embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. An automated novel generation method based on multi-agent cooperation and dynamic memory updating, characterized in that, Includes the following steps: a) Foundation Phase: At least one planning agent generates structured worldview data and a macro-level story outline containing multiple story chapters based on the story ideas input by the user, and stores them in a persistent memory database (MDB). b) Iterative generation phase: For each chapter to be generated, one or more executing agents, based on context information aggregated from the memory database, Generate the text for this chapter; c) Memory Consolidation Phase: After the text of each chapter is generated, a historian agent analyzes the newly generated chapter text and extracts structured key intelligence from it. The data in the memory database is updated based on this intelligence to form an updated context containing new chapter information for use in the generation of subsequent chapters.
2. The method according to claim 1, characterized in that, The memory consolidation stage in step c) further includes: – The historian agent invokes a large language model (LLM) to parse the chapter text into structured intelligence data containing at least one item: a textual summary of the core events of the chapter, state changes of one or more characters, or one or more unresolved new conflicts; The historian agent updates the structured intelligence data to the corresponding data table in the memory database, and calls the large language model to integrate the text summary of the core events into a "World History" entry stored in the database that summarizes the cumulative events up to the previous chapter, so as to generate an updated "World History" for the next chapter to be read.
3. The method according to claim 1 or 2, characterized in that, The iterative generation stage in step b) further includes: – Before generating the chapter text, a chief writer's intelligent agent aggregates a contextual information package from the memory database, which includes at least: the preset goal of the current story chapter, the latest "world history", and the current state of one or more key characters; – The chief screenwriter agent generates a structured chapter plan based on the context information package to guide the text generation of that chapter.
4. The method according to claim 3, characterized in that, The iterative generation phase also includes: – The text of the chapter is generated by a writer agent based on the structured chapter plan and by invoking a large language model through a set of preset prompts containing mandatory writing technique instructions for controlling the style of the output text.
5. The method according to claim 1, characterized in that, The foundation-laying phase in step a) further includes: – An architect-like intelligent agent generates the macro-story outline, in which the data structure of each story chapter, in addition to the plot description, also includes a preset core narrative theme, character growth goals, and key turning points.
6. The method according to claim 1, characterized in that, The macro-story outline generated in step a) also includes one or more long-term foreshadowing trackers, each tracker recording a description of a foreshadowing element and its planned placement and revelation in the story.
7. An automated novel generation system, characterized in that, include: - A persistent memory database (MDB) is configured to store structured worldview data, macro-story outlines, character status data, and a dynamically updated "world history" entry; – One or more processors; - Instructions stored in memory accessible to the processor, which, when executed, cause the one or more processors to implement a set of functionally specialized agents configured to perform the method as described in any one of claims 1 to 6.
8. The system according to claim 7, characterized in that, The group of intelligent agents includes at least: – A historian agent is configured to analyze the chapter text, extract key intelligence, and update the “World History” entries and character status data in the memory database after each chapter is generated; – A chief writer agent is configured to read the latest "world history" and character status data from the memory database before generating each chapter, in order to generate a plan for that chapter; – A writer agent is configured to generate the text for the chapter according to the stated plan.
9. The system according to claim 8, characterized in that, The group of intelligent agents also includes: – An architect agent is configured to generate the macro-story outline, which contains multiple story chapters, each containing a preset core theme and a preset character growth goal.
10. A computer-readable storage medium having a computer program stored thereon, the program, when executed by a processor on a computer, implementing the method as described in any one of claims 1 to 6.