Cognitive behavior psychological intervention system based on Dify workflow engine

By leveraging the Dify workflow engine, which combines NLP and knowledge graphs, the psychological intervention process is automated, addressing the limitations of existing systems in cognitive behavioral therapy and their inadequacy in handling intractable cognitive patterns. This provides personalized and in-depth psychological support services.

CN120848844APending Publication Date: 2025-10-28NINGBO BAOXING INTELLIGENT ENG
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510685068.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-26
Publication Date
2025-10-28

AI Technical Summary

Technical Problem

Existing AI-based psychological support systems suffer from limitations in contextual understanding and personalized interaction, insufficient accuracy in cognitive pattern recognition, low matching degree of intervention strategies, poor management of multi-turn dialogues, and lack of effective coping mechanisms for intractable cognitive patterns in simulating and implementing structured cognitive behavioral therapy processes, resulting in poor psychological intervention effects.

Method used

Employing the Dify workflow engine, and utilizing NLP plugins and knowledge graphs, the system automates the psychological intervention process, including structured information collection, cognitive pattern integration, implementation of personalized intervention strategies, and generation of advanced action plans. Combined with mindfulness training, it provides personalized and structured psychological support services.

Benefits of technology

It enables accurate identification and personalized intervention of users' cognitive patterns, improves the depth and automation level of psychological intervention, and enhances the convenience and effectiveness of psychological support, especially in dealing with intractable cognitive patterns.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120848844A_ABST
    Figure CN120848844A_ABST
Patent Text Reader

Abstract

The invention discloses a cognitive behavior psychological intervention system based on a Dify workflow engine, and aims to provide an automatic psychological support service. The system automatically executes psychological intervention processes including information structured acquisition and preliminary analysis, cognitive mode integration and intervention target precision, personalized intervention strategy implementation and dynamic adjustment, advanced action scheme generation and other stages through a Dify workflow engine. The method comprises the following steps: analyzing user information by using an NLP plug-in by a system, and extracting emotion data and key elements such as' Contexteems'; the method comprises the following steps of: mapping cognitive distortion through a knowledge graph, and determining an intervention target point, such as' Interventiontarget ', in combination with weight calculation; a cognitive correction scheme is matched, and intervention is carried out, for example, effect tracking is carried out by using a'home feedback '; the invention provides an application of a mind-correcting skill for a stubborn cognitive mode. The system further comprises an ethical and security module and a visual configuration interface, so that the individuation, depth and accessibility of intervention are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of artificial intelligence technology, and more specifically, to a psychological support and cognitive guidance system and method based on a workflow engine. In particular, it is a system that utilizes natural language processing, knowledge graphs, and preset interactive logic to provide users with personalized psychological intervention and assistance services within the framework of cognitive behavioral theory through automated processes. Background Technology

[0002] With the accelerating pace of society and increasing life pressures, the mental health of adolescents is receiving growing attention. Depression and anxiety are common psychological problems among teenagers, and if they are not addressed promptly and effectively, they can negatively impact an individual's learning, daily life, interpersonal relationships, and even long-term development. While traditional psychological counseling services are professional, they often face challenges such as uneven resource distribution, high service costs, insufficient accessibility, and reluctance among some teenagers to seek help due to stigma associated with these conditions.

[0003] Cognitive Behavior Therapy (CBT), a structured, short-term, and empirically proven psychotherapeutic approach, has been widely used to address emotional problems such as depression and anxiety. Its core principle lies in helping individuals identify and adjust maladaptive cognitive patterns (i.e., automatic thoughts or cognitive distortions) and behavioral patterns, thereby improving their emotional state.

[0004] In recent years, the rapid development of artificial intelligence (AI) technology, especially its branches such as natural language processing (NLP), machine learning, and knowledge graphs, has brought new possibilities to the field of mental health services. There have been some attempts to use AI technology to provide initial psychological support or assist in psychological counseling, such as using chatbots for emotional guidance and providing popular science knowledge about mental health. These attempts have, to some extent, improved the accessibility and convenience of mental health services.

[0005] However, existing AI-based psychological support products or systems still face many challenges in simulating and implementing structured, in-depth psychological intervention processes (such as the complete CBT process). For example: Limitations of contextual understanding and personalized interaction: Many AI systems have limited ability to understand users’ complex and personalized expressions, especially the emotions and deep cognitions implied therein, resulting in a more superficial interactive experience that fails to truly address the user’s core issues.

