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
31o key-numbers-as-list: ask bots for key numbers as a '- **Label:** value' list (#932)
Oleksandr Ivanchenkobe6b037a2559
diff --git a/docs/smart-results.md b/docs/smart-results.mdindex 49849f96..93dae763 100644--- a/docs/smart-results.md+++ b/docs/smart-results.md@@ -32,7 +32,7 @@ Code: `src/server/smart_results/` (contract types, selectors, checks) andone block.- **The bot prompt line:** every turn's system prompt carries `smart_results::PROMPT_LINE` once(in the cached tail, `drivers::TurnInput::system_prompt_parts`), asking for tables, numbered- steps, an "Ingredients" list then numbered steps for a recipe, and `**Label:** value` lines.+ steps, an "Ingredients" list then numbered steps for a recipe, and a `- **Label:** value` list for key numbers.- **What it never costs:** the reply. If a selector panics, a block fails its checks, or the writefails, kwant logs it and saves the message exactly as before.- **Edits:** when a reply's text is replaced (`set_message_text`), its block is deleted, because thediff --git a/src/server/smart_results/mod.rs b/src/server/smart_results/mod.rsindex 988c9e80..fa1d64a4 100644--- a/src/server/smart_results/mod.rs+++ b/src/server/smart_results/mod.rs@@ -50,7 +50,7 @@ pub const PICK_REASON: &str = "named as the pick in this reply";/// comparison. Every header cell must be filled, or the table stays text.pub const PROMPT_LINE: &str = "When you compare options use a table with every header cell filled (one row per option; for \just two, a column each and a row per point), for steps use a numbered list, for a recipe an 'Ingredients' list then \- numbered steps, and for key numbers use '**Label:** value' lines; kwant shows them as cards and charts.";+ numbered steps, and for key numbers a list of '- **Label:** value' items; kwant shows them as cards and charts.";/// The checked block set for a reply: the first candidate, in priority order ([`rank`]), whose/// type is enabled and that passes [`validate`]; `None` when there isn't one. A selector bug must never@@ -602,3 +602,34 @@ pub struct Recipe {pub notes: Vec<String>,pub provenance: Provenance,}++#[cfg(test)]+mod tests {+ use super::*;++ /// The shape [`PROMPT_LINE`] asks for key numbers: the quoted example after "key numbers".+ fn key_numbers_shape() -> &'static str {+ let after = &PROMPT_LINE[PROMPT_LINE.find("key numbers").expect("PROMPT_LINE asks for key numbers")..];+ let open = after.find('\'').expect("the key-numbers example is quoted") + 1;+ let len = after[open..].find('\'').expect("the key-numbers example is closed");+ &after[open..open + len]+ }++ /// Mira's UX pass at 0.9.32, fix #2: a bot that writes key numbers exactly the way the prompt+ /// asks gets metric tiles, not one run-on paragraph.+ #[test]+ fn key_numbers_written_as_the_prompt_asks_draw_as_metrics() {+ let shape = key_numbers_shape();+ assert!(shape.contains("Label") && shape.contains("value"), "{shape:?}");+ let lines: Vec<String> = [("Revenue", "EUR 18,420"), ("Orders", "627"), ("Refunds", "EUR 212")]+ .iter()+ .map(|(label, value)| shape.replace("Label", label).replace("value", value))+ .collect();+ let reply = format!("Here are October's numbers:\n\n{}\n", lines.join("\n"));+ let set = compute(&reply).unwrap_or_else(|| panic!("no block for the prompt's own shape {shape:?}:\n{reply}"));+ let Some(Block::Metrics(m)) = set.blocks.first() else { panic!("not metrics for {shape:?}: {set:?}") };+ let labels: Vec<&str> = m.items.iter().map(|i| i.label.as_str()).collect();+ assert_eq!(labels, ["Revenue", "Orders", "Refunds"]);+ assert_eq!(m.items[0].value_text, "EUR 18,420");+ }+}diff --git a/src/server/smart_results/present_result.rs b/src/server/smart_results/present_result.rsindex 2831fdc7..fa5d310f 100644--- a/src/server/smart_results/present_result.rs+++ b/src/server/smart_results/present_result.rs@@ -44,7 +44,7 @@ pub fn handles(name: &str) -> bool {pub fn tools() -> Vec<Value> {vec![json!({"name": NAME,- "description": "Optional. Declare the one block kwant should draw for your final reply (a comparison table, a numbered-steps list), only when the answer's data reads better that way than as plain text; never for a simple answer, and never instead of writing the reply. The data must match your reply text exactly: every label, cell, item and link is checked against it, and a call that doesn't match is dropped and the plain reply is shown. For a comparison, `source` is required: the index (from 0) of the table in your reply that it describes. For a recipe, no `source`: your reply must hold the recipe as an 'Ingredients' list then numbered steps. Call it once, just before your final reply. Types today: comparison, steps and recipe; kwant draws charts, metrics, facts, cards and findings from your reply's own structure (use '**Label:** value' lines for key numbers).",+ "description": "Optional. Declare the one block kwant should draw for your final reply (a comparison table, a numbered-steps list), only when the answer's data reads better that way than as plain text; never for a simple answer, and never instead of writing the reply. The data must match your reply text exactly: every label, cell, item and link is checked against it, and a call that doesn't match is dropped and the plain reply is shown. For a comparison, `source` is required: the index (from 0) of the table in your reply that it describes. For a recipe, no `source`: your reply must hold the recipe as an 'Ingredients' list then numbered steps. Call it once, just before your final reply. Types today: comparison, steps and recipe; kwant draws charts, metrics, facts, cards and findings from your reply's own structure (use a '- **Label:** value' list for key numbers).","inputSchema": {"type": "object","properties": {@@ -149,7 +149,7 @@ fn declared(args: &Value) -> Result<Declared, String> {steps(data, source)?}"chart" | "metrics" | "facts" | "cards" | "findings" => {- return Err(format!("{kind} can't be declared yet; kwant draws it from your reply's own table or '**Label:** value' lines"));+ return Err(format!("{kind} can't be declared yet; kwant draws it from your reply's own table or '- **Label:** value' list"));}"verification" | "files" => return Err(format!("{kind} comes only from kwant's own data")),other => return Err(format!("unknown type {other:?}")),