MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / query_ask

Function query_ask

atomic-cli/src/commands/rpc.rs:6973–7038  ·  view source on GitHub ↗

`atomic query ask` over QueryGraph (RagAsk) — the agentic loop runs handler-side; the CLI renders the same answer/stats/JSON lines. --verbose's live tool-call trace becomes an after-the-fact trace over the wire (the unary-RPC limit, documented in the dispatch guard).

(args: &super::query::QueryAsk)

Source from the content-addressed store, hash-verified

6971/// --verbose's live tool-call trace becomes an after-the-fact trace over
6972/// the wire (the unary-RPC limit, documented in the dispatch guard).
6973pub fn query_ask(args: &super::query::QueryAsk) -> CliResult<bool> {
6974 let Some(session) = Service::open()? else {
6975 return Ok(false);
6976 };
6977 let request = pb::QueryGraphRequest {
6978 repository: Some(session.reference.clone()),
6979 limit: 0,
6980 query: Some(pb::query_graph_request::Query::RagAsk(pb::RagAskQuery {
6981 question: args.question.clone(),
6982 top_k: 0,
6983 max_turns: Some(args.max_turns as u32),
6984 verbose: Some(args.verbose),
6985 })),
6986 view: None,
6987 };
6988 let response = session.query_graph(request)?;
6989 let Some(bundle) = response
6990 .ask_result
6991 .as_ref()
6992 .filter(|bytes| bytes.schema == "atomic.query.ask.v1")
6993 else {
6994 return Err(CliError::Internal(anyhow::anyhow!(
6995 "the service returned no ask result"
6996 )));
6997 };
6998 let result: atomic_repository::AgentResult = serde_json::from_slice(&bundle.payload)
6999 .map_err(|error| CliError::Internal(anyhow::anyhow!("ask result: {error}")))?;
7000 if args.json {
7001 let json = serde_json::json!({
7002 "query": args.question,
7003 "answer": result.answer,
7004 "model": result.model,
7005 "turns": result.turns,
7006 "input_tokens": result.total_usage.input_tokens,
7007 "output_tokens": result.total_usage.output_tokens,
7008 "tool_trace": result.tool_trace,
7009 });
7010 println!("{}", serde_json::to_string_pretty(&json).unwrap());
7011 } else {
7012 println!("{}\n", result.answer);
7013 let cache_info = if result.total_usage.cache_read_tokens > 0 {
7014 format!(
7015 ", {} cache read + {} cache write",
7016 result.total_usage.cache_read_tokens, result.total_usage.cache_creation_tokens
7017 )
7018 } else {
7019 String::new()
7020 };
7021 let secs = (response.ask_elapsed_ms.unwrap_or(0)) as f64 / 1000.0;
7022 let duration = if secs < 60.0 {
7023 format!("{:.1}s", secs)
7024 } else {
7025 format!("{}m {:.0}s", (secs / 60.0) as u64, secs % 60.0)
7026 };
7027 println!(
7028 " — {} ({} turns, {}, {} in + {} out tokens{})",
7029 result.model,
7030 result.turns,

Callers 1

runMethod · 0.85

Calls 4

openFunction · 0.85
as_refMethod · 0.80
cloneMethod · 0.45
query_graphMethod · 0.45

Tested by

no test coverage detected