Skip to content

armgit / kwant

Public Imported from GitHub
0

Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.

Router: in #general, a close call with no words behind it goes to the Concierge (#258)

Oleksandr Ivanchenkob4b12f3dda63
diff --git a/src/router/team.rs b/src/router/team.rs
index 0caefadf..62e4b946 100644
--- a/src/router/team.rs
+++ b/src/router/team.rs
@@ -982,20 +982,29 @@ pub fn pick_by_words<'a>(
return Some(p);
}
let tied: Vec<&'a Kwant> = best.iter().map(|&i| scored[i].0).take(2).collect();
+ // The words the tied bots matched: what makes the tie a close call worth asking about
+ let mut tied_terms: Vec<String> = Vec::new();
+ for &i in best.iter().take(2) {
+ for t in &scored[i].2 {
+ if !tied_terms.contains(t) {
+ tied_terms.push(t.clone());
+ }
+ }
+ }
// 5. Nothing in the message matched (or two bots tied on words): the bot that spoke last, else
// the lead, with no fit. Laya alone never picks: it sees only titles, and its confident guess
// sent "Best place to eat corn dogs in Munich tomorrow?" to a TikTok scriptwriter. A tie is a
// close call between the tied bots.
- let (fit, choices) = if tied.len() > 1 { (0.45, tied) } else { (0.0, vec![]) };
+ let (fit, choices, terms) = if tied.len() > 1 { (0.45, tied, tied_terms) } else { (0.0, vec![], vec![]) };
if let Some(k) = last_speaker.and_then(|id| members.iter().find(|m| m.id == id)).filter(|k| !avoided(k)) {
// "thanks", "make it shorter", "and for Berlin?" carry on with whoever is talking
let fit = if choices.is_empty() && (is_small_talk(prompt) || reads_as_follow_up(prompt)) { ROUTE_AT } else { fit };
let reason = format!("Nothing in your message named a role, so {} ({}), who spoke last here, carries on", k.name, k.title);
- return Some(Pick { kwant: k, basis: "last", reason, terms: vec![], fit, choices });
+ return Some(Pick { kwant: k, basis: "last", reason, terms, fit, choices });
}
let reason = format!("No one's role matched this, so it went to the {lead_word}, {} ({})", lead.name, lead.title);
- Some(Pick { kwant: lead, basis: "lead", reason, terms: vec![], fit, choices })
+ Some(Pick { kwant: lead, basis: "lead", reason, terms, fit, choices })
}
/// Everyday words that say nothing about whose work a request is. They never count as shared
@@ -1058,14 +1067,20 @@ pub enum Settle {
/// candidates) asks the person. Below that, #general (every bot in the space) leans to the
/// Concierge rather than to whichever specialist happened to lead or speak last; any other channel
/// leans to its own members, so a low score stays with the last speaker or lead as before.
+///
+/// In #general a close call asks only with words of the message behind it. Laya's titles-only
+/// guess against a weak hint for another bot ("Compare lidl and edeka": Laya said Community,
+/// "compare" leans to the Analyst) names no one's work, so the Concierge answers rather than
+/// asking the person to pick between two bots the message isn't for.
pub fn settle(route: &ChannelRoute, general: bool, has_concierge: bool) -> Settle {
if route.fit >= ROUTE_AT {
return Settle::Route;
}
- if route.fit >= ASK_FROM && route.choices.len() >= 2 {
+ let concierge = general && has_concierge;
+ if route.fit >= ASK_FROM && route.choices.len() >= 2 && !(concierge && route.matched_terms.is_empty()) {
return Settle::Ask(route.choices.iter().take(2).cloned().collect());
}
- if general && has_concierge {
+ if concierge {
return Settle::Concierge;
}
Settle::Route
@@ -1849,6 +1864,33 @@ mod fit_tests {
assert_eq!((p.kwant.id.as_str(), settle(&route_of(&p), true, true)), ("k-fe", Settle::Route));
}
+ /// Oleks 2026-11-03: in #general "Compare lidl and edeka" showed "Who should answer this?"
+ /// with Community and Analyst. Laya guessed Community from titles alone and "compare" only
+ /// leans to the Analyst: no word of the message is either bot's work, so the Concierge answers.
+ /// Outside #general (or with the Concierge removed) the close call still asks.
+ #[test]
+ fn a_titles_only_guess_against_a_weak_hint_goes_to_the_concierge_in_general() {
+ let members = kitchen();
+ let laya = Some(LayaGuess { kwant: &members[6], confident: true });
+ for prompt in ["Compare lidl and edeka", "Compare Aldi with lidl"] {
+ let p = pick_member_after(prompt, "k-tl", &members, laya, "channel lead", None).unwrap();
+ assert!((ASK_FROM..ROUTE_AT).contains(&p.fit), "{prompt}: {p:?}");
+ assert!(p.terms.is_empty(), "{prompt}: {p:?}");
+ let ids: Vec<&str> = p.choices.iter().map(|k| k.id.as_str()).collect();
+ assert_eq!(ids, ["k-comm", "k-data"], "{prompt}");
+ assert_eq!(settle(&route_of(&p), true, true), Settle::Concierge, "{prompt}");
+ let ask = Settle::Ask(vec!["k-comm".into(), "k-data".into()]);
+ assert_eq!(settle(&route_of(&p), true, false), ask, "{prompt}");
+ assert_eq!(settle(&route_of(&p), false, true), ask, "{prompt}");
+ // Without Laya's guess there is no one to ask about either
+ let p = pick_member_after(prompt, "k-tl", &members, None, "channel lead", None).unwrap();
+ assert_eq!(settle(&route_of(&p), true, true), Settle::Concierge, "{prompt}: {p:?}");
+ }
+ // A real close call in #general still asks
+ let p = pick_member_after("Ideas for our TikTok this week?", "k-tl", &members, laya, "channel lead", None).unwrap();
+ assert!(matches!(settle(&route_of(&p), true, true), Settle::Ask(_)), "{p:?}");
+ }
+
/// An entry of a bot's covers list counts like a word of its title; empty lists change nothing.
#[test]
fn covers_route_a_message_to_the_bot_that_covers_it() {
diff --git a/tests/router_eval/README.md b/tests/router_eval/README.md
index a3e04cb4..25d5544e 100644
--- a/tests/router_eval/README.md
+++ b/tests/router_eval/README.md
@@ -1,7 +1,7 @@
# Router eval
-47 messages with the expected routing, across 3 fixture spaces (`kitchen` mirrors the corn-dog screenshot,
-`software`, `duo`). 15 expect `concierge`, 2 expect `ask`. The runner is `tests/router_eval_test.rs`.
+48 messages with the expected routing, across 3 fixture spaces (`kitchen` mirrors the corn-dog screenshot,
+`software`, `duo`). 16 expect `concierge`, 2 expect `ask`. The runner is `tests/router_eval_test.rs`.
cargo test --test router_eval_test router_eval -- --ignored --nocapture
diff --git a/tests/router_eval/cases.json b/tests/router_eval/cases.json
index 51d6e345..85a0fdd8 100644
--- a/tests/router_eval/cases.json
+++ b/tests/router_eval/cases.json
@@ -757,6 +757,23 @@
]
},
"note": "Multi-role goes to the lead"
+ },
+ {
+ "id": 48,
+ "space": "kitchen",
+ "channel": "general",
+ "message": "Compare lidl and edeka",
+ "expect": {
+ "route": "concierge",
+ "basis": [
+ "concierge"
+ ]
+ },
+ "laya": {
+ "pick": "Community",
+ "confident": true
+ },
+ "note": "2026-11-03: a titles-only Laya guess (Community) against a weak hint (\"compare\" for the Analyst) asked who should answer."
}
]
}
\ No newline at end of file
diff --git a/tests/router_eval_test.rs b/tests/router_eval_test.rs
index c2b69e8e..d8eaee60 100644
--- a/tests/router_eval_test.rs
+++ b/tests/router_eval_test.rs
@@ -183,7 +183,7 @@ fn router_eval() {
/// Cases the router must get right, checked in CI: every no-match case (to the Concierge in
/// #general), the specialist questions and the go-ahead that main already routed right and the
/// first fit score broke (#12, #13, #16, #17, #40), and #35, where "go" made Backend a runner-up.
-const MUST_PASS: &[u32] = &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 16, 17, 20, 35, 36, 40, 44, 45];
+const MUST_PASS: &[u32] = &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 16, 17, 20, 35, 36, 40, 44, 45, 48];
#[test]
fn router_eval_must_pass() {