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.
Rust ai-agentsai-assistantai-botautomationbotbots-teamchatbotclaude-duetgrokgrok-botgrok-bot-alternativeharnessllmmulti-agentopenai-dotsopenbotpersonal-agentrustself-hostedselfhosted-ai
Bots research before asking, in team discussions too
Lin (kwant bot)ca44dc21ad45
diff --git a/src/router/team.rs b/src/router/team.rsindex bc978663..b16d4fc3 100644--- a/src/router/team.rs+++ b/src/router/team.rs@@ -725,6 +725,9 @@ fn direct(pick: Option<Pick<'_>>, team: &Team) -> TeamDecision {/// specialist, and that names no other bot: "need a new workout plan" is FitnessCoach's, and shouldn't/// start a discussion that puts TravelPlanner first. "Plan the migration…" still is a discussion.fn settles_without_discussion(prompt: &str, pick: &Option<Pick<'_>>, members: &[Kwant]) -> bool {+ if is_lookup_nudge(prompt) {+ return true;+ }let Some(p) = pick else { return true };if p.basis == "team" || p.reason.contains("was named in your message") || (is_code_request(prompt) && matches!(p.basis, "keywords" | "skills" | "only")) {return true;@@ -734,6 +737,17 @@ fn settles_without_discussion(prompt: &str, pick: &Option<Pick<'_>>, members: &[matches!(p.basis, "keywords" | "skills") && !p.terms.is_empty() && named <= 1 && !has_strong_discussion_word(prompt)}+/// A follow-up telling the team to look its own questions up ("You can answer your questions by+/// checking the site!") goes to one bot to do the research; a new discussion would only ask again.+fn is_lookup_nudge(prompt: &str) -> bool {+ const LOOKUP: &[&str] = &["check", "checking", "look", "lookup", "research", "search", "google", "find", "read", "visit"];+ const BACK: &[&str] = &["question", "questions", "yourself", "yourselves", "site", "website", "page", "docs"];+ let words = tokens(prompt);+ !is_complex_query(prompt)+ && words.iter().any(|w| LOOKUP.contains(&w.as_str()))+ && words.iter().any(|w| BACK.contains(&w.as_str()))+}+pub fn parse_laya_team_answers(prompt: &str,data: &serde_json::Value,@@ -1063,6 +1077,25 @@ mod tests {assert!(parse_laya_kwant_choice(&unknown, &members).is_none());}+ #[test]+ fn a_nudge_to_look_it_up_goes_to_one_bot_not_a_new_discussion() {+ let (team, members) = make_test_fixture();+ let sure = json!({+ "answers": {+ "team_decision": { "choice": "discuss", "probabilities": { "discuss": 0.9 } },+ "lead_kwant": { "choice": "kwant-1" }+ }+ });+ for nudge in ["You can answer on your questions by checking site!", "look it up yourself", "read the docs page"] {+ let decision = parse_laya_team_answers(nudge, &sure, &team, &members).unwrap();+ assert!(matches!(decision, TeamDecision::Direct { .. }), "{nudge}");+ assert!(matches!(heuristic_team_decision(nudge, &team, &members), TeamDecision::Direct { .. }), "{nudge}");+ }+ // A real planning request still starts a discussion+ let plan = parse_laya_team_answers("Plan the site migration and check the docs", &sure, &team, &members).unwrap();+ assert!(matches!(plan, TeamDecision::Discuss { .. }));+ }+#[test]fn test_parse_laya_team_answers_json() {let (team, members) = make_test_fixture();diff --git a/src/server/continuity.rs b/src/server/continuity.rsindex 5f86ff16..ae29aa25 100644--- a/src/server/continuity.rs+++ b/src/server/continuity.rs@@ -126,6 +126,9 @@ pub async fn prompt_block(clearly want: a shopping list with a meal plan; with a new routine, a sample of what it will send (a \motivation, the reminder's checklist); a monthly routine that sends a report you wrote. When a plan has \a start date or deadline, schedule a check-in with `follow_up_create` a few days in.\n\+ - Research before you ask: first try your tools (the named site and its pricing and docs pages, web search, files, \+ notes, earlier chats). Ask only what stays unknowable or is the person's decision, and say what you checked. Told \+ you could have looked it up? Look it up now.\n\- For a reversible choice (wording, order, a setting that can change later), don't `ask_user`: pick, state the \assumption in your reply and continue. Ask only before a step that can't be undone or reaches outside (sending, \paying, deleting, contacting someone), or with no sensible default.\n\diff --git a/src/server/discussion.rs b/src/server/discussion.rsindex 76ba719a..ddeb1e3a 100644--- a/src/server/discussion.rs+++ b/src/server/discussion.rs@@ -11,6 +11,11 @@ pub const TURN_LABEL: &str = "Team Discussion";/// Prefix of `reasoning_content` on the closing summary.pub const SUMMARY_LABEL: &str = "Team Summary";+/// Every discussion turn reads this: look things up before asking the user or leaving a question open.+pub const RESEARCH_FIRST: &str = "Research before you ask: when something is unclear (the audience, the price, what a product does), \+first try to answer it with your tools: open the site or URL in the user's message and its pricing, docs and about pages, \+search the web, read the files, your notes and earlier chats. Use what you find and name the source in a few words.";+/// Turns allowed per discussion, not counting the closing summary.pub const MAX_TURNS: usize = 5;/// How often one kwant may speak in a discussion (a reply when a teammate @mentions them back).@@ -60,9 +65,11 @@ pub fn opening_prompt(user_prompt: &str, team: &str, responders: &[String]) -> S"You're opening a team discussion in @{team} about the user's latest message. {next}\n\n\User's message:\n{user_prompt}\n\n\How to open:\n\- - If you truly can't make progress without information only the user has, reply with {ask} followed by at most 2 short questions; the team then waits for the user's answer. Prefer stating a reasonable assumption in one line and moving on.\n\- - Otherwise give your take from your role: concrete and numbered, so teammates can react to specific points.\n\- - Under 150 words. No preamble, don't introduce yourself, don't write the final answer yet.",+ - {research}\n\+ - Only if you looked and still can't make progress without something only the user knows or decides (budget, priorities, approvals), reply with {ask} followed by at most 2 short questions and one line on what you checked; the team then waits for the user's answer. Prefer stating a reasonable assumption in one line and moving on.\n\+ - Otherwise give your take from your role: concrete and numbered, so teammates can react to specific points. Start with what you found if you looked something up.\n\+ - Under 250 words. No preamble, don't introduce yourself, don't write the final answer yet.",+ research = RESEARCH_FIRST,ask = ASK_USER,)}@@ -78,9 +85,11 @@ pub fn reply_prompt(user_prompt: &str, team: &str, previous_speaker: &str, askedYour turn:\n\- React to what teammates said, naming them without @: agree, challenge, or refine specific points. Don't restart from scratch or repeat them.\n\- Add only what your expertise brings that's still missing.\n\- - Under 120 words. No preamble.\n\+ - {research} If a teammate left a question that a lookup answers, answer it.\n\+ - Under 200 words. No preamble.\n\- Only if one teammate's input is truly needed, @mention that one teammate with a specific question.\n\- If you have nothing meaningful to add, reply with exactly {pass} and nothing else.",+ research = RESEARCH_FIRST,pass = PASS,)}@@ -89,10 +98,14 @@ pub fn summary_prompt(user_prompt: &str, contributors: &[String]) -> String {format!("Wrap up the team discussion above (contributors: {}). Write the team's single final answer to the user's message:\n{user_prompt}\n\n\- Lead with the answer or recommendation; merge the best points and resolve disagreements, crediting teammates by name where it helps.\n\- - Bullets, under 200 words.\n\- - End with \"Open questions:\" only if decisions remain for the user.\n\+ - Bullets, under 300 words.\n\+ - {research}\n\+ - Never leave open a question that the user's message, a URL in it, the discussion above or a quick lookup can answer: \+ look it up and give the answer with its source, or state the assumption you made.\n\+ - End with \"Open questions:\" only for real decisions the user must make (budget, priorities, approvals), and say what you checked.\n\- No @mentions and no commentary about the discussion itself.",contributors.join(", "),+ research = RESEARCH_FIRST,)}@@ -112,6 +125,28 @@ mod tests {assert_eq!(parse_reply("I agree with TechLead."), Reply::Speak("I agree with TechLead.".into()));}+ #[test]+ fn every_discussion_prompt_says_research_before_asking() {+ let team = vec!["Writer".to_string()];+ for prompt in [+ opening_prompt("Plan kwant.si marketing", "core", &team),+ reply_prompt("Plan kwant.si marketing", "core", "Strategist", None),+ summary_prompt("Plan kwant.si marketing", &team),+ ] {+ assert!(prompt.contains(RESEARCH_FIRST), "{prompt}");+ }+ let open = opening_prompt("Plan kwant.si marketing", "core", &team);+ assert!(open.contains("Only if you looked and still can't"), "{open}");+ }++ #[test]+ fn summary_keeps_open_questions_for_real_decisions_only() {+ let summary = summary_prompt("Create a marketing plan for kwant.si", &["Strategist".into(), "Writer".into()]);+ assert!(summary.contains("Never leave open a question that the user's message, a URL in it"), "{summary}");+ assert!(summary.contains("only for real decisions the user must make"), "{summary}");+ assert!(!summary.contains("only if decisions remain for the user"), "{summary}");+ }+#[test]fn labels_share_prefixes_the_ui_groups_on() {assert!(turn_label(2, "core").starts_with(TURN_LABEL));diff --git a/tests/initiative_test.rs b/tests/initiative_test.rsindex 4a17c386..94c83aa7 100644--- a/tests/initiative_test.rs+++ b/tests/initiative_test.rs@@ -333,10 +333,10 @@ async fn bots_with_tools_are_told_how_to_work_and_bots_without_are_not() {let section = &with[with.find("[How to work]").unwrap()..];let section = §ion[..section[1..].find("\n\n[").map_or(section.len(), |i| i + 1)];// Proactive extras and check-ins, but never ones that cost money or reach outside, and no asking for reversible ones- for words in ["Be proactive", "shopping list", "a few days in", "Don't ask permission", "End by naming every extra", "I also added a shopping list", "list or tips in your reply", "Undo", "10 changes", "costs money", "Never redo what the person undid", "a sample of what it will send", "saved notes don't", "state the assumption in your reply", "can't be undone or reaches outside"] {+ for words in ["Be proactive", "shopping list", "a few days in", "Don't ask permission", "End by naming every extra", "I also added a shopping list", "list or tips in your reply", "Undo", "10 changes", "costs money", "Never redo what the person undid", "a sample of what it will send", "saved notes don't", "state the assumption in your reply", "can't be undone or reaches outside", "Research before you ask", "say what you checked", "Look it up now"] {assert!(section.contains(words), "{words}: {section}");}// Bots' own tools can only be refused by name: the prompt says where the person switches themassert!(with.contains("App settings (gear at the bottom of the space rail) → \"Bots can use their own tools\""), "{with}");- assert!(section.len() < 1700, "keep it tight: {} bytes", section.len());+ assert!(section.len() < 2000, "keep it tight: {} bytes", section.len());}