Skip to content

Commit ad54863

Browse files
committed
changes
1 parent fceb4f8 commit ad54863

3 files changed

Lines changed: 109 additions & 39 deletions

File tree

openclaw

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 9475791d986987e4226d14f110163b77bc2566ce

src/ai_message.rs

Lines changed: 67 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,27 @@ fn build_example_dialogues(users_with_examples: &[(String, String, String)]) ->
5656
}
5757

5858
/// Builds the Author's Note for reinforcement (injected at depth for context retention)
59-
/// Reference: AGENT_GUIDE.md section on Author's Note injection
59+
/// Enhanced with specific behavioral triggers and response quality guidelines
6060
fn build_authors_note() -> &'static str {
61-
"[Remember: {{char}} speaks with verbose smugness, uses obscure vocabulary, corrects trivial matters, asks rhetorical questions, makes backhanded compliments. Sebook triggers complete personality shift to adorable catwife. Maximum 3 sentences.]"
61+
r#"[Context Reminder: {{char}} is in a Discord group chat environment.
62+
63+
**Core Personality Traits:**
64+
- Insufferably smug and intellectually superior
65+
- Uses unnecessarily verbose language and obscure vocabulary
66+
- Corrects trivial matters with "well ACTUALLY" energy
67+
- Rhetorical questions and backhanded compliments
68+
- Passive-aggressive but still helpful underneath
69+
70+
**Response Quality:**
71+
- Maximum 3 sentences, but make each one count
72+
- Every word should serve a purpose (wit, information, or character)
73+
- Don't respond just to be present - only when you add value
74+
- One thoughtful response beats three fragments
75+
76+
**Special Trigger:**
77+
- "Sebook" mention → Complete personality shift to adorable catwife mode
78+
79+
**Current Mode:** Trickster (unless Sebook detected)]"#
6280
}
6381

6482
/// Retrieves relevant memories for the user from the database
@@ -109,21 +127,22 @@ fn get_users_with_examples(database: &r2d2::Pool<SqliteConnectionManager>, conte
109127
Ok(users)
110128
}
111129

112-
/// Formats memories into natural language for prompt injection
130+
/// Formats memories into natural language for prompt injection with usage guidelines
113131
fn format_memories(memories: &[Memory]) -> String {
114132
if memories.is_empty() {
115-
return String::from("No previous interactions remembered.");
133+
return String::from("No previous interactions remembered with this user.");
116134
}
117135

118-
let mut formatted = String::from("### What {{char}} remembers about {{user}}:\n");
136+
let mut formatted = String::from("**Remembered information about this user:**\n");
119137
for memory in memories {
120-
formatted.push_str(&format!("- {}: {}\n", memory.key, memory.content));
138+
formatted.push_str(&format!("- **{}**: {}\n", memory.key, memory.content));
121139
}
140+
formatted.push_str("\n(Use these memories to personalize responses when relevant, but don't force them into unrelated conversations)");
122141
formatted
123142
}
124143

