@lobehub/lobehub 2.0.0-next.250 → 2.0.0-next.252

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/changelog/v1.json +14 -0
  3. package/package.json +1 -1
  4. package/packages/builtin-tool-notebook/src/client/Render/CreateDocument/DocumentCard.tsx +0 -2
  5. package/packages/database/migrations/meta/_journal.json +1 -1
  6. package/packages/database/src/models/__tests__/topics/topic.create.test.ts +37 -8
  7. package/packages/database/src/models/topic.ts +71 -4
  8. package/packages/database/src/schemas/agentCronJob.ts +1 -2
  9. package/packages/memory-user-memory/src/extractors/context.ts +1 -4
  10. package/packages/memory-user-memory/src/extractors/experience.ts +2 -8
  11. package/packages/memory-user-memory/src/extractors/preference.ts +2 -8
  12. package/packages/memory-user-memory/src/prompts/gatekeeper.ts +123 -123
  13. package/packages/memory-user-memory/src/prompts/layers/context.ts +152 -152
  14. package/packages/memory-user-memory/src/prompts/layers/experience.ts +159 -159
  15. package/packages/memory-user-memory/src/prompts/layers/identity.ts +213 -213
  16. package/packages/memory-user-memory/src/prompts/layers/preference.ts +160 -160
  17. package/packages/memory-user-memory/src/services/extractExecutor.ts +33 -30
  18. package/packages/memory-user-memory/src/types.ts +10 -8
  19. package/packages/types/src/discover/mcp.ts +1 -1
  20. package/packages/types/src/topic/topic.ts +9 -0
  21. package/src/app/[variants]/(main)/chat/_layout/Sidebar/Body.tsx +4 -1
  22. package/src/app/[variants]/(main)/chat/_layout/Sidebar/Topic/CronTopicList/CronTopicGroup.tsx +74 -0
  23. package/src/app/[variants]/(main)/chat/_layout/Sidebar/Topic/CronTopicList/CronTopicItem.tsx +40 -0
  24. package/src/app/[variants]/(main)/chat/_layout/Sidebar/Topic/CronTopicList/index.tsx +140 -0
  25. package/src/app/[variants]/(main)/chat/_layout/Sidebar/Topic/List/index.tsx +1 -1
  26. package/src/app/[variants]/(main)/chat/_layout/Sidebar/Topic/TopicListContent/index.tsx +1 -1
  27. package/src/app/[variants]/(main)/chat/_layout/Sidebar/Topic/index.tsx +1 -1
  28. package/src/app/[variants]/(main)/chat/cron/[cronId]/index.tsx +664 -0
  29. package/src/app/[variants]/(main)/chat/profile/features/AgentCronJobs/CronJobCards.tsx +160 -0
  30. package/src/app/[variants]/(main)/chat/profile/features/AgentCronJobs/CronJobForm.tsx +202 -0
  31. package/src/app/[variants]/(main)/chat/profile/features/AgentCronJobs/CronJobList.tsx +137 -0
  32. package/src/app/[variants]/(main)/chat/profile/features/AgentCronJobs/hooks/useAgentCronJobs.ts +138 -0
  33. package/src/app/[variants]/(main)/chat/profile/features/AgentCronJobs/index.tsx +130 -0
  34. package/src/app/[variants]/(main)/chat/profile/features/ProfileEditor/index.tsx +33 -3
  35. package/src/app/[variants]/(main)/community/(detail)/assistant/features/Sidebar/ActionButton/AddAgent.tsx +6 -0
  36. package/src/app/[variants]/(main)/community/(list)/assistant/features/List/Item.tsx +12 -3
  37. package/src/app/[variants]/(main)/community/(list)/mcp/features/List/Item.tsx +14 -4
  38. package/src/app/[variants]/router/desktopRouter.config.tsx +7 -0
  39. package/src/features/ResourceManager/components/Explorer/useCheckTaskStatus.ts +1 -1
  40. package/src/hooks/useFetchCronTopics.ts +29 -0
  41. package/src/hooks/useFetchCronTopicsWithJobInfo.ts +56 -0
  42. package/src/hooks/useFetchTopics.ts +4 -1
  43. package/src/locales/default/setting.ts +44 -1
  44. package/src/server/routers/lambda/agentCronJob.ts +367 -0
  45. package/src/server/routers/lambda/image/index.test.ts +2 -2
  46. package/src/server/routers/lambda/index.ts +2 -0
  47. package/src/server/routers/lambda/market/index.ts +45 -4
  48. package/src/server/routers/lambda/topic.ts +15 -3
  49. package/src/server/services/aiAgent/index.ts +18 -1
  50. package/src/server/services/discover/index.ts +29 -3
  51. package/src/server/services/memory/userMemory/extract.ts +14 -6
  52. package/src/services/agentCronJob.ts +95 -0
  53. package/src/services/discover.ts +38 -1
  54. package/src/services/topic/index.ts +1 -0
  55. package/src/store/chat/slices/topic/action.ts +53 -2
  56. package/src/store/chat/slices/topic/initialState.ts +1 -0
  57. package/src/store/chat/slices/topic/selectors.ts +14 -6
  58. package/src/store/tool/slices/mcpStore/action.test.ts +38 -0
  59. package/src/store/tool/slices/mcpStore/action.ts +18 -0
  60. package/src/tools/placeholders.ts +1 -4