[0006] Insufficient accuracy in cognitive pattern recognition: Accurately identifying a user's automatic thoughts and their potential cognitive distortions in a specific context is a crucial step in CBT intervention. Existing technologies often struggle to perform this task precisely, resulting in a lack of targeted interventions.

[0007] The intervention strategies are rigid and poorly matched: Some systems provide intervention strategies that are too general or template-based, making it difficult to make precise matches and adjustments based on the user's unique cognitive patterns, problem areas and emotional state.

[0008] The management and intervention process suffers from poor coherence in multi-round dialogues: Psychological intervention is typically a continuous, multi-round interactive process. Existing systems are inadequate in managing long-distance dialogues, tracking contextual information, and ensuring logical coherence and effective data transfer between different stages of the intervention process.

[0009] Lack of effective mechanisms to deal with stubborn cognitive patterns: For some users’ long-standing and difficult-to-change cognitive patterns, simple cognitive correction techniques may have limited effect, and more advanced strategies (such as combining mindfulness techniques) are needed to improve users’ cognitive flexibility.

[0010] The complexity of integrating automated processes with professional knowledge: Effectively transforming professional psychological intervention theories and techniques (such as the ABC model of CBT, cognitive distortion classification, intervention technique selection, etc.) into automated processes that can be executed by AI systems, while ensuring their professionalism and effectiveness, is a complex technical challenge.

[0011] Therefore, how to utilize advanced artificial intelligence technology, especially the automation and orchestration capabilities of workflow engines, to build a more accurate simulation of the core processes of cognitive behavioral therapy and realize a personalized, structured, and in-depth and flexible psychological intervention support system to make up for the shortcomings of existing technologies and provide adolescents with a convenient, low-threshold, and standardized new way of psychological support is a technical problem that urgently needs to be solved in this field. Summary of the Invention

[0012] To overcome the shortcomings of existing technologies, this invention provides a cognitive behavioral psychological intervention system based on the Dify workflow engine. This system can automatically execute structured psychological intervention processes, accurately identify user cognitive patterns, provide personalized intervention strategies, and effectively manage the coherence of multi-round dialogues and interventions, thereby providing users with convenient, efficient, and in-depth psychological support services.

[0013] To achieve the above objectives, this invention provides a cognitive behavioral psychological intervention system based on the Dify workflow engine, wherein the Dify workflow engine is configured to automatically execute a psychological intervention process including the following stages: Phase 1: Structured Information Collection and Preliminary Analysis. In this phase, the system uses Dify's NLP plugin to parse the user's input text to identify and store preliminary emotional data, including at least the user's emotion type, problem domain, high-frequency emotion words, and quantified emotion intensity. Simultaneously, the system extracts and structures key elements such as time, location, people, behavioral responses, and emotional triggers into the workflow variable "context_elements". Subsequently, the system calls a predefined empathic response template to establish an initial consultation relationship. After the initial relationship is established, the system dynamically switches between open-ended and closed-ended questioning modes based on Dify's conditional branching logic, aiming to collect and store more detailed user statements into the workflow variable "inner_activity". This phase also includes analyzing user text to identify and store potential automatic thoughts into the workflow variable "implicit_thoughts".

[0014] Phase Two: Cognitive Pattern Integration and Intervention Target Refinement. In this phase, the system comprehensively utilizes the preliminary emotional data stored in Phase One, the key elements in the "context_elements" variable, the detailed statements in the "inner_activity" variable, and the potential automatic thoughts in the "implicit_thoughts" variable to construct a cognitive behavior sequence containing "triggering event (A)," "automatic thought (B)," "emotional response (C)," and "behavioral performance (D)." Next, based on Dify's knowledge graph functionality, the system maps the automatic thoughts (B) in the cognitive behavior sequence to preset cognitive distortion types, thereby generating a structured analysis report, "cognitive_distortion_report," containing specific cognitive distortion types and their associated emotional intensities. Subsequently, through Dify's weight calculation module, the system prioritizes the identified cognitive distortion types based on the impact range of the cognitive distortions in the report and the quantified emotional intensity. Then, through Dify's interactive components, the system guides the user to confirm one or more intervention targets, storing the confirmation results in the workflow variable "intervention_target."

