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

Function query_ask

atomic-cli/src/commands/rpc.rs:7013–7078  ·  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

7011/// --verbose's live tool-call trace becomes an after-the-fact trace over
7012/// the wire (the unary-RPC limit, documented in the dispatch guard).
7013pub fn query_ask(args: &super::query::QueryAsk) -> CliResult<bool> {
7014 let Some(session) = Service::open()? else {
7015 return Ok(false);
7016 };
7017 let request = pb::QueryGraphRequest {
7018 repository: Some(session.reference.clone()),
7019 limit: 0,
7020 query: Some(pb::query_graph_request::Query::RagAsk(pb::RagAskQuery {
7021 question: args.question.clone(),
7022 top_k: 0,
7023 max_turns: Some(args.max_turns as u32),
7024 verbose: Some(args.verbose),
7025 })),
7026 view: None,
7027 };
7028 let response = session.query_graph(request)?;
7029 let Some(bundle) = response
7030 .ask_result
7031 .as_ref()
7032 .filter(|bytes| bytes.schema == "atomic.query.ask.v1")
7033 else {
7034 return Err(CliError::Internal(anyhow::anyhow!(
7035 "the service returned no ask result"
7036 )));
7037 };
7038 let result: atomic_repository::AgentResult = serde_json::from_slice(&bundle.payload)
7039 .map_err(|error| CliError::Internal(anyhow::anyhow!("ask result: {error}")))?;
7040 if args.json {
7041 let json = serde_json::json!({
7042 "query": args.question,
7043 "answer": result.answer,
7044 "model": result.model,
7045 "turns": result.turns,
7046 "input_tokens": result.total_usage.input_tokens,
7047 "output_tokens": result.total_usage.output_tokens,
7048 "tool_trace": result.tool_trace,
7049 });
7050 println!("{}", serde_json::to_string_pretty(&json).unwrap());
7051 } else {
7052 println!("{}\n", result.answer);
7053 let cache_info = if result.total_usage.cache_read_tokens > 0 {
7054 format!(
7055 ", {} cache read + {} cache write",
7056 result.total_usage.cache_read_tokens, result.total_usage.cache_creation_tokens
7057 )
7058 } else {
7059 String::new()
7060 };
7061 let secs = (response.ask_elapsed_ms.unwrap_or(0)) as f64 / 1000.0;
7062 let duration = if secs < 60.0 {
7063 format!("{:.1}s", secs)
7064 } else {
7065 format!("{}m {:.0}s", (secs / 60.0) as u64, secs % 60.0)
7066 };
7067 println!(
7068 " — {} ({} turns, {}, {} in + {} out tokens{})",
7069 result.model,
7070 result.turns,

Callers 1

runMethod · 0.85

Calls 4

as_refMethod · 0.80
openFunction · 0.50
cloneMethod · 0.45
query_graphMethod · 0.45

Tested by

no test coverage detected