Skip to main content

microclaw_engine/
relationship.rs

1//! Relationship familiarity: a light, prompt-level sense of how well the bot
2//! "knows" the person it's talking to, derived from how much history they share
3//! (the stored message count). People treat a stranger and an old friend
4//! differently; this nudges tone the same way.
5//!
6//! Conservative by design: only the extremes (brand-new vs. long-time) inject
7//! anything. The broad middle stays silent so we don't over-prompt.
8
9/// Threshold (messages) below which a chat is treated as brand-new.
10const NEW_MAX: i64 = 6;
11/// Threshold (messages) at/above which a chat is treated as long-running.
12const FAMILIAR_MIN: i64 = 200;
13
14/// One-line familiarity guidance for the system prompt, or `None` for the
15/// broad middle where no nudge is warranted.
16pub fn familiarity_hint(message_count: i64) -> Option<&'static str> {
17    if message_count < NEW_MAX {
18        Some(
19            "This looks like one of your first conversations with this person. Be welcoming and a \
20touch more explicit — you don't share much history yet, so don't assume prior context.",
21        )
22    } else if message_count >= FAMILIAR_MIN {
23        Some(
24            "You and this person go back a long way. You can be relaxed and familiar, and lean on \
25the history and context you already share.",
26        )
27    } else {
28        None
29    }
30}
31
32#[cfg(test)]
33mod tests {
34    use super::*;
35
36    #[test]
37    fn new_chats_get_a_welcoming_nudge() {
38        assert!(familiarity_hint(0).unwrap().contains("first conversations"));
39        assert!(familiarity_hint(5).is_some());
40    }
41
42    #[test]
43    fn the_middle_stays_silent() {
44        assert!(familiarity_hint(6).is_none());
45        assert!(familiarity_hint(50).is_none());
46        assert!(familiarity_hint(199).is_none());
47    }
48
49    #[test]
50    fn long_running_chats_get_a_familiar_nudge() {
51        assert!(familiarity_hint(200)
52            .unwrap()
53            .contains("go back a long way"));
54        assert!(familiarity_hint(5000).is_some());
55    }
56}