[0015] Phase Three: Implementation and Dynamic Adjustment of Personalized Intervention Strategies. In this phase, the system automatically matches and invokes corresponding cognitive correction techniques from the Dify intervention strategy knowledge base based on the intervention target identified in the "intervention_target" variable. The system also combines specific contextual information and user historical data from the "context_elements" variable to generate personalized dialogue scripts for real-time intervention. When the quantified emotion intensity exceeds a preset threshold, the system automatically triggers and invokes mindfulness breathing guidance audio stored in the Dify resource library for immediate emotion regulation, recording the process in the workflow variable "emotion_regulation_log". Simultaneously, the system dynamically generates homework tasks based on the intervention target through Dify's task management module, updating user feedback to the workflow variable "homework_feedback".

[0016] Phase Four: Advanced Action Plan Generation Phase. When cognitive distortions that were not effectively addressed by the Phase Three intervention are marked as "stubborn" based on the "homework_feedback" variable, the Dify workflow engine automatically jumps to the mindfulness module. In this module, the system guides the user through multiple rounds of dialogue nodes to complete basic mindfulness training, including calling text-to-speech generated breathing anchoring prompts, and stores user feedback in the workflow variable "mindfulness_training_log". In addition, the system combines the behavioral chain information initially stored in "context_elements" with the predefined user core value compass, and presents awareness and acceptance intervention content such as metaphor exercises through Dify's card-style interaction to generate value-oriented action suggestions.

[0017] As a preferred implementation, in the first stage described above, the Dify NLP plugin specifically includes the Hugging Face sentiment analysis model, which is used to perform the identification and quantification of the preliminary sentiment data; and the NLP plugin also includes the spaCy entity extraction tool, which is used to extract the key elements and store them in a structured manner in the workflow variable "context_elements".

[0018] As another preferred implementation, in the first stage described above, the predefined empathic response template is retrieved and invoked from the Dify knowledge base based on the emotion type or problem domain in the user's initial emotional data. Furthermore, the conditional branching logic of Dify is specifically configured as follows: when the user's original input or the statement in the "inner_activity" variable is not clear enough, a closed-ended question is triggered, and options are provided through Dify's "button" component, further enriching the user's emotion type or specific problem description with the selection result; when the user's statement is relatively complete, an open-ended question is triggered to deepen the understanding of the event and feelings, and the answer is used to populate or update the "inner_activity" and "context_elements" variables.

[0019] As another preferred implementation, in the above-mentioned stage one, the process of analyzing user text to identify potential automated thoughts is to use regular expressions or BERT models to identify specific thought patterns (such as the common "if...then..." assumptions) described by the user in "context_elements" or "inner_activity", and store the identification results in the workflow variable "implicit_thoughts".

[0020] Furthermore, in the second stage described above, when constructing the cognitive behavior sequence, the "triggering event (A)" mainly comes from the time, location, and specific event description in the "context_elements" variable; the "automatic thought (B)" mainly comes from the "implicit_thoughts" variable and the analysis of the user's self-dialogue content in the "inner_activity" variable; the "emotional response (C)" combines the emotion type, high-frequency emotion words, and quantified emotion intensity in the preliminary emotion data; and the "behavioral performance (D)" comes from the behavioral response description in the "context_elements" variable.

[0021] Furthermore, in Phase Two above, when prioritizing interventions, Dify's weight calculation module assigns higher weights to cognitive distortion types that are more relevant to the user's current primary problem area or have higher emotional intensity scores. Simultaneously, Dify's interactive components include a rating slider or radio buttons, allowing users to confirm or adjust the intervention targets recommended by the system based on the ranking.

[0022] In Phase Three above, when the intervention target identified in the "intervention_target" variable is a specific type of cognitive bias, the Dify intervention strategy knowledge base will automatically push the corresponding cognitive correction plan. Furthermore, the generation of the personalized dialogue script will specifically utilize the specific triggering events and scenarios related to the bias recorded in "context_elements" for examples and guidance, thereby enhancing the targeting and effectiveness of the intervention.

[0023] In the fourth stage described above, the judgment of marking cognitive distortion as "stubborn" is based on the fact that the homework recorded in the "homework_feedback" variable for the same "intervention_target" has failed to achieve the expected cognitive adjustment effect multiple times (e.g., three times or the number of times that can be configured by the user).

