Context awareness type emotion AI agent management method and equipment

By constructing an undirected weighted memory-topic association graph and a multi-dimensional priority value calculation model, the problem of balancing performance and emotional intelligence in emotional AI systems under high concurrency scenarios is solved, achieving efficient memory evokedness and emotional adaptation, and improving system performance and user experience.

CN121884802APending Publication Date: 2026-04-17SHANDONG LANGCHAO SMART CULTURAL TOURISM IND DEV CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SHANDONG LANGCHAO SMART CULTURAL TOURISM IND DEV CO LTD
Filing Date
2025-12-19
Publication Date
2026-04-17

AI Technical Summary

Technical Problem

Existing technologies struggle to efficiently handle requests from a massive number of devices in high-concurrency scenarios, and they also struggle to accurately remember key information during emotional interactions and recall relevant memories at appropriate times, making it difficult for emotional companionship AI systems to balance performance and emotional intelligence.

Method used

The method adopts a context-aware emotion AI agent management approach. By constructing an undirected weighted memory-topic association graph and combining semantic similarity and multi-dimensional priority value calculation models, it dynamically manages roles and states to achieve intelligent memory evokedness and emotion adaptation.

Benefits of technology

It improves system performance and resource utilization efficiency, reduces response latency and maintenance costs, enhances the appropriateness and security of emotional interaction, and ensures the subtlety and personalized experience of AI emotional companionship.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121884802A_ABST
    Figure CN121884802A_ABST
Patent Text Reader

Abstract

The invention discloses a context awareness type emotion AI agent management method and equipment, and mainly relates to the technical field of context awareness. The method and the device are used for solving the problems that a traditional architecture is difficult to meet high-concurrency processing requirements and complex emotional interaction requirements at the same time, the ability of intelligently awakening related memories according to situations lacks, and roles and states of intelligent agents are mixed in the prior art. Comprising the following steps: calculating a priority value of a corresponding memory node according to semantic similarity, a privacy level in the memory node, an emotion weight, emotion data and an emotion conflict coefficient of current emotion data; meanwhile, according to a preset weight updating formula, updating and calculating an edge weight between the preset topic node and the matched memory node; and according to the falling interval of the priority value, determining whether to actively mention the memory node corresponding to the priority value, or mention the memory node corresponding to the priority value when the user mention the preset related topic corresponding to the memory node, or not waking up the memory node.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of context-aware technology, and in particular to a method and device for managing context-aware emotional AI agents. Background Technology

[0002] With the rapid development of artificial intelligence technology, AI smart hardware has evolved from functional voice assistants into personalized companion devices with deep emotional interaction capabilities. Users are no longer satisfied with simple question-and-answer services, but expect to establish a long-term, warm emotional connection with a "digital partner" that has a stable personality, can remember important events, and can provide care at appropriate times. The core competitiveness of this type of emotional companion AI lies in the consistency of its "personality" and the intelligence of its "memory." However, current technology is insufficient to meet these needs.

[0003] Achieving this goal presents a dual challenge to the server-side architecture: on the one hand, the system needs to efficiently handle requests from massive numbers of devices in high-concurrency scenarios, ensuring low latency and high availability; on the other hand, the system must simulate the operation of human memory, accurately remembering key information and "naturally recalling" it when relevant topics arise, rather than mechanically repeating or coldly forgetting. Traditional AI service architectures are clearly inadequate in addressing these challenges.

[0004] Existing technologies often conflate the "role" and "state" of an agent, or employ a simple database loading model, making it difficult to balance performance, cost, and emotional intelligence. Furthermore, for important information provided by users (such as "I've lost my job"), existing systems either mention it as a fixed context in every conversation, which sounds abrupt and may cause emotional harm; or they are only valid in the current session and forgotten afterward, which seems indifferent. There is a lack of a comprehensive solution that can both efficiently manage state and intelligently recall memories. Summary of the Invention

[0005] This application provides a context-aware emotional AI agent management method and device to solve the problems that traditional architectures cannot simultaneously meet the needs of high-concurrency processing and complex emotional interaction, lack the ability to intelligently recall relevant memories based on context, and that existing technologies confuse the "role" and "state" of the agent.

[0006] Firstly, this application provides a method for managing context-aware emotion-based AI agents, the method comprising: When the server starts, it loads all role templates from the preset shared role pool into the local Redis; each role template corresponds to a unique role ID; it extracts memory nodes from the long-term memory (LCM) storing current user interaction data; it calculates the initial edge weights between memory nodes and preset topic nodes; and it constructs an undirected weighted memory-topic association graph based on memory nodes, preset topic nodes, and initial edge weights. When a user initiates a conversation, the server assigns a unique session_id to the current session; it loads the corresponding role template from the local Redis based on the user's set role ID; it generates a unique session identifier based on the session_id and the current user ID; and it retrieves the user session data input for the current unique session identifier to identify the user. The conversation data includes preset topic nodes, sentiment data, and conversation keywords. Based on the preset topic nodes, their corresponding edge weights, the current user ID, and conversation keywords, matching memory nodes and their corresponding semantic similarities are extracted from the memory-topic association graph. Priority values ​​for corresponding memory nodes are calculated based on semantic similarity, privacy level, sentiment weight, sentiment data, and the sentiment conflict coefficient of the current sentiment data. Simultaneously, the edge weights between preset topic nodes and matching memory nodes are updated according to the preset weight update formula. Based on the priority value's range, it is determined whether to actively mention the memory node corresponding to the priority value, mention the memory node corresponding to the priority value when the user mentions a preset related topic, or not to activate the memory node.