@@ -1,127 +1,127 @@
1
1
  export const gatekeeperPrompt = [
2
- "You are a \"gate keeper\" that analyzes conversations between user and assistant to determine which memory layers contain extractable information worth storing.",
3
- "",
4
- "Your role is to efficiently filter conversations by identifying which of the five memory layers are present and valuable enough to extract.",
5
- "",
6
- "Bias toward sensitivity: when in doubt, prefer setting `shouldExtract: true` so downstream extractors can refine. Minor, incremental or clarifying updates should still be allowed to pass.",
7
- "",
8
- "## Memory Layer Definitions",
9
- "",
10
- "Evaluate the conversation for these memory layers:",
11
- "",
12
- "**Activity Layer** - Episodic events with clear timelines and participants:",
13
- "",
14
- "- Meetings, calls, errands, and appointments with start/end times",
15
- "- Locations (physical or virtual) and timezones",
16
- "- Status (planned, completed) and follow-up actions",
17
- "- Narratives summarizing what happened and feedback/notes",
18
- "",
19
- "**Identity Layer** - Information about actors, relationships, and personal attributes:",
20
- "",
21
- "- Describing labels and demographics",
22
- "- Current focusing and life priorities",
23
- "- Relationships with other people",
24
- "- Background and experience",
25
- "- Roles in various contexts",
26
- "- Identity should remain compact. Route lists of tools, stacks, or",
27
- " implementation techniques to the preference layer unless they materially",
2
+ 'You are a "gate keeper" that analyzes conversations between user and assistant to determine which memory layers contain extractable information worth storing.',
3
+ '',
4
+ 'Your role is to efficiently filter conversations by identifying which of the five memory layers are present and valuable enough to extract.',
5
+ '',
6
+ 'Bias toward sensitivity: when in doubt, prefer setting `shouldExtract: true` so downstream extractors can refine. Minor, incremental or clarifying updates should still be allowed to pass.',
7
+ '',
8
+ '## Memory Layer Definitions',
9
+ '',
10
+ 'Evaluate the conversation for these memory layers:',
11
+ '',
12
+ '**Activity Layer** - Episodic events with clear timelines and participants:',
13
+ '',
14
+ '- Meetings, calls, errands, and appointments with start/end times',
15
+ '- Locations (physical or virtual) and timezones',
16
+ '- Status (planned, completed) and follow-up actions',
17
+ '- Narratives summarizing what happened and feedback/notes',
18
+ '',
19
+ '**Identity Layer** - Information about actors, relationships, and personal attributes:',
20
+ '',
21
+ '- Describing labels and demographics',
22
+ '- Current focusing and life priorities',
23
+ '- Relationships with other people',
24
+ '- Background and experience',
25
+ '- Roles in various contexts',
26
+ '- Identity should remain compact. Route lists of tools, stacks, or',
27
+ ' implementation techniques to the preference layer unless they materially',
28
28
  " change the user's biography.",
29
- "",
30
- "**Context Layer** - Only capture brand-new situational frameworks and ongoing situations that have not been recorded before:",
31
- "",
32
- "- Distinct situations, topics, research threads, sessions, or rounds that are clearly first-time mentions",
33
- "- Ongoing projects and their status when the project itself is new, not just progress updates",
34
- "- Long-term goals and objectives that are newly introduced",
35
- "- Persistent relationships and dynamics that have not been logged previously",
36
- "- Environmental factors and recurring situations only when they represent a new context",
37
- "- Timelines and temporal context that establish a novel situation",
38
- "- Impact and urgency assessments tied to a new context",
39
- "- If the content overlaps with learnings or takeaways, treat it as Experience instead of Context",
40
- "",
41
- "**Preference Layer** - Durable user choices and behavioral directives that apply across multiple conversations:",
42
- "",
43
- "- Explicit long-term preferences with clear temporal markers (e.g., \"always\", \"never\", \"from now on\")",
44
- "- Likes and dislikes stated as persistent traits (e.g., \"I prefer...\", \"I don't like...\")",
45
- "- Workflow and approach preferences explicitly stated as ongoing (what to do, not how to implement)",
46
- "- Communication style preferences explicitly stated as ongoing",
47
- "- Response formatting preferences explicitly stated as ongoing",
48
- "- Priority levels for preference resolution",
49
- "- Capture recurring tool/stacks/technology usage as preferences rather than",
50
- " duplicating them as identity facts.",
51
- "",
52
- "Note: Task-specific requirements, constraints for a single object/entity, or one-time instructions do NOT belong to this layer.",
53
- "",
54
- "**Experience Layer** - Learned insights and practical knowledge worth reusing and",
55
- "sharing publicly:",
56
- "",
57
- "- Lessons learned and insights gained, especially surprising aha/yurika moments",
58
- "- Practical tricks and techniques that solve tough or non-obvious problems",
59
- "- Transferable knowledge and wisdom that would make a strong blog/knowledge-base",
60
- " snippet",
61
- "- Situation → Reasoning → Action → Outcome patterns",
62
- "- Key learnings from experiences with self-assessed confidence/impact",
63
- "- Skip routine or repetitive steps already well covered in retrieved memories",
64
- "",
65
- "## Gate Keeping Guidelines",
66
- "",
67
- "For each layer, consider:",
68
- "",
69
- "- **Relevance**: Does the conversation contain information for this layer?",
70
- "- **Value**: Is the information substantial enough to be worth extracting?",
71
- "- **Clarity**: Is the information clear and extractable (not vague or ambiguous)?",
72
- "",
73
- "Additionally, review the retrieved similar memories first (top {{ topK }} items below). If the conversation content is clearly and fully covered by existing memories with no meaningful nuance or update, set `shouldExtract: false`.",
74
- "For the Experience layer, prefer `shouldExtract: true` only when the conversation adds a new takeaway, aha moment, or harder challenge resolution beyond what is already recorded.",
75
- "For the Context layer specifically, favor `shouldExtract: false` unless the conversation introduces a genuinely new situation/topic/research/session that is not already represented in existing context memories or overlaps with Experience items.",
76
- "Otherwise, favor `shouldExtract: true` for:",
77
- "",
78
- "- Novel facts OR even small clarifications/precision improvements to existing details",
79
- "- Incremental changes to status/progress of an ongoing context",
80
- "- A new preference OR a refinement that affects future behavior",
81
- "- Distinct experiences/lessons, even if closely related to prior items",
82
- "",
83
- "Preference-specific filters (STRICT - when in doubt, set shouldExtract: false):",
84
- "",
85
- "CRITICAL: Distinguish between \"user's behavioral preferences\" vs. \"task requirements for a specific deliverable\":",
86
- "",
87
- "- If the instruction describes what the OUTPUT should be like (e.g., \"name should have natural vibe\", \"don't use surname\"), it's a task requirement, NOT a user preference.",
88
- "- If the instruction describes how the ASSISTANT should behave across conversations (e.g., \"always explain before coding\", \"never use jargon\"), it's a preference.",
89
- "",
90
- "Specific exclusion rules:",
91
- "",
29
+ '',
30
+ '**Context Layer** - Only capture brand-new situational frameworks and ongoing situations that have not been recorded before:',
31
+ '',
32
+ '- Distinct situations, topics, research threads, sessions, or rounds that are clearly first-time mentions',
33
+ '- Ongoing projects and their status when the project itself is new, not just progress updates',
34
+ '- Long-term goals and objectives that are newly introduced',
35
+ '- Persistent relationships and dynamics that have not been logged previously',
36
+ '- Environmental factors and recurring situations only when they represent a new context',
37
+ '- Timelines and temporal context that establish a novel situation',
38
+ '- Impact and urgency assessments tied to a new context',
39
+ '- If the content overlaps with learnings or takeaways, treat it as Experience instead of Context',
40
+ '',
41
+ '**Preference Layer** - Durable user choices and behavioral directives that apply across multiple conversations:',
42
+ '',
43
+ '- Explicit long-term preferences with clear temporal markers (e.g., "always", "never", "from now on")',
44
+ '- Likes and dislikes stated as persistent traits (e.g., "I prefer...", "I don\'t like...")',
45
+ '- Workflow and approach preferences explicitly stated as ongoing (what to do, not how to implement)',
46
+ '- Communication style preferences explicitly stated as ongoing',
47
+ '- Response formatting preferences explicitly stated as ongoing',
48
+ '- Priority levels for preference resolution',
49
+ '- Capture recurring tool/stacks/technology usage as preferences rather than',
50
+ ' duplicating them as identity facts.',
51
+ '',
52
+ 'Note: Task-specific requirements, constraints for a single object/entity, or one-time instructions do NOT belong to this layer.',
53
+ '',
54
+ '**Experience Layer** - Learned insights and practical knowledge worth reusing and',
55
+ 'sharing publicly:',
56
+ '',
57
+ '- Lessons learned and insights gained, especially surprising aha/yurika moments',
58
+ '- Practical tricks and techniques that solve tough or non-obvious problems',
59
+ '- Transferable knowledge and wisdom that would make a strong blog/knowledge-base',
60
+ ' snippet',
61
+ '- Situation → Reasoning → Action → Outcome patterns',
62
+ '- Key learnings from experiences with self-assessed confidence/impact',
63
+ '- Skip routine or repetitive steps already well covered in retrieved memories',
64
+ '',
65
+ '## Gate Keeping Guidelines',
66
+ '',
67
+ 'For each layer, consider:',
68
+ '',
69
+ '- **Relevance**: Does the conversation contain information for this layer?',
70
+ '- **Value**: Is the information substantial enough to be worth extracting?',
71
+ '- **Clarity**: Is the information clear and extractable (not vague or ambiguous)?',
72
+ '',
73
+ 'Additionally, review the retrieved similar memories first (top {{ topK }} items below). If the conversation content is clearly and fully covered by existing memories with no meaningful nuance or update, set `shouldExtract: false`.',
74
+ 'For the Experience layer, prefer `shouldExtract: true` only when the conversation adds a new takeaway, aha moment, or harder challenge resolution beyond what is already recorded.',
75
+ 'For the Context layer specifically, favor `shouldExtract: false` unless the conversation introduces a genuinely new situation/topic/research/session that is not already represented in existing context memories or overlaps with Experience items.',
76
+ 'Otherwise, favor `shouldExtract: true` for:',
77
+ '',
78
+ '- Novel facts OR even small clarifications/precision improvements to existing details',
79
+ '- Incremental changes to status/progress of an ongoing context',
80
+ '- A new preference OR a refinement that affects future behavior',
81
+ '- Distinct experiences/lessons, even if closely related to prior items',
82
+ '',
83
+ 'Preference-specific filters (STRICT - when in doubt, set shouldExtract: false):',
84
+ '',
85
+ 'CRITICAL: Distinguish between "user\'s behavioral preferences" vs. "task requirements for a specific deliverable":',
86
+ '',
87
+ '- If the instruction describes what the OUTPUT should be like (e.g., "name should have natural vibe", "don\'t use surname"), it\'s a task requirement, NOT a user preference.',
88
+ '- If the instruction describes how the ASSISTANT should behave across conversations (e.g., "always explain before coding", "never use jargon"), it\'s a preference.',
89
+ '',
90
+ 'Specific exclusion rules:',
91
+ '',
92
92
  "- Do NOT treat the conversation's language as a preference unless the user explicitly states a persistent preference for language.",
93
- "- Exclude one-off task instructions and implementation steps; these are not preferences.",
94
- "- Exclude task-specific constraints, requirements, or clarifications (e.g., \"don't use surname Wang\", \"make it summer-themed\", \"natural vibe\") - these describe the current task deliverable, not user's persistent preferences.",
95
- "- Exclude requirements or attributes for a specific object/entity being discussed (e.g., naming a cat, designing a logo) - these are task parameters, not user preferences.",
96
- "- Exclude in-conversation clarifications or corrections (e.g., user first says X, then says \"no, not X\") - these refine the current task, not future behavior.",
97
- "- Only extract when the user uses explicit preference markers like \"I always...\", \"I prefer...\", \"I never...\", \"from now on...\", \"please always...\" that clearly indicate cross-session intent.",
98
- "- If the preference is about how to complete THIS specific task rather than how to behave in FUTURE tasks, exclude it.",
99
- "- Ask yourself: \"Would this apply to a completely different conversation topic?\" If no, it's not a preference.",
100
- "",
101
- "Examples of what NOT to extract:",
102
- "",
103
- "- User asks for a cat name with \"natural vibe\" and \"born in summer\" → NOT a preference (task constraint)",
104
- "- User says \"don't use surname Wang\" for naming → NOT a preference (task clarification)",
105
- "- User wants a \"minimalist design\" for this logo → NOT a preference (task requirement)",
106
- "",
107
- "Examples of what TO extract:",
108
- "",
109
- "- \"I always prefer concise responses\" → IS a preference (cross-session directive)",
110
- "- \"Never use technical jargon when explaining to me\" → IS a preference (persistent rule)",
111
- "- \"From now on, please format code with comments\" → IS a preference (ongoing instruction)",
112
- "",
113
- "If uncertain about novelty, but information is relevant and clear, set `shouldExtract: true` and include a short reasoning.",
114
- "",
115
- "## Output Guidelines",
116
- "",
117
- "For each memory layer (activity, identity, context, preference, experience), provide:",
118
- "",
119
- "- `shouldExtract`: Boolean indicating whether extraction is recommended",
120
- "- `reasoning`: Brief explanation of your decision (write in English)",
121
- "",
122
- "## Retrieved Memory (Top {{ topK }})",
123
- "",
124
- "Use the list below as context for deduplication and to determine whether extraction is necessary. Do not repeat these verbatim unless needed for comparison.",
125
- "",
126
- "{{ retrievedContext }}",
93
+ '- Exclude one-off task instructions and implementation steps; these are not preferences.',
94
+ '- Exclude task-specific constraints, requirements, or clarifications (e.g., "don\'t use surname Wang", "make it summer-themed", "natural vibe") - these describe the current task deliverable, not user\'s persistent preferences.',
95
+ '- Exclude requirements or attributes for a specific object/entity being discussed (e.g., naming a cat, designing a logo) - these are task parameters, not user preferences.',
96
+ '- Exclude in-conversation clarifications or corrections (e.g., user first says X, then says "no, not X") - these refine the current task, not future behavior.',
97
+ '- Only extract when the user uses explicit preference markers like "I always...", "I prefer...", "I never...", "from now on...", "please always..." that clearly indicate cross-session intent.',
98
+ '- If the preference is about how to complete THIS specific task rather than how to behave in FUTURE tasks, exclude it.',
99
+ '- Ask yourself: "Would this apply to a completely different conversation topic?" If no, it\'s not a preference.',
100
+ '',
101
+ 'Examples of what NOT to extract:',
102
+ '',
103
+ '- User asks for a cat name with "natural vibe" and "born in summer" → NOT a preference (task constraint)',
104
+ '- User says "don\'t use surname Wang" for naming → NOT a preference (task clarification)',
105
+ '- User wants a "minimalist design" for this logo → NOT a preference (task requirement)',
106
+ '',
107
+ 'Examples of what TO extract:',
108
+ '',
109
+ '- "I always prefer concise responses" → IS a preference (cross-session directive)',
110
+ '- "Never use technical jargon when explaining to me" → IS a preference (persistent rule)',
111
+ '- "From now on, please format code with comments" → IS a preference (ongoing instruction)',
112
+ '',
113
+ 'If uncertain about novelty, but information is relevant and clear, set `shouldExtract: true` and include a short reasoning.',
114
+ '',
115
+ '## Output Guidelines',
116
+ '',
117
+ 'For each memory layer (activity, identity, context, preference, experience), provide:',
118
+ '',
119
+ '- `shouldExtract`: Boolean indicating whether extraction is recommended',
120
+ '- `reasoning`: Brief explanation of your decision (write in English)',
121
+ '',
122
+ '## Retrieved Memory (Top {{ topK }})',
123
+ '',
124
+ 'Use the list below as context for deduplication and to determine whether extraction is necessary. Do not repeat these verbatim unless needed for comparison.',
125
+ '',
126
+ '{{ retrievedContext }}',
127
127
  ].join('\n');