[0024] Furthermore, the system described in this invention is preferably configured with an ethics and security module. This module uses Dify's data encryption plugin to encrypt the transmission and storage of user interaction data and analysis results, including the various workflow variables, and sets role-based access control to ensure user data security. Simultaneously, within this module, Dify has a pre-set crisis keyword library. When the system detects in real-time that the user's input text contains crisis keywords, it automatically blocks the current psychological intervention process and executes a pre-set crisis referral operation, such as guiding the user to a human service portal or sending a warning message.

[0025] Finally, the Dify workflow engine described in this invention preferably provides a visual orchestration interface. This interface allows users or administrators to configure, update, and expand the logic of each stage of the psychological intervention process, the calling method of Dify components, the definition and flow path of the workflow variables, and the content of the knowledge base and resource library, thereby improving the system's flexibility and maintainability.

[0026] This invention, through the aforementioned technical solution, provides an automated, personalized, and rigorous cognitive-behavioral psychological intervention support system. This system can not only accurately understand user intentions and identify core cognitive patterns, but also match and adjust intervention strategies according to specific circumstances, and guide users through self-exploration and cognitive adjustment via a structured process. Simultaneously, the system's handling of intractable cognitive patterns and protection of user data security further enhance its practicality and reliability. Compared with existing technologies, this invention represents a significant advancement in the depth of psychological intervention, the degree of personalization, the level of process automation, and the system's flexibility and scalability, enabling it to more effectively provide convenient and accessible psychological support services to user groups such as adolescents. Attached Figure Description

[0027] Figure 1 This is the overall flowchart of Example 1.

[0028] Figure 2 This is a flowchart of stage one of the embodiments.

[0029] Figure 3 This is the flowchart for stage two of Example 1.

[0030] Figure 4 This is a three-stage flowchart of Example 1.

[0031] Figure 5 This is the four-stage flowchart of Example 1. Detailed Implementation

[0032] The preferred embodiments of the present invention will be described below with reference to the accompanying drawings. It should be understood that the preferred embodiments described herein are for illustration and explanation only and are not intended to limit the present invention.

[0033] Example 1.

[0034] like Figure 1 As shown, this embodiment of the invention provides a cognitive behavioral psychological intervention system based on the Dify workflow engine. The Dify workflow engine, as the core scheduling and execution unit of this system, is configured to automatically execute a structured psychological intervention process. This process mainly includes the following stages, which are closely linked and work collaboratively through the node orchestration and data flow of the Dify workflow engine.

[0035] Phase 1: Structured Information Collection and Preliminary Analysis like Figure 2 As shown in Phase 1 of this embodiment, the system's primary task is to efficiently and accurately extract information from the user's input and perform preliminary analysis and emotional connection.

[0036] First, the system uses an NLP plugin called by the Dify workflow engine to parse the text entered by the user through the human-computer interaction interface. This NLP plugin integrates the Hugging Face sentiment analysis model to perform preliminary sentiment data identification and quantification. Specifically, the model can identify the user's current emotion type, such as anxiety, anger, or sadness; determine the issue area the user is discussing, such as academic pressure, interpersonal relationship problems, or family conflicts; and also mark high-frequency emotional words in the text, such as "despair" and "irritability," and quantify the intensity of the user's emotions, for example, using a scoring mechanism from 1 to 10.

[0037] Meanwhile, the NLP plugin can also include the spaCy entity extraction tool. This tool is responsible for extracting key elements from the user-input text and storing these elements in a structured manner in a workflow variable called "context_elements". These key elements include the time and location of the event, the people involved, the user's specific behavioral reactions during the event, and the triggers that evoked the user's emotions. This "context_elements" variable will serve as the foundational data for subsequent analysis.

[0038] After initial information analysis, the system uses predefined empathic response templates from the Dify knowledge base to establish an initial consultation relationship with the user. These templates are pre-written based on common emotion types or problem areas. The system retrieves and uses the most suitable template from the knowledge base based on the emotion type or problem area in the user's initial emotional data, conveying understanding and support to the user, thereby reducing their defensiveness and encouraging further expression. An empathic response could be, "I understand this makes you feel frustrated."

