diff options
| author | aichat-agent <agent@aichat.local> | 2026-10-01 14:58:06 +0000 |
|---|---|---|
| committer | aichat-agent <agent@aichat.local> | 2026-10-01 15:54:19 +0000 |
| commit | 83a2cd1ac24ca0feda34ae877aaf31f41b58b86c (patch) | |
| tree | cbc83678fa05fe6a82908c448a4e20eae673a9c7 /src/client/common.rs | |
| parent | 82976d349ad97ac9aae0655ad631dace5e2a6385 (diff) | |
| download | aichat-83a2cd1ac24ca0feda34ae877aaf31f41b58b86c.tar.gz | |
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.
Diffstat (limited to 'src/client/common.rs')
| -rw-r--r-- | src/client/common.rs | 30 |
1 files changed, 28 insertions, 2 deletions
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<ToolCall>, +) -> Result<Vec<ToolResult>> { + 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() { |
