Skip to main content

codetether_agent/search/
prompt.rs

1//! Prompt builder for the LLM-based search router.
2//!
3//! Produces the single user-turn prompt that instructs the router model
4//! to pick one (or more) backends for a user query and return structured
5//! JSON. Router must emit JSON only — no markdown.
6
7/// System message for the router model.
8pub const ROUTER_SYSTEM: &str = "You are a search router. Given a user query, pick the best \
9    search backend(s) and return ONLY JSON. No prose, no markdown.";
10
11/// Build the user prompt.
12///
13/// # Examples
14///
15/// ```rust
16/// use codetether_agent::search::prompt::build_user_prompt;
17/// let p = build_user_prompt("how to center a div", 1);
18/// assert!(p.contains("websearch"));
19/// assert!(p.contains("how to center a div"));
20/// ```
21pub fn build_user_prompt(query: &str, top_n: usize) -> String {
22    format!(
23        "Query:\n{query}\n\n\
24         Available backends:\n\
25         - grep: exact or regex text search across the workspace (args: {{\"pattern\": string, \"is_regex\"?: bool, \"path\"?: string, \"limit\"?: int}})\n\
26         - glob: filename glob search (args: {{\"pattern\": string}})\n\
27         - websearch: live web search (args: {{\"query\": string, \"max_results\"?: int}})\n\
28         - webfetch: fetch a specific URL (args: {{\"url\": string}})\n\
29         - memory: search persisted agent memory (args: {{\"action\": \"search\", \"query\": string}})\n\
30         - rlm: semantic analysis across large codebases (args: {{\"action\": \"search\", \"query\": string}})\n\n\
31         Return JSON ONLY in this exact shape:\n\
32         {{\"choices\":[{{\"backend\":\"grep|glob|websearch|webfetch|memory|rlm\",\"args\":{{...}}}}]}}\n\
33         Pick at most {top_n} choice(s). Order by best first."
34    )
35}