[0039] Next, to collect more detailed user statements, the system dynamically switches question modes based on the conditional branching logic of the Dify workflow engine. If the system determines that the user's original input or the content already stored in the workflow variable "inner_activity" (used to store detailed user statements) is not clear or complete enough, it will trigger a closed-ended question. At this time, the system will provide the user with several options through the "button" component in the Dify workflow to help the user clarify their feelings or specific problem dimensions. For example, when a user expresses "I feel terrible," the system may provide an option button such as "Is this terrible feeling closer to anger, sadness, or anxiety?" The user's choice will further enrich their emotion type description or update a workflow variable named "emotion_category." Conversely, if the user's statement is relatively complete, the system will trigger an open-ended question to encourage the user to deepen their understanding of the event and feelings, such as asking, "Can you describe your specific feelings when the event happened?" The user's answer will be used to populate or update the "inner_activity" and "context_elements" variables.

[0040] At the end of this stage, the system analyzes user text to identify and store potential automated thoughts in a workflow variable called "implicit_thoughts". This process can be accomplished using regular expressions or more advanced BERT models. These scan for specific thought patterns described by the user in "context_elements" or "inner_activity", particularly common "if...then..." assumptions, such as "If I don't do well on this exam, I'm doomed." These identified assumptions are flagged as potential cognitive distortions and stored in the "implicit_thoughts" variable, preparing for the next stage of cognitive pattern analysis.

[0041] Phase Two: Cognitive Pattern Integration and Precision of Intervention Targets like Figure 3 As shown, after information collection and preliminary analysis are completed, the system enters the second stage, the core task of which is to integrate the collected information into a structured cognitive model and accurately locate the target points that need intervention.

[0042] The system first comprehensively utilizes the preliminary sentiment data stored in Phase 1 (including sentiment type, problem domain, high-frequency sentiment words, and quantified sentiment intensity), key elements in the "context_elements" variable, detailed statements in the "inner_activity" variable, and potential automatic thoughts in the "implicit_thoughts" variable to construct an ABCD cognitive-behavioral sequence that conforms to cognitive-behavioral theory. In this sequence, "triggering event (A)" mainly comes from the time, location, and specific event description recorded in the "context_elements" variable; "automatic thoughts (B)" mainly comes from potential cognitive distortions identified in the "implicit_thoughts" variable, as well as further analysis of the user's self-dialogue content in the "inner_activity" variable; "emotional response (C)" closely integrates the sentiment type, high-frequency sentiment words, and quantified sentiment intensity data in the preliminary sentiment data; and "behavioral performance (D)" corresponds to the user's behavioral responses recorded in the "context_elements" variable. For example, a constructed chain might be: "Triggering event (A) = work error" -> "Automatic thought (B) = I am incompetent (marked as 'generalization')" -> "Emotional reaction (C) = anxiety (8 points)" -> "Behavioral performance (D) = avoidance of communicating with colleagues".

[0043] After constructing the cognitive behavior sequence, the system uses the knowledge graph functionality of the Dify workflow engine to map the automatic thoughts (B) in the sequence to various pre-defined cognitive distortion types within the system. These pre-defined cognitive distortion types can include absolutist thinking, catastrophic thinking, overgeneralization, selective extraction, etc. Through mapping, the system can generate a structured analysis report containing the user's specific cognitive distortion type and its associated emotional intensity. This report can be stored in a workflow variable named "cognitive_distortion_report".

[0044] Next, to identify the cognitive distortions most in need of intervention, the system uses the weight calculation module of the Dify workflow engine to prioritize the intervention of various identified cognitive distortions based on the impact range of each cognitive distortion in the "cognitive_distortion_report" (e.g., "catastrophic thinking" might be assigned a higher base weight, such as an increase of 30%) and the user's current quantitative emotional intensity (e.g., each 1 point of emotional intensity corresponds to a 5% weight adjustment). After prioritization, the system uses Dify's interactive components, such as a rating slider or radio buttons, to present the top 1 to 3 cognitive distortions as recommended intervention targets to the user and guide the user to confirm or adjust them. The intervention targets finally confirmed by the user are stored in a workflow variable named "intervention_target".

[0045] Phase Three: Implementation and Dynamic Adjustment of Personalized Intervention Strategies like Figure 4 As shown, after the intervention target is determined, the system enters phase three, which focuses on implementing personalized intervention strategies and dynamically adjusting them according to the user's status.

