From 9868f80e9c275b1d6440b45fe8589736f6470227 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Tue, 16 Jun 2026 10:19:44 +0200 Subject: [PATCH] feat(tools): Extend context chat tool with scope_type and scope_list params Assisted-by: ClaudeCode:claude-opus-4-8 Signed-off-by: Marcel Klehr --- ex_app/lib/all_tools/context_chat.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/ex_app/lib/all_tools/context_chat.py b/ex_app/lib/all_tools/context_chat.py index a8e5105..990d488 100644 --- a/ex_app/lib/all_tools/context_chat.py +++ b/ex_app/lib/all_tools/context_chat.py @@ -1,5 +1,6 @@ # SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors # SPDX-License-Identifier: AGPL-3.0-or-later +from typing import Literal from langchain_core.tools import tool from nc_py_api import AsyncNextcloudApp @@ -11,17 +12,32 @@ async def get_tools(nc: AsyncNextcloudApp): @tool @safe_tool - async def ask_context_chat(question: str) -> str: + async def ask_context_chat( + question: str, + scope_type: Literal['none', 'source', 'provider'] = 'none', + scope_list: list[str] | None = None, + ) -> str: """ Ask the context chat oracle a question about the user's documents. It knows the contents of all of the users documents. + This is often easier than searching for documents and then fetching their contents when trying to answer questions. :param question: The question to ask + :param scope_type: Optional. Restricts which documents the oracle searches. + - "none" (default): search across all of the user's documents. + - "source": restrict the search to specific items listed in scope_list. + - "provider": restrict the search to specific content providers listed in scope_list. + :param scope_list: Required when scope_type is "source" or "provider"; ignored otherwise. + - For scope_type "source": a list of source IDs in the format "__: " + (e.g., "files__default: 12345" for the file with Nextcloud file id 12345). File ids can be + obtained from the file-related tools or unified search. + - For scope_type "provider": a list of provider keys in the format "__" + (e.g., "files__default" for files, "mail__messages" for mail). :return: the answer from context chat """ task_input = { 'prompt': question, - 'scopeType': 'none', - 'scopeList': [], + 'scopeType': scope_type, + 'scopeList': scope_list or [], 'scopeListMeta': '', } task_output = (await run_task(nc, "context_chat:context_chat", task_input)).output