[0007] In one implementation of this application, before fully loading all role templates from the preset shared role pool to the local Redis, the method further includes: Configure JSON-formatted role templates in the preset shared role pool; the role template includes: a unique role identifier, basic role personality configuration, role interaction style configuration, and a sensitive topic avoidance list; the basic role personality configuration includes: personality type, knowledge base domain accessed by the role, and preset output requirement criteria; the role interaction style configuration includes: language style template and tone mapping rules; When a new or modified role is obtained from the preset shared role pool by calling the API through the preset role, the new or modified role template will be updated to the preset shared role pool.

[0008] In one implementation of this application, before retrieving memory nodes from the long-term memory storing current user interaction data, the method further includes: A MongoDB sharded cluster is used to distribute and store single memory data in JSON format containing user session data. Each memory data includes: a unique identifier consisting of user ID, event type, and sequence number; the lifecycle of the single memory data; memory information containing user session data; and attribute fields that support context triggering. Furthermore, the lifecycle of a single memory record includes the memory creation time, the most recent update time, the most recent access time, and the cumulative number of wake-ups; The memory information includes user session data and key entities involved in the user session data; key entities include: extracted keywords and time information; The attribute fields supporting context-triggered events include: topic tags, sentiment weight, privacy level, expiration flag, and expiration time; topic tags include preset core keywords from the extracted keywords; Extract memory nodes from the long-term memory that stores current user interaction data, specifically including: Based on the unique identifier of a memory record, user ID, topic tag, sentiment weight, privacy level, and most recent access time in a single memory record, a corresponding memory node is established; each single memory record corresponds one-to-one with a memory node; and each memory node also includes: a unique identifier for the memory node.

[0009] In one implementation of this application, when a new single memory data entry appears in the long-term memory, a corresponding memory node is generated, and the initial edge weights are calculated and updated to the undirected weighted memory-topic association graph. When a single piece of memory data in the long-term memory is modified, the data corresponding to the memory node is automatically updated; After each round of dialogue, when a memory node is awakened, the last access time of the memory node is updated.

[0010] In one implementation of this application, before calculating the initial edge weights between the memory node and the preset topic node, the method further includes: Several topic nodes are preset; among them, a topic node includes at least: a unique identifier for the topic node, a topic name, preset topic keywords, the number of times the current topic node is awakened by associated memories within a preset time period, the creation time, and the update time; Calculate the initial edge weights between the memory node and the preset topic node, specifically including: When a memory node is first added to the database, the semantic similarity between the topic tags in the memory node and the preset topic keywords in the topic node is calculated; where the semantic similarity ∈ [0,1]; Determine the semantic similarity as the initial edge weight, and delete the initial edge weight and the corresponding edge that are less than the preset weight threshold.

[0011] In one implementation of this application, user session data is obtained by inputting the current unique session identifier, and preset topic nodes, sentiment data, and session keywords involved in the user session data are identified, specifically including: The NLU module is used to identify preset topic nodes, sentiment data, and conversation keywords corresponding to user conversation data from several preset topic nodes.

[0012] In one implementation of this application, based on preset topic nodes, the edge weights corresponding to the preset topic nodes, the current user ID, and conversation keywords, matching memory nodes and their corresponding semantic similarities are extracted from the memory-topic association graph; based on the semantic similarity, the privacy level, sentiment weight, and emotion data in the memory nodes, the priority value of the corresponding memory nodes is calculated, specifically including: Query all memory nodes connected to the preset topic node; then filter the memory node set corresponding to the current user ID from all memory nodes; determine the memory nodes in the memory node set as the matching memory nodes; Calculate the semantic similarity between the current session keywords and the topic tags of each memory node in the memory node set; Extract the emotional weight and privacy level from the matched memory nodes; Through the formula: Priority value = α × emotional_weight + β × similarity_score - γ × privacy_coefficient - δ × emotion_conflict_coefficient; Calculate the priority value; Where α represents the preset emotional weight coefficient, β represents the preset semantic similarity coefficient, γ represents the preset privacy coefficient, δ represents the emotional conflict coefficient, emotional_weight represents the emotional weight, similarity_score represents the semantic similarity, privacy_coefficient represents the preset value corresponding to the privacy level, and emotion_conflict_coefficient represents the emotional conflict coefficient. When the emotional data is preset negative and the memory node is preset negative event, the emotional conflict coefficient is 0.5; otherwise, the emotional conflict coefficient is 0.

[0013] In one implementation of this application, the edge weights between the preset topic node and the matched memory node are updated according to a preset weight update formula, specifically including: In each round of dialogue, the matching memory nodes and the preset topic nodes that trigger the matching are determined; According to the formula: Edge weight = original edge weight × 0.9 + new similarity × 0.1, update edge weight; The new similarity is based on the preset topic nodes, the edge weights corresponding to the preset topic nodes, the current user ID, and the conversation keywords. It is extracted from the memory-topic association graph and the semantic similarity of the matching memory nodes and the corresponding semantic similarity.

[0014] In one implementation of this application, based on the priority value's falling range, it is determined whether to actively mention the memory node corresponding to the priority value, or mention the memory node corresponding to the priority value when the user mentions a preset related topic corresponding to the memory node, or not to wake up the memory node, specifically including: When the priority value is greater than the preset first threshold, the memory node corresponding to the active mention priority value is determined, the single memory data corresponding to the memory node is extracted from the long-term memory bank, and the single memory data is input into the AI ​​agent as context information and current user session data to obtain a response combined with the single memory data; When the priority value is less than or equal to the preset first threshold and greater than the preset second threshold, when the user mentions the preset related topic corresponding to the memory node, the memory node corresponding to the priority value is mentioned. The single memory data corresponding to the memory node is extracted from the long-term memory bank, and the single memory data is used as context information and current user session data to input into the AI ​​agent to obtain a response combined with the single memory data. When the priority value is less than or equal to the preset second threshold, the memory node is not woken up.