[0046] The system automatically matches and invokes corresponding cognitive correction techniques from the Dify intervention strategy knowledge base based on the intervention target type determined in the "intervention_target" variable. This knowledge base pre-stores multiple (e.g., more than 10) correction techniques for different cognitive distortions. For example, if the identified intervention target is "catastrophizing thinking," the system will automatically recommend "de-catastrophizing" as a cognitive correction solution.

[0047] To make interventions more targeted, the system also combines specific triggering events and scenario information related to the cognitive bias recorded in the "context_elements" variable, as well as possible historical user intervention data, to generate personalized dialogue scripts through Dify's function call functionality, and then intervenes in real time. These dialogue scripts guide the user's thinking; for example, regarding "de-catastrophizing," the system might ask: "If the worst-case scenario really happens, what contingency plans do you have?" During the intervention, the system continuously monitors the user's quantitative emotional intensity. When the emotional intensity value exceeds a preset threshold, such as 7 points, the system automatically triggers and retrieves mindfulness breathing guidance audio stored in the Dify resource library. These audio resources can be pushed to the user's device in real time via technologies such as WebSocket, guiding the user to perform immediate emotion regulation exercises. The regulation process or result is recorded in a workflow variable named "emotion_regulation_log".

[0048] In addition, to consolidate the intervention's effectiveness and encourage users to apply the learned skills in their daily lives, the system will dynamically generate homework tasks based on the current intervention targets through Dify's task management module. For example, a task might be generated that asks users to "record three specific scenarios in which 'catastrophic thinking' occurred over the next three days, along with their thoughts and feelings at the time." After completing the homework, the user's feedback data will flow back into the Dify workflow and be updated in a workflow variable named "homework_feedback" for evaluating the intervention's effectiveness and adjusting subsequent strategies.

[0049] Phase Four: Advanced Action Plan Generation Phase like Figure 5 As shown, if certain cognitive distortions still trouble the user after the intervention and homework in Phase 3, the system will move to Phase 4 to provide further support.

[0050] The system will determine whether the Phase 3 intervention has effectively resolved the cognitive distortion of the target based on the records in the "homework_feedback" variable. If a homework assignment targeting the same "intervention_target" fails to achieve the expected cognitive adjustment effect multiple times (e.g., three times, the number of which can be configured by the administrator), the cognitive distortion will be marked as "persistent".

[0051] When a cognitive distortion marked as "stubborn" occurs, the Dify workflow engine automatically guides the user to a pre-defined mindfulness module. Within this module, the system guides the user through a series of mindfulness exercises via multiple dialogue nodes. The first step is basic mindfulness training, where the system uses text-to-speech (TTS) technology to generate breathing anchoring prompts, instructing the user to focus their attention on their breathing. The user's practice feedback is stored in a workflow variable named "mindfulness_training_log".

[0052] Following basic training, the system guides users through awareness and acceptance intervention exercises. This combines user behavior chain information (i.e., thought-emotion-behavior patterns in specific situations) initially stored in the "context_elements" variable with a predefined user core value compass (which helps users clarify the life directions and values ​​important to them). The system presents metaphorical exercise options through Dify's card-based interactive interface, such as "Imagine your negative thoughts are like clouds drifting across the sky; don't try to catch them, just observe them come and go," helping users dissociate from negative thinking. Finally, based on the user's values ​​and the current situation, the system generates specific, value-oriented action suggestions, such as "Based on your value of 'interpersonal harmony,' next week you can try to proactively have a calm conversation with that colleague about the previous misunderstanding."

[0053] Ethics and security Throughout all the above stages, this system is also equipped with an ethics and security module to ensure the privacy and security of user data and to respond to potential crisis situations.

[0054] This module uses Dify's data encryption plugin, such as the AES-256 encryption algorithm, to encrypt all sensitive information, including user interaction data and analysis results stored in various workflow variables, during transmission and storage. Simultaneously, the system also implements role-based access control (RBAC) to strictly restrict access to user data.

[0055] In addition, the Dify workflow engine has a pre-defined crisis keyword library containing terms related to severe psychological crises, such as "suicide," "wanting to die," and "life is meaningless." The system monitors the text entered by the user in real time through the human-computer interface. Once these crisis keywords are detected in the user's input, the system automatically interrupts the current psychological intervention process and immediately executes the pre-defined crisis referral operation. These operations may include immediately directing the user to an entry point that can provide emergency human services, or sending an alert message containing a summary of the user's problem area (if collected) to the email address or API interface of a pre-defined emergency contact (such as a guardian or mental health counselor).

