Skip to main content

open_agent/client/
query.rs

1/// A stream of content, optional reasoning, and one final finish event.
2pub type EventStream = Pin<Box<dyn Stream<Item = Result<StreamEvent>> + Send>>;
3
4/// Starts a single-turn streaming query using the configured protocol.
5///
6/// Does not execute tools or lifecycle hooks. For conversation history and
7/// automatic tool execution, use [`Client`].
8pub async fn query(prompt: &str, options: &AgentOptions) -> Result<EventStream> {
9    let client = model_http_client_builder(options)
10        .build()
11        .map_err(Error::Http)?;
12
13    let mut messages = Vec::new();
14
15    if !options.system_prompt().is_empty() {
16        messages.push(OpenAIMessage {
17            role: "system".to_string(),
18            content: Some(OpenAIContent::Text(options.system_prompt().to_string())),
19            tool_calls: None,
20            tool_call_id: None,
21        });
22    }
23
24    messages.push(OpenAIMessage {
25        role: "user".to_string(),
26        content: Some(OpenAIContent::Text(prompt.to_string())),
27        tool_calls: None,
28        tool_call_id: None,
29    });
30
31    let request = request::build_request(options, messages);
32
33    stream_request(&client, options, &request).await
34}