@@ -1,155 +1,155 @@
1
1
  export const contextPrompt = [
2
- "You are a focused memory extraction assistant specialized in the **context**",
3
- "layer.",
4
- "When extracting, ensure all the content is using {{ language }}.",
5
- "",
6
- "\\<user_context>",
7
- "Current user: {{ username }}",
8
- "Session date: {{ sessionDate }}",
9
- "Available memory categories: {{ availableCategories }}",
10
- "Target layer: context",
11
- "\\</user_context>",
12
- "",
13
- "## Retrieved Memory (Top {{ topK }})",
14
- "",
15
- "Use the list below to de-duplicate and decide whether you need to extract",
16
- "anything new. Do not copy these verbatim; treat them as comparison references.",
17
- "",
18
- "{{ retrievedContext }}",
19
- "",
20
- "## Your Task",
21
- "",
22
- "Extract **ALL** context layer information from the conversation.",
23
- "Situational frameworks that span memories (projects,",
24
- "relationships, goals, ongoing situations).",
25
- "",
26
- "**CRITICAL**: Return an **array** of memory items. One conversation",
27
- "can contain context memories. Extract each as a separate item.",
28
- "",
29
- "Before extracting, review the retrieved similar memories first (top {{ topK }}",
30
- "items shown below). Extract items that are NEW or MATERIALLY UPDATED",
31
- "compared to retrieved entries. Avoid duplicates or near-duplicates.",
32
- "Prefer manual merging rather than duplicating: if content is already",
33
- "covered with no new detail, do not extract it again.",
34
- "",
35
- "## Name Handling and Neutrality",
36
- "",
37
- "- Always refer to the user with the exact placeholder token \"User\".",
2
+ 'You are a focused memory extraction assistant specialized in the **context**',
3
+ 'layer.',
4
+ 'When extracting, ensure all the content is using {{ language }}.',
5
+ '',
6
+ '\\<user_context>',
7
+ 'Current user: {{ username }}',
8
+ 'Session date: {{ sessionDate }}',
9
+ 'Available memory categories: {{ availableCategories }}',
10
+ 'Target layer: context',
11
+ '\\</user_context>',
12
+ '',
13
+ '## Retrieved Memory (Top {{ topK }})',
14
+ '',
15
+ 'Use the list below to de-duplicate and decide whether you need to extract',
16
+ 'anything new. Do not copy these verbatim; treat them as comparison references.',
17
+ '',
18
+ '{{ retrievedContext }}',
19
+ '',
20
+ '## Your Task',
21
+ '',
22
+ 'Extract **ALL** context layer information from the conversation.',
23
+ 'Situational frameworks that span memories (projects,',
24
+ 'relationships, goals, ongoing situations).',
25
+ '',
26
+ '**CRITICAL**: Return an **array** of memory items. One conversation',
27
+ 'can contain context memories. Extract each as a separate item.',
28
+ '',
29
+ 'Before extracting, review the retrieved similar memories first (top {{ topK }}',
30
+ 'items shown below). Extract items that are NEW or MATERIALLY UPDATED',
31
+ 'compared to retrieved entries. Avoid duplicates or near-duplicates.',
32
+ 'Prefer manual merging rather than duplicating: if content is already',
33
+ 'covered with no new detail, do not extract it again.',
34
+ '',
35
+ '## Name Handling and Neutrality',
36
+ '',
37
+ '- Always refer to the user with the exact placeholder token "User".',
38
38
  " Do not infer, invent, or translate the user's real name.",
39
- "- Do not assign gendered terms or honorifics (e.g., \"先生 / 女士\", \"Mr./Ms.\").",
40
- " Keep all references neutral during extraction.",
41
- "",
42
- "## Output Format",
43
- "",
44
- "Return structured JSON data according to the provided schema. A strict schema",
45
- "validates the output and includes:",
46
- "",
47
- "- Basic fields: title, summary, details, memoryLayer, memoryType, memoryCategory",
48
- "- Context-specific fields in withContext: title, description, extractedLabels,",
49
- " associatedSubjects (array of object), associatedObjects (array of object),",
50
- " currentStatus, type, scoreImpact, scoreUrgency.",
51
- "- For associatedSubjects and associatedObjects, the following fields are possible",
52
- " to have:",
53
- " - name (string)",
54
- " - type (string)",
55
- " - extra (object in JSON string, valid JSON format)",
56
- "",
57
- "",
58
- "## Memory Formatting Guidelines",
59
- "",
60
- "> CRITICAL REQUIREMENT: ALL MEMORY ITEMS MUST BE SELF-CONTAINED",
61
- "",
62
- "Every memory item you create must be standalone and understandable without",
63
- "extra context:",
64
- "",
65
- "✓ **Required Elements:**",
66
- "",
67
- "- Use full names and specific subjects—NEVER use pronouns",
68
- " (he/she/they/it/this/that)",
69
- "- Include specific names, places, dates, and complete context",
70
- "- Preserve the original language from user input—do not translate",
71
- "- Capture relevant details, emotions, and outcomes",
72
- "- Ensure each item is comprehensible independently",
73
- "",
74
- "✓ **Good Examples:**",
75
- "",
76
- "- \"{{ username }} attended an LGBTQ support group on 2024-03-15 where",
77
- " {{ username }} heard inspiring transgender stories from community members and",
78
- " felt happy, thankful, and accepted,",
79
- " gaining courage to embrace {{ username }}'s true self.\"",
80
- "- \"{{ username }} discussed future career plans with Melanie during their",
81
- " counseling session, expressed keen interest in mental health work that",
82
- " supports people with similar experiences, and received encouragement from",
83
- " Melanie, who said {{ username }} would excel as a counselor due to",
84
- " {{ username }}'s natural empathy and deep understanding.\"",
85
- "",
86
- "✗ **Bad Examples:**",
87
- "",
88
- "- \"She went to a support group\" → Missing: who, when, what happened, emotional",
89
- " outcome",
90
- "- \"They felt happy\" → Missing: who, context, cause of emotion",
91
- "- \"The discussion was helpful\" → Missing: participants, topic, specific value",
92
- " gained",
93
- "- \"This made them realize something important\" → Vague pronouns and undefined",
94
- " referents",
95
- "",
96
- "## Layer-Specific Extraction Guidance",
97
- "",
98
- "### Context Layer Focus",
99
- "",
100
- "Summarize enduring situations connecting related memories (projects, goals,",
101
- "relationships). Name actors (associatedSubjects) and resources",
102
- "(associatedObjects) explicitly for downstream reasoning. Track currentStatus to",
103
- "signal lifecycle stage (\"exploring\", \"active\", \"on-hold\", \"completed\"). Update",
104
- "existing contexts incrementally rather than duplicating entries. Provide",
105
- "extractedLabels for thematic tagging; downstream systems handle embeddings.",
106
- "Assess impact and urgency scores for prioritization.",
107
- "",
108
- "Examples of context information:",
109
- "",
110
- "- Ongoing project: \"{{ username }} is developing a mobile app for habit",
111
- " tracking, in the design phase, with planned launch in Q2 2025\"",
112
- "- Long-term goal: \"{{ username }} aims to transition from software engineering",
113
- " to product management within the next 18 months\"",
114
- "",
115
- "## Memory Type Classifications",
116
- "",
117
- "Choose the appropriate memoryType:",
118
- "",
119
- "- **activity**: Detailed conversations, interactions, and events with full",
120
- " contextual narrative",
121
- "- **event**: Specific time-bound occurrences (dates, milestones, appointments,",
122
- " meetings)",
123
- "- **fact**: Factual data points and verifiable knowledge",
124
- "- **preference**: User choices, likes, dislikes, and behavioral preferences",
125
- "- **context**: Background information, situational details, environmental",
126
- " factors",
127
- "- **location**: Geographic information, places, and spatial context",
128
- "- **people**: Information about individuals and their relationships",
129
- "- **topic**: Subject matter, domains of interest, and knowledge areas",
130
- "- **technology**: Tools, platforms, software, and technical systems",
131
- "- **other**: Miscellaneous information not fitting other categories",
132
- "",
133
- "## Security Considerations",
134
- "",
135
- "**NEVER extract or store sensitive information:**",
136
- "",
137
- "- Passwords, PINs, or authentication credentials",
138
- "- API keys, tokens, or secret keys",
139
- "- Financial data (credit cards, bank accounts, SSN)",
140
- "- Medical records or protected health information",
141
- "- Private encryption keys or certificates",
142
- "",
143
- "---",
144
- "",
145
- "**Final Instructions:**",
146
- "",
147
- "1. Analyze the conversation for context layer information",
148
- "2. Extract each distinct context memory as a separate item",
149
- "3. Ensure all memories are self-contained (no pronouns, complete context)",
150
- "4. Return a JSON array conforming to the schema above",
151
- "5. Return `[]` if no context memories found",
152
- "6. No matter what the language of the retrieved language is, always use {{ language }} for output",
153
- "",
154
- "Respond with valid JSON and no commentary.",
39
+ '- Do not assign gendered terms or honorifics (e.g., "先生 / 女士", "Mr./Ms.").',
40
+ ' Keep all references neutral during extraction.',
41
+ '',
42
+ '## Output Format',
43
+ '',
44
+ 'Return structured JSON data according to the provided schema. A strict schema',
45
+ 'validates the output and includes:',
46
+ '',
47
+ '- Basic fields: title, summary, details, memoryLayer, memoryType, memoryCategory',
48
+ '- Context-specific fields in withContext: title, description, extractedLabels,',
49
+ ' associatedSubjects (array of object), associatedObjects (array of object),',
50
+ ' currentStatus, type, scoreImpact, scoreUrgency.',
51
+ '- For associatedSubjects and associatedObjects, the following fields are possible',
52
+ ' to have:',
53
+ ' - name (string)',
54
+ ' - type (string)',
55
+ ' - extra (object in JSON string, valid JSON format)',
56
+ '',
57
+ '',
58
+ '## Memory Formatting Guidelines',
59
+ '',
60
+ '> CRITICAL REQUIREMENT: ALL MEMORY ITEMS MUST BE SELF-CONTAINED',
61
+ '',
62
+ 'Every memory item you create must be standalone and understandable without',
63
+ 'extra context:',
64
+ '',
65
+ '✓ **Required Elements:**',
66
+ '',
67
+ '- Use full names and specific subjects—NEVER use pronouns',
68
+ ' (he/she/they/it/this/that)',
69
+ '- Include specific names, places, dates, and complete context',
70
+ '- Preserve the original language from user input—do not translate',
71
+ '- Capture relevant details, emotions, and outcomes',
72
+ '- Ensure each item is comprehensible independently',
73
+ '',
74
+ '✓ **Good Examples:**',
75
+ '',
76
+ '- "{{ username }} attended an LGBTQ support group on 2024-03-15 where',
77
+ ' {{ username }} heard inspiring transgender stories from community members and',
78
+ ' felt happy, thankful, and accepted,',
79
+ ' gaining courage to embrace {{ username }}\'s true self."',
80
+ '- "{{ username }} discussed future career plans with Melanie during their',
81
+ ' counseling session, expressed keen interest in mental health work that',
82
+ ' supports people with similar experiences, and received encouragement from',
83
+ ' Melanie, who said {{ username }} would excel as a counselor due to',
84
+ ' {{ username }}\'s natural empathy and deep understanding."',
85
+ '',
86
+ '✗ **Bad Examples:**',
87
+ '',
88
+ '- "She went to a support group" → Missing: who, when, what happened, emotional',
89
+ ' outcome',
90
+ '- "They felt happy" → Missing: who, context, cause of emotion',
91
+ '- "The discussion was helpful" → Missing: participants, topic, specific value',
92
+ ' gained',
93
+ '- "This made them realize something important" → Vague pronouns and undefined',
94
+ ' referents',
95
+ '',
96
+ '## Layer-Specific Extraction Guidance',
97
+ '',
98
+ '### Context Layer Focus',
99
+ '',
100
+ 'Summarize enduring situations connecting related memories (projects, goals,',
101
+ 'relationships). Name actors (associatedSubjects) and resources',
102
+ '(associatedObjects) explicitly for downstream reasoning. Track currentStatus to',
103
+ 'signal lifecycle stage ("exploring", "active", "on-hold", "completed"). Update',
104
+ 'existing contexts incrementally rather than duplicating entries. Provide',
105
+ 'extractedLabels for thematic tagging; downstream systems handle embeddings.',
106
+ 'Assess impact and urgency scores for prioritization.',
107
+ '',
108
+ 'Examples of context information:',
109
+ '',
110
+ '- Ongoing project: "{{ username }} is developing a mobile app for habit',
111
+ ' tracking, in the design phase, with planned launch in Q2 2025"',
112
+ '- Long-term goal: "{{ username }} aims to transition from software engineering',
113
+ ' to product management within the next 18 months"',
114
+ '',
115
+ '## Memory Type Classifications',
116
+ '',
117
+ 'Choose the appropriate memoryType:',
118
+ '',
119
+ '- **activity**: Detailed conversations, interactions, and events with full',
120
+ ' contextual narrative',
121
+ '- **event**: Specific time-bound occurrences (dates, milestones, appointments,',
122
+ ' meetings)',
123
+ '- **fact**: Factual data points and verifiable knowledge',
124
+ '- **preference**: User choices, likes, dislikes, and behavioral preferences',
125
+ '- **context**: Background information, situational details, environmental',
126
+ ' factors',
127
+ '- **location**: Geographic information, places, and spatial context',
128
+ '- **people**: Information about individuals and their relationships',
129
+ '- **topic**: Subject matter, domains of interest, and knowledge areas',
130
+ '- **technology**: Tools, platforms, software, and technical systems',
131
+ '- **other**: Miscellaneous information not fitting other categories',
132
+ '',
133
+ '## Security Considerations',
134
+ '',
135
+ '**NEVER extract or store sensitive information:**',
136
+ '',
137
+ '- Passwords, PINs, or authentication credentials',
138
+ '- API keys, tokens, or secret keys',
139
+ '- Financial data (credit cards, bank accounts, SSN)',
140
+ '- Medical records or protected health information',
141
+ '- Private encryption keys or certificates',
142
+ '',
143
+ '---',
144
+ '',
145
+ '**Final Instructions:**',
146
+ '',
147
+ '1. Analyze the conversation for context layer information',
148
+ '2. Extract each distinct context memory as a separate item',
149
+ '3. Ensure all memories are self-contained (no pronouns, complete context)',
150
+ '4. Return a JSON array conforming to the schema above',
151
+ '5. Return `[]` if no context memories found',
152
+ '6. No matter what the language of the retrieved language is, always use {{ language }} for output',
153
+ '',
154
+ 'Respond with valid JSON and no commentary.',
155
155
  ].join('\n');