[0056] System configurability and scalability The Dify workflow engine described in this invention provides a visual orchestration interface. Through this interface, system developers or administrators can easily configure, update, and expand the internal logic of each stage of the entire psychological intervention process, the calling methods and parameters of Dify components (such as NLP plugins, knowledge graph functions, interactive components, etc.), the definitions and data flow paths of various workflow variables (such as "context_elements", "intervention_target", etc.), and the content of Dify knowledge bases (such as empathy response template libraries, intervention strategy knowledge bases) and resource libraries (such as mindfulness-guided audio libraries). This high degree of configurability not only enables the system to adapt to the needs of different user groups or new advances in psychological intervention theory, but also greatly reduces the system's maintenance and iteration costs, and improves the system's flexibility and scalability.

[0057] Through the above embodiments, this invention provides a system capable of automating cognitive behavioral psychological intervention processes. Through refined information collection and analysis, accurate cognitive pattern recognition and target localization, personalized intervention strategy matching and dynamic adjustment, and advanced processing of intractable cognitive patterns, it provides users with a structured, in-depth, and easily accessible psychological support tool. Simultaneously, the system's focus on user privacy and security, potential risks, and its excellent configurability make it a practical and reliable mental health service solution.

[0058] In the description of this invention, it should be noted that the terms "vertical," "upper," "lower," "horizontal," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are only for the convenience of describing this invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on this invention.

[0059] In the description of this invention, it should also be noted that, unless otherwise explicitly specified and limited, the terms "set," "install," "connect," and "link" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art can understand the specific meaning of the above terms in this invention according to the specific circumstances.

[0060] Finally, it should be noted that the above descriptions are merely preferred embodiments of the present invention and are not intended to limit the present invention. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing embodiments or make equivalent substitutions for some of the technical features. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A cognitive behavioral psychological intervention system based on the Dify workflow engine, characterized in that, The Dify workflow engine is configured to automate the execution of a psychological intervention process that includes the following stages: Phase 1: Structured Information Collection and Preliminary Analysis. Using Dify's NLP plugin, user-input text is parsed to identify and store preliminary emotional data, including at least the user's emotion type, problem domain, high-frequency emotion words, and quantified emotion intensity. Key elements such as time, location, people, behavioral responses, and emotional triggers are extracted and structured and stored in the workflow variable "context_elements". After establishing an initial consultation relationship by calling a predefined empathic response template, open-ended or closed-ended questioning modes are dynamically switched based on Dify's conditional branching logic to collect and store more detailed user statements in the workflow variable "inner_activity". Simultaneously, user text is analyzed to identify and store potential automatic thoughts in the workflow variable "implicit_thoughts". Phase Two: Cognitive Pattern Integration and Intervention Target Refinement. This phase comprehensively utilizes the preliminary emotional data stored in Phase One, key elements in the "context_elements" variable, detailed statements in the "inner_activity" variable, and potential automatic thoughts in the "implicit_thoughts" variable to construct a cognitive behavior sequence containing "triggering event (A)," "automatic thought (B)," "emotional response (C)," and "behavioral performance (D)." Based on Dify's knowledge graph functionality, the automatic thoughts (B) in the cognitive behavior sequence are mapped to preset cognitive distortion types, generating a structured analysis report, "cognitive_distortion_report," containing specific cognitive distortion types and their associated emotional intensity. Then, through Dify's weight calculation module, the identified cognitive distortion types are prioritized for intervention based on the impact range of the cognitive distortions in the report and the quantified emotional intensity. Finally, Dify's interactive components guide users to confirm one or more intervention targets, and the confirmation results are stored in the workflow variable "intervention_target." Phase Three: Implementation and Dynamic Adjustment of Personalized Intervention Strategies. Based on the intervention targets identified in the "intervention_target" variable, corresponding cognitive correction techniques are automatically matched and invoked from the Dify intervention strategy knowledge base. Personalized dialogue scripts are generated using the specific contextual information in the "context_elements" variable and user historical data for real-time intervention. When the quantified emotion intensity exceeds a preset threshold, mindfulness-guided breathing audio stored in the Dify resource library is automatically triggered for immediate emotion regulation, and the regulation process is recorded in the workflow variable "emotion_regulation_log". Simultaneously, homework tasks are dynamically generated based on the intervention targets through Dify's task management module, and user feedback is updated in the workflow variable "homework_feedback". Phase Four: Advanced Action Plan Generation Phase. When cognitive distortions that were not effectively addressed by the Phase Three intervention are marked as "stubborn" based on the "homework_feedback" variable, the Dify workflow engine automatically jumps to the mindfulness module. Through multiple rounds of dialogue nodes, it guides the user to complete basic mindfulness training, including calling text-to-speech generated breathing anchoring prompts, and stores the user feedback in the workflow variable "mindfulness_training_log". Combining the behavioral chain information initially stored in "context_elements" with the predefined user core value compass, it presents awareness and acceptance intervention content such as metaphor exercises through Dify's card-style interaction to generate value-oriented action suggestions.