[0015] Secondly, this application provides a context-aware emotion-based AI agent management device, the device comprising: processor; And a memory containing executable code, which, when executed, causes the processor to perform a context-aware emotion AI agent management method as described above.

[0016] As can be seen from the above technical solutions, this application has the following advantages: By constructing an undirected weighted graph containing topic nodes and memory nodes, and calculating the semantic similarity between topics and memories, edge weights are generated by combining historical association frequency (edge ​​weights ≥ 0.6 are included in the match). The context triggering engine takes the current topic vector and user emotion tag as input, calls the graph query to match memories, and substitutes them into a priority formula that integrates emotional weight, semantic similarity, privacy level and emotional conflict to dynamically determine the active / passive / non-awakening strategy of the memory, thereby realizing intelligent memory waking across keywords.

[0017] Furthermore, by introducing a role-state separation architecture, the static role templates of the intelligent agent are decoupled from the dynamic dialogue states, enabling cross-user sharing of role templates. This mechanism fundamentally avoids the huge memory overhead caused by repeatedly loading the same role configuration for each user instance, effectively solving the technical bottleneck of linearly increasing memory consumption with the user scale in traditional long-connection or full-state loading modes. Under the same hardware resource configuration, the number of concurrent users supported by the system is increased by an order of magnitude, significantly reducing the computing resource consumption per user, thereby greatly reducing server deployment and maintenance costs.

[0018] By introducing a multi-dimensional priority value calculation model, the system achieves precise control and emotional adaptation of memory recall. This method integrates parameters such as semantic similarity, privacy level, emotional weight, real-time emotional data, and emotional conflict coefficient to calculate the priority value of each memory node and determine the recall strategy based on a threshold range. This mechanism directly overcomes the shortcomings of existing technologies, such as inappropriate timing of memory mentions or emotional conflicts. For example, memories with high priority and low emotional conflict will be proactively mentioned at appropriate times, while sensitive information will be recalled based on privacy level restrictions. This avoids the emotional harm that may be caused by abrupt insertion and ensures the appropriateness of emotional interaction, thereby enhancing the subtlety and security of AI emotional companionship.

[0019] By separating role templates from session states, system performance and resource utilization efficiency are effectively improved. At server startup, all role templates are loaded into the local Redis instance. During a session, only the corresponding template needs to be loaded quickly by role ID, and a unique session identifier is generated using session_id and user ID. This architecture decouples the relatively static role definitions from the dynamic session states, avoiding the resource duplication and performance bottlenecks caused by mixing roles and states in traditional systems. The direct benefit is a significant reduction in response latency under high concurrency scenarios, improved system throughput and availability, and the provision of stable and efficient emotional interaction services for a massive number of user devices.

[0020] Furthermore, by dynamically updating the edge weights of the memory-topic association graph, continuous optimization of memory associations is achieved. During each conversation interaction, the system adjusts the connection strength between topic nodes and memory nodes in real time according to a preset weight update formula. This design allows the system to autonomously evolve its association model based on actual interaction data, and the accuracy of memory recall continuously improves with increased usage frequency. This mechanism directly solves the problems of fixed memory associations and lack of adaptive evolution in traditional systems, endowing the AI ​​agent with the ability to continuously learn user preferences and interaction patterns, thereby ensuring a personalized and consistent experience in long-term emotional companionship. Attached Figure Description

[0021] To more clearly illustrate the technical solution of the present invention, the accompanying drawings used in the description will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0022] Figure 1 This is a flowchart of a context-aware emotion AI agent management method provided in an embodiment of this application.

[0023] Figure 2 This is a schematic diagram of the internal structure of a context-aware emotion AI intelligent agent management device provided in an embodiment of this application. Detailed Implementation

[0024] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0025] Those skilled in the art should understand that the embodiments described below are merely preferred embodiments of this disclosure and do not imply that this disclosure can only be implemented through these preferred embodiments. These preferred embodiments are merely used to explain the technical principles of this disclosure and are not intended to limit the scope of protection of this disclosure. Based on the preferred embodiments provided by this disclosure, all other embodiments obtained by those skilled in the art without creative effort should still fall within the scope of protection of this disclosure.

[0026] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.

[0027] The technical solutions proposed in the embodiments of this application will be described in detail below with reference to the accompanying drawings.

[0028] The embodiment provides a context-aware emotion-based AI agent management method, such as Figure 1 As shown in the embodiments of this application, the method mainly includes the following steps: Step 110: When the server starts, load all role templates from the preset shared role pool to the local Redis.

[0029] Each character template corresponds to a unique character ID.

[0030] In some embodiments, before fully loading all role templates from a preset shared role pool to local Redis, the method further includes: Configure JSON-formatted role templates in the preset shared role pool; the role template includes: a unique role identifier, basic role personality configuration, role interaction style configuration, and a sensitive topic avoidance list; the basic role personality configuration includes: personality type, knowledge base domain accessed by the role, and preset output requirement criteria; the role interaction style configuration includes: language style template and tone mapping rules; When a new or modified role is obtained from the preset shared role pool by calling the API through the preset role, the new or modified role template will be updated to the preset shared role pool.

[0031] It should be noted that when the server starts, all role templates are fully loaded into Redis (loading 100+ role types takes less than 5 minutes); when adding or modifying roles, incremental updates are achieved through the role's API (no service restart required), with a single role template update taking less than 100ms. For example, to add a "Career Mentor" role, only JSON data in the above format needs to be uploaded, and the API automatically synchronizes to all Redis nodes, completing the full cluster effect within 10 seconds.

[0032] Those skilled in the art will understand that all users with the same role only store the role ID (uuid), without loading the complete template. For example, if 100,000 users use the "Gentle Best Friend" role, only a few hundred KB of role-related data is required, which reduces memory usage by 99.9% compared to the traditional architecture (100,000 × 500KB = 50GB), and the memory usage of a single service node is ≤2GB.

