From 83a2cd1ac24ca0feda34ae877aaf31f41b58b86c Mon Sep 17 00:00:00 2001 From: aichat-agent Date: Thu, 1 Oct 2026 14:58:06 +0000 Subject: feat: add built-in subquery tool with hierarchical query ids * Add config options subquery and subquery_max_depth. * Register an internal subquery function that spawns a fresh LLM query with the current model configuration but without the full context. The model selects context numerically (message_indexes) or by text excerpt (excerpts). * Subqueries can use tools, including further nested subqueries up to subquery_max_depth. * Queries and subqueries get hierarchical ids ([0], [0/1], [0/1/2]) that prefix tool-call prints and spinner messages. --- src/client/common.rs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'src/client/common.rs') diff --git a/src/client/common.rs b/src/client/common.rs index 3b89d11..ed95291 100644 --- a/src/client/common.rs +++ b/src/client/common.rs @@ -403,6 +403,26 @@ pub async fn create_openai_compatible_client_config( Ok(Some((model, clients))) } +async fn eval_tool_calls_with_ctx( + input: &Input, + client: &dyn Client, + tool_calls: Vec, +) -> Result> { + let path = input.query_path(); + let subquery_ctx = crate::config::SubqueryContext::from_input(input); + let mut ctx = crate::function::EvalToolCallsContext { + subquery_ctx: Some(subquery_ctx), + }; + if path.is_empty() { + eval_tool_calls(client.global_config(), tool_calls, &mut ctx).await + } else { + crate::utils::with_query_scope(crate::utils::format_query_path(&path), async { + eval_tool_calls(client.global_config(), tool_calls, &mut ctx).await + }) + .await + } +} + pub async fn call_chat_completions( input: &Input, print: bool, @@ -432,7 +452,10 @@ pub async fn call_chat_completions( client.global_config().read().print_markdown(&text)?; } } - Ok((text, eval_tool_calls(client.global_config(), tool_calls)?)) + Ok(( + text, + eval_tool_calls_with_ctx(input, client, tool_calls).await?, + )) } Err(err) => Err(err), } @@ -463,7 +486,10 @@ pub async fn call_chat_completions_streaming( if !text.is_empty() && !text.ends_with('\n') { println!(); } - Ok((text, eval_tool_calls(client.global_config(), tool_calls)?)) + Ok(( + text, + eval_tool_calls_with_ctx(input, client, tool_calls).await?, + )) } Err(err) => { if !text.is_empty() { -- cgit v1.2.3