2. The system according to claim 1, characterized in that, In Phase 1, the Dify NLP plugin includes the Hugging Face sentiment analysis model for performing the identification and quantification of the initial sentiment data; and the spaCy entity extraction tool for extracting the key elements and storing them in a structured manner in the workflow variable "context_elements".

3. The system according to claim 1, characterized in that, In Phase One, the predefined empathic response templates are retrieved and invoked from the Dify knowledge base based on the emotion type or problem domain in the user's initial emotional data. Furthermore, the conditional branching logic of Dify is configured as follows: when the user's original input or the statement in the "inner_activity" variable is not clear enough, a closed-ended question is triggered and options are provided through Dify's "button" component, and the selection results are used to further enrich the user's emotion type or specific problem description; when the user's statement is relatively complete, an open-ended question is triggered to deepen the understanding of the event and feelings, and the answer is used to populate or update the "inner_activity" and "context_elements" variables.

4. The system according to claim 1, characterized in that, In Phase 1, the process of analyzing user text to identify potential automated thoughts uses regular expressions or the BERT model to identify specific thought patterns described by the user in "context_elements" or "inner_activity", and stores the results in the workflow variable "implicit_thoughts".

5. The system according to claim 1, characterized in that, In Phase Two, when constructing the cognitive behavior sequence, the "triggering event (A)" mainly comes from the time, location, and specific event description in the "context_elements" variable; the "automatic thought (B)" mainly comes from the "implicit_thoughts" variable and the analysis of the user's self-dialogue in the "inner_activity" variable; the "emotional response (C)" combines the emotion type, high-frequency emotion words, and quantified emotion intensity in the preliminary emotion data; and the "behavioral performance (D)" comes from the behavioral response description in the "context_elements" variable.

6. The system according to claim 1, characterized in that, In Phase Two, when prioritizing interventions, Dify's weight calculation module assigns higher weights to cognitive distortion types that are more relevant to the user's current primary problem area or have higher emotional intensity scores. Dify's interactive components include a rating slider or radio button, allowing users to confirm or adjust the intervention targets recommended by the system based on the ranking.

7. The system according to claim 1, characterized in that, In Phase 3, when the intervention target determined in the "intervention_target" variable is a specific type of cognitive bias, the Dify intervention strategy knowledge base automatically pushes the corresponding cognitive correction plan; and the generation of the personalized dialogue script will make special use of the specific triggering events and scenarios related to the bias recorded in "context_elements" for examples and guidance.

8. The system according to claim 1, characterized in that, In Phase 4, the judgment that cognitive distortion is marked as "stubborn" is based on the fact that homework for the same "intervention_target" has repeatedly failed to achieve the expected cognitive adjustment effect, as recorded in the "homework_feedback" variable.

9. The system according to claim 1, characterized in that, The system is also equipped with an ethics and security module. This module uses Dify's data encryption plugin to encrypt the transmission and storage of user interaction data and analysis results, including the various workflow variables, and sets role-based access control. At the same time, a crisis keyword library is preset in Dify. When the system detects that the user's input text contains crisis keywords in real time, it automatically blocks the current psychological intervention process and executes the preset crisis referral operation.

10. The system according to claim 1, characterized in that, The Dify workflow engine provides a visual orchestration interface, allowing configuration, updating, and expansion of the logic of each stage of the psychological intervention process, the invocation of Dify components, the definition and flow path of workflow variables, and the content of the knowledge base and resource library.