vv_agent/sdk/session/run/
query.rs1use crate::sdk::types::agent_status_value;
2use crate::types::AgentStatus;
3
4use super::super::AgentSession;
5
6impl AgentSession {
7 pub fn query(&mut self, prompt: impl Into<String>) -> Result<String, String> {
8 self.query_with_require_completed(prompt, true)
9 }
10
11 pub fn query_with_require_completed(
12 &mut self,
13 prompt: impl Into<String>,
14 require_completed: bool,
15 ) -> Result<String, String> {
16 let run = self.prompt(prompt)?;
17 if run.result.status == AgentStatus::Completed {
18 return Ok(run.result.final_answer.unwrap_or_default());
19 }
20 if require_completed {
21 let reason = run
22 .result
23 .error
24 .clone()
25 .or(run.result.wait_reason.clone())
26 .or(run.result.final_answer.clone())
27 .unwrap_or_else(|| "session query did not complete".to_string());
28 return Err(format!(
29 "Session query failed with status={}: {}",
30 agent_status_value(run.result.status),
31 reason
32 ));
33 }
34 Ok(run
35 .result
36 .final_answer
37 .or(run.result.wait_reason)
38 .or(run.result.error)
39 .unwrap_or_default())
40 }
41}