[0033] Step 120: Extract memory nodes from the long-term memory that stores current user interaction data; calculate the initial edge weights between memory nodes and preset topic nodes; construct an undirected weighted memory-topic association graph based on memory nodes, preset topic nodes, and initial edge weights.

[0034] It should be noted that memory nodes must include at least a memory identifier, user identifier, topic tags, sentiment weight, and privacy level. Preset topic nodes must include at least a topic identifier, topic name, and preset topic keywords. The long-term memory repository stores personalized information of long-term value to users (such as important events and preferences). It uses a MongoDB sharded cluster for distributed storage, supports horizontal scaling, and a single shard can store 100 million memory records with a query response time of <50ms. After the user provides information, the NLU module automatically extracts the memory content (e.g., extracting the event description and key entities from "I lost my job today, I'm so sad"), generates topic tags (based on a pre-trained topic classification model), calculates the sentiment weight (referencing the sentiment dictionary: unemployment = 0.9), and sets the default privacy level to "middle" (users can manually adjust this to "high" or "low" via the app). Finally, the data is written to MongoDB in the aforementioned JSON format, with a single memory write time of <300ms. The backup mechanism employs a "full backup every morning at midnight + incremental backup every 5 minutes" to ensure that user memories are not lost.

[0035] More specifically, before retrieving memory nodes from the long-term memory that stores current user interaction data, the method further includes: A MongoDB sharded cluster is used to distribute and store single memory data in JSON format containing user session data. Each memory data includes: a unique identifier consisting of user ID, event type, and sequence number; the lifecycle of the single memory data; memory information containing user session data; and attribute fields that support context triggering. Furthermore, the lifecycle of a single memory record includes the memory creation time, the most recent update time, the most recent access time, and the cumulative number of wake-ups; The memory information includes user session data and key entities involved in the user session data; key entities include: extracted keywords and time information; The attribute fields supporting context-triggered events include: topic tags, sentiment weight, privacy level, expiration flag, and expiration time; topic tags include preset core keywords from the extracted keywords; This includes extracting memory nodes from the long-term memory that stores current user interaction data, specifically including: Based on the unique identifier of a memory record, user ID, topic tag, sentiment weight, privacy level, and most recent access time in a single memory record, a corresponding memory node is established; each single memory record corresponds one-to-one with a memory node; and each memory node also includes: a unique identifier for the memory node.

[0036] In addition, when a new single memory data is added to the long-term memory, a corresponding memory node is generated, and the initial edge weights are calculated and updated to the undirected weighted memory-topic association graph. When a single piece of memory data in the long-term memory is modified, the data corresponding to the memory node is automatically updated; After each round of dialogue, when a memory node is awakened, the last access time of the memory node is updated.

[0037] The method further includes the following steps before calculating the initial edge weights between the memory node and the preset topic node: Several topic nodes are preset; among them, a topic node includes at least: a unique identifier for the topic node, a topic name, preset topic keywords, the number of times the current topic node is awakened by associated memories within a preset time period, the creation time, and the update time; Calculate the initial edge weights between the memory node and the preset topic node, specifically including: When a memory node is first added to the database, the semantic similarity between the topic tag in the memory node and the preset topic keyword in the topic node is calculated; where the semantic similarity ∈ [0,1] (for example, the core text of “mem_job_loss_user123_001” is “user became unemployed in May 2025”, and the semantic similarity with the description of “topic_career_001”, “career-related topics, including unemployment”, is 0.85, so the initial edge weight = 0.85). Semantic similarity is determined as the initial edge weight. Edges with initial weights less than the preset weight threshold and their corresponding edges are deleted (for example, the semantic similarity between "mem_job_loss_user123_001" and "topic_weather_001" (weather topic) is 0.12, and the edge weight = 0.12 < 0.6, so they are not included in the matching range to avoid users accidentally recalling their unemployment memories when talking about the weather).

[0038] Further examples of adding memory nodes: User inputs: "I lost my job today, I'm so sad" → The client transmits the text to the server; NLU processing: Identify the emotion "sadness" (confidence 0.92), extract the core text "User lost their job on May 10, 2025, feeling sad", generate topic_tags=["career","employment","negative_event"], calculate emotional_weight=0.9 (high negative emotional event), and set privacy_level="high" by default; LTM write: Generate memory_id="mem_job_loss_user123_001" according to the JSON format mentioned above, and write it to MongoDB shard 2 (route by user_id hash), with a time of <300ms; Graph update: Create a memory node “memory_mem_job_loss_user123_001” in Neo4j, establish an edge with “topic_career_001” and “topic_employment_001”, and calculate the initial weight (the semantic similarity with “topic_career_001” is 0.85, and the initial weight = 0.85).

[0039] Step 130: When a user initiates a conversation, the server assigns a unique session_id to the current session; loads the corresponding role template from the local Redis based on the role ID set by the user; and generates a unique session identifier based on the session_id and the current user ID.

[0040] It should be noted that the data involved in generating the unique session identifier is stored in the working memory area. The working memory area is a module that stores temporary information of the current session, implemented using local Redis (one instance per service node). A unique session identifier is generated when the session is created and is automatically cleaned up 30 minutes after the session ends to avoid memory redundancy. After each round of dialogue, the dialogue context cache (retaining the last 5-10 rounds, configurable) and the real-time topic queue (retaining the last 3 topics) are automatically updated. The context triggering engine outputs a memory wake-up candidate list each round, overwriting old data. After the session ends (user exits or no interaction for 30 minutes), Redis automatically triggers expiration cleanup, synchronizing only the single memory data involved in the memory wake-up candidate list memory node to the long-term memory (updating the most recent access time and cumulative wake-up count), ensuring efficient memory utilization—the unique session identifier of a single user occupies ≤5KB of memory, and 100,000 concurrent sessions only occupy 500MB of memory.