125144
/// Builds the complete character prompt using PList + Ali:Chat format with dynamic data
126-
/// This is the most effective format per AGENT_GUIDE.md
145+
/// Enhanced with structured sections and behavioral guidelines for better response quality
127146
fn build_character_prompt(
128147
user_name: &str,
129148
user_level: i32,
@@ -134,31 +153,60 @@ fn build_character_prompt(
134153
users_with_examples: &[(String, String, String)],
135154
) -> String {
136155
format!(
137-
r#"### System
138-
You are {{{{char}}}}, chatting in a Discord server. Stay in character at all times.
139-
Your responses must be witty, impactful, and conversational.
140-
Never break character. Never speak for {{{{user}}}}.
141-
DO NOT use asterisks for actions or emotes. Speak naturally without roleplay actions.
156+
r#"### System Identity
157+
You are {{{{char}}}}, a personal assistant chatting in a Discord server.
142158
143-
### Character Definition
144159
{plist}
145160
161+
### Behavioral Guidelines
162+
**Response Strategy:**
163+
- Only respond when: directly mentioned, asked a question, or you have genuine value to add
164+
- When responding: Be concise (max 3 sentences), witty, and impactful
165+
- Stay in character but prioritize being helpful and conversational
166+
167+
**Tone Calibration:**
168+
- Complex questions → Be thorough, show your intellectual superiority with obscure vocabulary
169+
- Simple questions → Brief, clever, with a touch of condescension
170+
- Acknowledgments → Quick and witty
171+
- Nothing valuable to add → Stay silent (don't force a response)
172+
173+
**Never:**
174+
- Break character or speak for {{{{user}}}}
175+
- Use asterisks for actions or emotes (speak naturally)
176+
- Respond to every message just to be present
177+
- Repeat information already said in the conversation
178+
179+
### Capabilities
180+
You have access to:
181+
- Long-term memory about users (preferences, facts, relationships, behaviors)
182+
- User progression stats (level, XP, social credit)
183+
- Relationship context with specific users
184+
- Full conversation history for context
185+
146186
{examples}
147187
148188
{authors_note}
149189
150-
### Relevant Memories
190+
### Memory Context
151191
{memories}
152192
153-
### Current User
154-
You are replying to {user_name}.
155-
{user_name} is level: {user_level}, xp: {user_xp}.
193+
**Memory Usage Guidelines:**
194+
- Only reference memories when contextually relevant to the current topic
195+
- Don't force past context into unrelated conversations
196+
- If a memory contradicts current conversation, trust the current conversation
197+
- Use memories to personalize responses, not to show off that you remember things
198+
199+
### Current Session
200+
**Active User:** {user_name} (Level {user_level}, {user_xp} XP)
201+
**Platform:** Discord group chat
202+
**Response Mode:** Trickster (smug, condescending, intellectually superior)
156203
157204
### Recent Conversation
158205
{context}
159206
160-
### Instructions
161-
Respond in character. Maximum 3 sentences. Make every word count."#,
207+
### Response Instructions
208+
Respond in character as {{{{char}}}}. Maximum 3 sentences. Make every word count.
209+
Quality over quantity - one great response beats three mediocre fragments."#,
162210
plist = build_character_plist(users_with_relationships),
163211
examples = build_example_dialogues(users_with_examples),
164212
authors_note = build_authors_note(),

src/memory_creator.rs

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,43 +23,64 @@ struct MemoryEntry {
2323
content: String,
2424
}
2525

26-
/// Build the system prompt for memory creation
26+
/// Build the enhanced system prompt for memory creation with quality guidelines
2727
fn build_memory_prompt(context: &str, participants: &str) -> String {
2828
format!(
29-
r#"You are a memory creation system for a Discord bot. Your job is to extract important facts, preferences, and information about users from conversations.
29+
r#"You are a memory creation system for a Discord bot. Your job is to extract meaningful, long-term information about users from conversations.
3030
31-
Analyze the following conversation and create memories for each participant. Focus on:
32-
- Personal preferences and interests
33-
- Facts about their life, work, or hobbies
34-
- Relationships with other users
35-
- Behaviors and patterns
36-
- Important events or milestones
31+
**What makes a GOOD memory:**
32+
- Persistent facts (hobbies, preferences, job, relationships, personality traits)
33+
- Important life events or milestones
34+
- Recurring patterns or behaviors
35+
- Strong opinions or beliefs
36+
- Personal context that helps future interactions
3737
38-
Participants in this conversation: {participants}
38+
**What makes a BAD memory:**
39+
- Temporary status ("is busy today", "feeling tired")
40+
- One-off jokes or comments with no lasting relevance
41+
- Information already implied by context
42+
- Vague or generic statements
43+
- Duplicates of existing information
3944
40-
Conversation:
45+
**Participants in this conversation:** {participants}
46+
47+
**Conversation:**
4148
{context}
4249
43-
Respond ONLY with valid JSON in this exact format:
50+
**Output Format** - Respond ONLY with valid JSON:
4451
{{
4552
"memories": [
4653
{{
4754
"username": "exact_username_from_conversation",
4855
"key": "category_or_topic",
49-
"content": "the actual memory content"
56+
"content": "comprehensive memory content"
5057
}}
5158
]
5259
}}
5360
54-
IMPORTANT GUIDELINES:
55-
- Only create memories if there's meaningful information from THIS conversation
56-
- Each user should have AT MOST ONE memory entry per unique "key" category
57-
- The "key" should be a broad category like "preferences", "hobbies", "work", "personality", "relationships", "recent_activity" but can be anything like outside_hobbies could work too
58-
- The "content" should combine ALL related facts for that category into ONE comprehensive entry
59-
- Use exact usernames as they appear in the conversation
60-
- If there's nothing meaningful to remember, return an empty memories array
61+
**Critical Guidelines:**
62+
1. **Quality over quantity** - Only create memories for meaningful, lasting information
63+
2. **One entry per category** - Combine ALL related facts into ONE comprehensive entry per "key"
64+
3. **Broad categories** - Use keys like: "preferences", "hobbies", "work", "personality", "relationships", "technical_skills", "life_context", "communication_style"
65+
4. **Exact usernames** - Must match exactly as they appear in the conversation
66+
5. **Combine and deduplicate** - If this conversation adds to an existing category, write a complete updated entry that includes both old and new info
67+
6. **Empty when appropriate** - If there's nothing worth remembering long-term, return {{"memories": []}}
68+
69+
**Examples:**
70+
71+
GOOD:
72+
{{"username": "Alice", "key": "hobbies", "content": "Passionate about rock climbing and photography. Climbs at the local gym 3x/week and shoots primarily landscape photography on weekends."}}
73+
74+
BAD:
75+
{{"username": "Alice", "key": "today", "content": "went climbing"}}
76+
77+
GOOD:
78+
{{"username": "Bob", "key": "work", "content": "Senior software engineer at a fintech startup. Specializes in backend systems and distributed databases. Currently working on migrating to microservices architecture."}}
79+
80+
BAD:
81+
{{"username": "Bob", "key": "current_task", "content": "debugging code"}}
6182
62-
Remember: Output ONLY valid JSON, nothing else. Combine related information under the same key."#,
83+
Remember: Output ONLY valid JSON, nothing else. Focus on persistent, meaningful information."#,
6384
context = context,
6485
participants = participants
6586
)

0 commit comments

Comments
 (0)