mcp/common/
streaming_cli.rs1use std::io::{self, Write};
2use tiny_loop::Agent;
3
4pub async fn run_cli_loop(agent: Agent) {
5 let mut agent = agent.stream_callback(|chunk| {
6 print!("{}", chunk);
7 io::stdout().flush().unwrap();
8 });
9
10 println!("Chatbot started. Type 'quit' to exit.\n");
11
12 loop {
13 print!("> ");
14 io::stdout().flush().unwrap();
15
16 let mut input = String::new();
17 io::stdin().read_line(&mut input).unwrap();
18 let input = input.trim();
19
20 if input == "quit" {
21 break;
22 }
23
24 match agent.chat(input).await {
25 Ok(_) => println!("\n"),
26 Err(e) => eprintln!("Error: {}\n", e),
27 }
28 }
29}