From 1517e8675d5c876eb92b13bafaae3e4c71f55d08 Mon Sep 17 00:00:00 2001 From: Henry Li Date: Fri, 16 Jan 2026 21:48:00 +0800 Subject: [PATCH] feat: add present_file tool --- backend/src/tools/builtins/__init__.py | 3 +++ .../src/tools/builtins/present_file_tool.py | 24 +++++++++++++++++++ backend/src/tools/tools.py | 8 ++++++- 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 backend/src/tools/builtins/__init__.py create mode 100644 backend/src/tools/builtins/present_file_tool.py diff --git a/backend/src/tools/builtins/__init__.py b/backend/src/tools/builtins/__init__.py new file mode 100644 index 0000000..5c87b04 --- /dev/null +++ b/backend/src/tools/builtins/__init__.py @@ -0,0 +1,3 @@ +from .present_file_tool import present_file_tool + +__all__ = ["present_file_tool"] diff --git a/backend/src/tools/builtins/present_file_tool.py b/backend/src/tools/builtins/present_file_tool.py new file mode 100644 index 0000000..bc1fef2 --- /dev/null +++ b/backend/src/tools/builtins/present_file_tool.py @@ -0,0 +1,24 @@ +from langchain.tools import tool + + +@tool("present_files", parse_docstring=True) +def present_file_tool(filepaths: list[str]) -> str: + """Make files visible to the user for viewing and rendering in the client interface. + + When to use the present_files tool: + + - Making any file available for the user to view, download, or interact with + - Presenting multiple related files at once + - After creating a file that should be presented to the user + + When NOT to use the present_files tool: + - When you only need to read file contents for your own processing + - For temporary or intermediate files not meant for user viewing + + Args: + filepaths: List of absolute file paths to present to the user. **Only** files in `/mnt/user-data/outputs` can be presented. + + Returns: + "OK" if the files were presented successfully. + """ + return "OK" diff --git a/backend/src/tools/tools.py b/backend/src/tools/tools.py index 870df6b..a89a4b1 100644 --- a/backend/src/tools/tools.py +++ b/backend/src/tools/tools.py @@ -2,9 +2,15 @@ from langchain.tools import BaseTool from src.config import get_app_config from src.reflection import resolve_variable +from src.tools.builtins import present_file_tool + +BUILTIN_TOOLS = [ + present_file_tool, +] def get_available_tools(groups: list[str] | None = None) -> list[BaseTool]: """Get all available tools from config""" config = get_app_config() - return [resolve_variable(tool.use, BaseTool) for tool in config.tools if groups is None or tool.group in groups] + loaded_tools = [resolve_variable(tool.use, BaseTool) for tool in config.tools if groups is None or tool.group in groups] + return loaded_tools + BUILTIN_TOOLS