[0041] Step 140: Obtain the user conversation data input by the current unique conversation identifier, and identify the preset topic nodes, sentiment data, and conversation keywords involved in the user conversation data; based on the preset topic nodes, the edge weights corresponding to the preset topic nodes, the current user ID, and the conversation keywords, extract the matching memory nodes and their corresponding semantic similarities from the memory-topic association graph; calculate the priority value of the corresponding memory node according to the semantic similarity, the privacy level in the memory node, the sentiment weight, the sentiment data, and the sentiment conflict coefficient of the current sentiment data; at the same time, update the edge weights between the preset topic nodes and the matching memory nodes according to the preset weight update formula.

[0042] It's important to note that the memory-topic association graph is the core data structure for achieving "cross-keyword memory recall." It's stored using the Neo4j graph database and establishes a deep association between memories and semantic topics through an undirected weighted graph design of "topic nodes - memory nodes - edge weights," supporting millisecond-level adjacent node queries. Preset topic nodes represent semantic topics in the dialogue (such as "career" and "birthday"), with over 500 preset basic topic types. Dynamic additions are supported (e.g., automatically adding the topic "pet_deworming" when a user mentions "pet deworming"). Furthermore, in the node visualization design, preset topic nodes can be circular (node ​​size increases with topic popularity), and memory nodes can be square (node ​​color represents privacy level: red = high, yellow = middle, green = low), facilitating manual maintenance and troubleshooting.

[0043] In some embodiments, user session data input by the current unique session identifier is obtained, and preset topic nodes, sentiment data, and session keywords involved in the user session data are identified, specifically including: The NLU module is used to identify preset topic nodes, sentiment data, and conversation keywords corresponding to user conversation data from several preset topic nodes.

[0044] Based on preset topic nodes, their corresponding edge weights, the current user ID, and conversation keywords, matching memory nodes and their corresponding semantic similarities are extracted from the memory-topic association graph. The priority value of the corresponding memory node is calculated based on semantic similarity, the privacy level, sentiment weight, and emotion data within the memory node, specifically including: Query all memory nodes connected to the preset topic node; then filter the memory node set corresponding to the current user ID from all memory nodes; determine the memory nodes in the memory node set as the matching memory nodes; Calculate the semantic similarity between the current session keywords and the topic tags of each memory node in the memory node set; Extract the emotional weight and privacy level from the matched memory nodes; Through the formula: Priority value = α × emotional_weight + β × similarity_score - γ × privacy_coefficient - δ × emotion_conflict_coefficient; Calculate the priority value; Wherein, α represents the preset emotional weight coefficient, β represents the preset semantic similarity coefficient, γ represents the preset privacy coefficient, δ represents the emotional conflict coefficient, emotional_weight represents emotional weight, similarity_score represents semantic similarity, privacy_coefficient represents the preset value corresponding to the privacy level, and emotion_conflict_coefficient represents the emotional conflict coefficient. When the emotional data is preset negative (e.g., sadness, anxiety, anger) and the memory node is preset negative event (e.g., unemployment, illness, breakup), the emotional conflict coefficient is 0.5; otherwise, the emotional conflict coefficient is 0.

[0045] The coefficients range as follows: α = 0.4-0.6 (emotional weight has the highest proportion), β = 0.2-0.3 (semantic similarity is the second highest), γ = 0.1-0.3 (privacy coefficient increases with level), δ = 0.05-0.2 (emotional conflict coefficient); the privacy coefficients correspond to high = 0.5, middle = 0.3, and low = 0.1; the emotional conflict coefficient is 0.5 (the user's current emotion is negative and the memory is of a negative event) or 0 (other cases).

[0046] For example, for the user "mem_job_loss_user123_001", the emotional_weight=0.9, similarity_score=0.82, privacy_level=high (coefficient 0.5), and the user's emotion is anxiety (negative, conflict coefficient 0.5). Taking α=0.4, β=0.3, γ=0.3, and δ=0.2, the priority is 0.4×0.9+0.3×0.82-0.3×0.5-0.2×0.5=0.36+0.246-0.15-0.1=0.356.

[0047] Specifically, the edge weights between the preset topic nodes and the matched memory nodes are updated according to the preset weight update formula, including: In each round of dialogue, the matching memory nodes and the preset topic nodes that trigger the matching are determined; According to the formula: Edge weight = original edge weight × 0.9 + new similarity × 0.1, update edge weight; The new similarity is based on preset topic nodes, the edge weights corresponding to preset topic nodes, the current user ID, and conversation keywords. It extracts the matching memory nodes and the semantic similarity of the corresponding semantic similarity from the memory-topic association graph (for example, the original weight of "mem_job_loss_user123_001" and "topic_career_001" is 0.85. In a certain round of dialogue, the user talks about "interview" (the topic is still "career"), and the new similarity is 0.91. Then the updated weight = 0.85×0.9+0.91×0.1=0.765+0.091=0.856, ensuring that the weight of frequently associated memories gradually increases, making them easier to match in the future).

[0048] Step 150: Based on the priority value's falling range, determine whether to actively mention the memory node corresponding to the priority value, or mention the memory node corresponding to the priority value when the user mentions a preset related topic corresponding to the memory node, or not to wake up the memory node.

[0049] Based on the priority value's falling range, determine whether to proactively mention the memory node corresponding to the priority value, or mention the memory node corresponding to the priority value when the user mentions a preset related topic corresponding to the memory node, or not to activate the memory node. Specifically, this includes: When the priority value is greater than the preset first threshold, the memory node corresponding to the active mention priority value is determined, the single memory data corresponding to the memory node is extracted from the long-term memory bank, and the single memory data is input into the AI ​​agent as context information and current user session data to obtain a response combined with the single memory data; When the priority value is less than or equal to the preset first threshold and greater than the preset second threshold, when the user mentions the preset related topic corresponding to the memory node, the memory node corresponding to the priority value is mentioned. The single memory data corresponding to the memory node is extracted from the long-term memory bank, and the single memory data is used as context information and current user session data to input into the AI ​​agent to obtain a response combined with the single memory data. When the priority value is less than or equal to the preset second threshold, the memory node is not woken up.

[0050] For example, the mention strategy is determined based on the priority score: Priority ≥ 0.8 → Active mention (the memory is naturally integrated into the reply, such as "I remember you were unemployed before, good luck with your interview now"); 0.6 ≤ Priority < 0.8 → Passive response (reply only when the user mentions the relevant topic, such as responding only when the user asks "Do you remember me being unemployed?"); < 0.6 → No evoked response (not included in the reply consideration). Simultaneously, if the user actively mentions the memory (such as "Do you remember me being unemployed before?"), the priority automatically increases to 0.9, forcibly triggering a passive response to ensure that the user's perceived memory is retained.

[0051] Based on the description above, the implementation can be specifically as follows: Scenario 1: Unemployment relief for users: System initialization phase; After the server starts, Redis loads the "Gentle Best Friend" role template (JSON format, which is selected by the user). The role_id is a unique identifier for the role, which is "role_gentle_girlfriend_001". Import basic preset topic nodes into the Neo4j graph, including "topic_career_001" (described as "career-related topics, including work, unemployment, and interviews"), "topic_health_001", etc., totaling 500+ topics; The MongoDB sharded cluster is started, and a composite index (user_id user ID + topic_tags topic tags) is created to ensure query efficiency.

[0052] Memory storage phase (T=0, user first informs of unemployment); User inputs: "I lost my job today, I'm so sad" → The client transmits the text to the server; NLU processing: Identify the emotion "sadness" (confidence 0.92), extract the core text "User lost their job on May 10, 2025, feeling sad", and generate: topic_tags = ["career", "employment", "negative_event"], emotional_weight = 0.9 (high emotional weight for negative events), privacy_level = "high" by default; LTM write: Generate a memory_id in the JSON format described above, remembering the unique identifier = "mem_job_loss_user123_001", and write it to MongoDB shard 2 (route by user_id hash). Graph Update: Create a unique identifier for the memory node “memory_mem_job_loss_user123_001” in Neo4j, establish an edge with “topic_career_001” and “topic_employment_001”, and calculate the initial weight (the semantic similarity with “topic_career_001” is 0.85, so the initial weight = 0.85).

[0053] Daily interaction phase (T=7 days, users discuss work stress): Session creation: User enters "It's so hard to find a job lately, I'm under so much pressure" → Server assigns session_id="session456" → Loads the role template "role_gentle_girlfriend_001" → Initializes a unique session identifier (wm_id="wm_session456_user123", context_cache is empty, real_time_topic_queue is empty); NLU processing: Identify the topic "career" (generate topic_vector) and the emotion "anxiety" (confidence score 0.88) → output to the context triggering engine; Contextual Trigger: ① Association matching: Call the graph to query the adjacency memory of “topic_career_001” and “user123” → get “mem_job_loss_user123_001”, edge weight = 0.85 (not updated), similarity_score = 0.82 (semantic similarity between the current text and the memory); ② Priority calculation: α=0.4, β=0.3, γ=0.3, δ=0.2, privacy_coefficient=0.5 (high), emotion_conflict_coefficient=0.5 (anxiety + unemployment negative) → priority=0.4×0.9+0.3×0.82-0.3×0.5-0.2×0.5=0.36+0.246-0.15-0.1=0.356 (<0.6); ③ Wake-up decision: Determine "Do not wake up", and output memory_candidate_list to the unique session; Response generation: NLG combines character style (gentle comfort) and context_cache of the unique conversation (first round of dialogue) → generates the response "The job search process can indeed be anxiety-inducing. Don't put too much pressure on yourself. Take it slow. You can share your progress with me." Session Update: Unique session update context_cache (conversation context cache: the last 5 rounds of conversation, adding the current round of conversation), real_time_topic_queue real-time topic queue = ["career"], memory_candidate_list → LTM update "mem_job_loss_user123_001" last_accessed_time = "2025-05-1710:00:00" (actual update time), access_count is still 0.

[0054] Active reactivation phase (T=30 days, user requests "new interview"): User input: "I have an interview tomorrow and I'm a little nervous" → NLU identifies the topic "career" and the emotion "nervous" (confidence 0.85); Contextual Trigger: ① Association matching: Get “mem_job_loss_user123_001”, similarity_score semantic similarity = 0.91 (semantic similarity between “interview” and “unemployment”); ② Priority calculation: emotion_conflict_coefficient=0 (tense non-negative conflict) → priority=0.4×0.9+0.3×0.91-0.3×0.5-0.2×0=0.36+0.273-0.15=0.483 (<0.6); ③ Awakening Decision: "Don't awaken," reply with "It's normal to be nervous before an interview. You can prepare for common questions first and believe in your abilities." User asks, "Do you remember when I was unemployed?" → NLU recognizes the active mention signal → priority is automatically increased to 0.9 → memory is awakened, NLG generates a reply, "Of course I remember, you were very sad back then, it's great to have an interview opportunity now, good luck!" → unique session updates memory_candidate_list's mention_strategy to "passive" → LTM updates access_count=1, graph edge weights are updated to 0.85×0.9+0.91×0.1=0.856.

[0055] Scenario 2: User birthday reminder: Memory storage stage: User input: "My birthday is June 1st" → NLU extracts the core text "User's birthday is June 1st", topic_tags=["birthday","festival"], emotional_weight=0.9 (positive high emotional event), privacy_level="low" (coefficient 0.1). LTM write: Generate memory_id="mem_birthday_user123_001", and in the JSON format, the key_entities of the content_fields are set to {"event_type":"birthday","time":"June 1st"}, and write it to MongoDB shard 2; Graph update: Create a memory node “memory_mem_birthday_user123_001” and establish an edge with “topic_birthday_001”, with an initial weight of 0.95 (semantic similarity 0.95).

[0056] Active wake-up phase (June 1st, when users chat about the weather): User input: "The weather is so nice today" → NLU identifies the topic "weather" (topic_vector) and the emotion "pleasant" (confidence 0.9); The system triggers a "time-triggered mechanism" (in parallel with context-triggered mechanisms): detects the current date "June 1st" → matches the key_entities.time of "mem_birthday_user123_001" in the LTM → triggers additional priority calculation; Priority calculation: α=0.5 (positive events increase the weight of emotional impact), β=0.3, γ=0.1, δ=0.05, similarity_score=0.1 (similarity between weather and birthday), added "time matching bonus = 0.2" → priority = 0.5×0.9+0.3×0.1+0.2×1-0.1×0.1=0.45+0.03+0.2-0.01=0.67 (≥0.6); Awakening Decision: "Actively Mention" → NLG combines the character's style (gentle best friend, with a blessing tone) to generate a reply such as "The weather is so nice today, perfect for going out~ Oh, and happy birthday! Wishing you a day full of joy"; Subsequent updates: LTM updated access_count=1, graph edge weights updated to 0.95×0.9+0.1×0.1=0.855+0.01=0.865, topic_birthday_001 popularity increased by 1.

[0057] The above are method embodiments of this application. Based on the same inventive concept, this application also provides a context-aware emotion AI intelligent agent management device. Figure 2 As shown, the device includes: a processor; and a memory storing executable code thereon, which, when executed, causes the processor to perform a context-aware emotion AI agent management method as described in the above embodiments.

[0058] Specifically, when the server starts, it loads all role templates from the preset shared role pool into the local Redis; each role template corresponds to a unique role ID; it extracts memory nodes from the long-term memory (LCM) storing current user interaction data; it calculates the initial edge weights between memory nodes and preset topic nodes; and it constructs an undirected weighted memory-topic association graph based on the memory nodes, preset topic nodes, and initial edge weights. When a user initiates a conversation, the server assigns a unique session_id to the current session; it loads the corresponding role template from the local Redis based on the user's set role ID; it generates a unique session identifier based on the session_id and the current user ID; and it retrieves the user session data input for the current unique session identifier. The system identifies preset topic nodes, sentiment data, and conversation keywords involved in user conversation data. Based on the preset topic nodes, their corresponding edge weights, the current user ID, and conversation keywords, it extracts matching memory nodes and their corresponding semantic similarities from the memory-topic association graph. It calculates the priority value of the corresponding memory node based on semantic similarity, the privacy level of the memory node, sentiment weight, sentiment data, and the sentiment conflict coefficient of the current sentiment data. Simultaneously, it updates the edge weights between the preset topic nodes and the matching memory nodes according to the preset weight update formula. Based on the priority value's range, it determines whether to actively mention the memory node corresponding to the priority value, mention the memory node corresponding to the priority value when the user mentions a preset related topic, or not to activate the memory node.

[0059] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily 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 invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A method for managing context-aware emotion-based AI agents, characterized in that, The method includes: When the server starts, it loads all role templates from the preset shared role pool into the local Redis; each role template corresponds to a unique role ID. Extract memory nodes from the long-term memory that stores current user interaction data; calculate the initial edge weights between memory nodes and preset topic nodes; and construct an undirected weighted memory-topic association graph based on memory nodes, preset topic nodes, and initial edge weights. When a user initiates a conversation, the server assigns a unique session_id to the current session; loads the corresponding role template from the local Redis based on the role ID set by the user; and generates a unique session identifier based on the session_id and the current user ID. The system acquires user conversation data with the current unique conversation identifier, identifies preset topic nodes, sentiment data, and conversation keywords involved in the user conversation data; based on the preset topic nodes, the edge weights corresponding to the preset topic nodes, the current user ID, and the conversation keywords, it extracts matching memory nodes and their corresponding semantic similarities from the memory-topic association graph; based on the semantic similarity, the privacy level in the memory node, the sentiment weight, the sentiment data, and the sentiment conflict coefficient of the current sentiment data, it calculates the priority value of the corresponding memory node; simultaneously, it updates and calculates the edge weights between the preset topic nodes and the matching memory nodes according to the preset weight update formula. Based on the priority value's range, determine whether to actively mention the memory node corresponding to the priority value, or mention the memory node corresponding to the priority value when the user mentions a preset related topic corresponding to the memory node, or not to wake up the memory node.

2. The context-aware emotion-based AI agent management method according to claim 1, characterized in that, Before fully loading all role templates from the preset shared role pool to the local Redis, the method further includes: Configure JSON-formatted role templates in the preset shared role pool; the role template includes: a unique role identifier, basic role personality configuration, role interaction style configuration, and a sensitive topic avoidance list; the basic role personality configuration includes: personality type, knowledge base domain accessed by the role, and preset output requirement criteria; the role interaction style configuration includes: language style template and tone mapping rules; When a new or modified role is obtained from the preset shared role pool by calling the API through the preset role, the new or modified role template will be updated to the preset shared role pool.

3. The context-aware emotion-based AI agent management method according to claim 1, characterized in that, Before retrieving memory nodes from the long-term memory storing current user interaction data, the method further includes: A MongoDB sharded cluster is used to distribute and store single memory data in JSON format containing user session data. Each memory data includes: a unique identifier consisting of user ID, event type, and sequence number; the lifecycle of the single memory data; memory information containing user session data; and attribute fields that support context triggering. Furthermore, the lifecycle of a single memory record includes the memory creation time, the most recent update time, the most recent access time, and the cumulative number of wake-ups; The memory information includes user session data and key entities involved in the user session data; key entities include: extracted keywords and time information; The attribute fields supporting context-triggered events include: topic tags, sentiment weight, privacy level, expiration flag, and expiration time; topic tags include preset core keywords from the extracted keywords; Extract memory nodes from the long-term memory that stores current user interaction data, specifically including: Based on the unique identifier of a memory record, user ID, topic tag, sentiment weight, privacy level, and most recent access time in a single memory record, a corresponding memory node is established; each single memory record corresponds one-to-one with a memory node; and each memory node also includes: a unique identifier for the memory node.

4. The context-aware emotion-based AI agent management method according to claim 3, characterized in that, When a new single memory data entry appears in the long-term memory, a corresponding memory node is generated, and the initial edge weights are calculated and updated in the undirected weighted memory-topic association graph. When a single piece of memory data in the long-term memory is modified, the data corresponding to the memory node is automatically updated; After each round of dialogue, when a memory node is awakened, the last access time of the memory node is updated.

5. The context-aware emotion-based AI agent management method according to claim 1, characterized in that, Before calculating the initial edge weights between the memory node and the preset topic node, the method further includes: Several topic nodes are preset; among them, a topic node includes at least: a unique identifier for the topic node, a topic name, preset topic keywords, the number of times the current topic node is awakened by associated memories within a preset time period, the creation time, and the update time; Calculate the initial edge weights between the memory node and the preset topic node, specifically including: When a memory node is first added to the database, the semantic similarity between the topic tags in the memory node and the preset topic keywords in the topic node is calculated; where the semantic similarity ∈ [0,1]; Determine the semantic similarity as the initial edge weight, and delete the initial edge weight and the corresponding edge that are less than the preset weight threshold.

6. The context-aware emotion-based AI agent management method according to claim 1, characterized in that, Obtain the user conversation data input by the current unique conversation identifier, and identify the preset topic nodes, sentiment data, and conversation keywords involved in the user conversation data, specifically including: The NLU module is used to identify preset topic nodes, sentiment data, and conversation keywords corresponding to user conversation data from several preset topic nodes.

7. The context-aware emotion-based AI agent management method according to claim 1, characterized in that, Based on preset topic nodes, their corresponding edge weights, the current user ID, and conversation keywords, matching memory nodes and their corresponding semantic similarities are extracted from the memory-topic association graph. The priority value of the corresponding memory node is calculated based on semantic similarity, the privacy level, sentiment weight, and emotion data within the memory node, specifically including: Query all memory nodes connected to the preset topic node; then filter the memory node set corresponding to the current user ID from all memory nodes; determine the memory nodes in the memory node set as the matching memory nodes; Calculate the semantic similarity between the current session keywords and the topic tags of each memory node in the memory node set; Extract the emotional weight and privacy level from the matched memory nodes; Through the formula: Priority value = α × emotional_weight + β × similarity_score - γ × privacy_coefficient - δ × emotion_conflict_coefficient; Calculate the priority value; Where α represents the preset emotional weight coefficient, β represents the preset semantic similarity coefficient, γ represents the preset privacy coefficient, δ represents the emotional conflict coefficient, emotional_weight represents the emotional weight, similarity_score represents the semantic similarity, privacy_coefficient represents the preset value corresponding to the privacy level, and emotion_conflict_coefficient represents the emotional conflict coefficient. When the emotional data is preset negative and the memory node is preset negative event, the emotional conflict coefficient is 0.5; otherwise, the emotional conflict coefficient is 0.

8. The context-aware emotion-based AI agent management method according to claim 1, characterized in that, According to the preset weight update formula, the edge weights between the preset topic nodes and the matched memory nodes are updated and calculated, specifically including: In each round of dialogue, the matching memory nodes and the preset topic nodes that trigger the matching are determined; According to the formula: Edge weight = original edge weight × 0.9 + new similarity × 0.1, update edge weight; The new similarity is based on the preset topic nodes, the edge weights corresponding to the preset topic nodes, the current user ID, and the conversation keywords, and is extracted from the memory-topic association graph to obtain the semantic similarity of the matching memory nodes and the corresponding semantic similarity.

9. The context-aware emotion-based AI agent management method according to claim 1, characterized in that, Based on the priority value's falling range, determine whether to proactively mention the memory node corresponding to the priority value, or mention the memory node corresponding to the priority value when the user mentions a preset related topic corresponding to the memory node, or not to activate the memory node. Specifically, this includes: When the priority value is greater than the preset first threshold, the memory node corresponding to the active mention priority value is determined, the single memory data corresponding to the memory node is extracted from the long-term memory bank, and the single memory data is input into the AI ​​agent as context information and current user session data to obtain a response combined with the single memory data; When the priority value is less than or equal to the preset first threshold and greater than the preset second threshold, when the user mentions the preset related topic corresponding to the memory node, the memory node corresponding to the priority value is mentioned. The single memory data corresponding to the memory node is extracted from the long-term memory bank, and the single memory data is used as context information and current user session data to input into the AI ​​agent to obtain a response combined with the single memory data. When the priority value is less than or equal to the preset second threshold, the memory node is not woken up.

10. A context-aware emotion-based AI intelligent agent management device, characterized in that, The device includes: processor; And a memory having executable code stored thereon, which, when executed, causes the processor to perform a context-aware emotion AI agent management method as described in any one of claims 1-9.