]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
server: Add a simple get_datetime server tool (#22649)
authorEvan Huus <redacted>
Mon, 4 May 2026 10:19:41 +0000 (06:19 -0400)
committerGitHub <redacted>
Mon, 4 May 2026 10:19:41 +0000 (12:19 +0200)
common/arg.cpp
tools/server/README.md
tools/server/server-tools.cpp

index dd8ce40a6159ffa86026c9d88f46e8b91b783307..8f54ee38c1b8f3c1966780dde44e1fe1e653a423 100644 (file)
@@ -2864,7 +2864,7 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
         {"--tools"}, "TOOL1,TOOL2,...",
         "experimental: whether to enable built-in tools for AI agents - do not enable in untrusted environments (default: no tools)\n"
         "specify \"all\" to enable all tools\n"
-        "available tools: read_file, file_glob_search, grep_search, exec_shell_command, write_file, edit_file, apply_diff",
+        "available tools: read_file, file_glob_search, grep_search, exec_shell_command, write_file, edit_file, apply_diff, get_datetime",
         [](common_params & params, const std::string & value) {
             params.server_tools = parse_csv_row(value);
         }
index eda87595132285060d4cdb4858447861cffcb3c6..a0cfdbb6feccd0f067740cdf673dc7ba16aad8b4 100644 (file)
@@ -191,7 +191,7 @@ For the full list of features, please refer to [server's changelog](https://gith
 | `--webui-config JSON` | JSON that provides default WebUI settings (overrides WebUI defaults)<br/>(env: LLAMA_ARG_WEBUI_CONFIG) |
 | `--webui-config-file PATH` | JSON file that provides default WebUI settings (overrides WebUI defaults)<br/>(env: LLAMA_ARG_WEBUI_CONFIG_FILE) |
 | `--webui-mcp-proxy, --no-webui-mcp-proxy` | experimental: whether to enable MCP CORS proxy - do not enable in untrusted environments (default: disabled)<br/>(env: LLAMA_ARG_WEBUI_MCP_PROXY) |
-| `--tools TOOL1,TOOL2,...` | experimental: whether to enable built-in tools for AI agents - do not enable in untrusted environments (default: no tools)<br/>specify "all" to enable all tools<br/>available tools: read_file, file_glob_search, grep_search, exec_shell_command, write_file, edit_file, apply_diff<br/>(env: LLAMA_ARG_TOOLS) |
+| `--tools TOOL1,TOOL2,...` | experimental: whether to enable built-in tools for AI agents - do not enable in untrusted environments (default: no tools)<br/>specify "all" to enable all tools<br/>available tools: read_file, file_glob_search, grep_search, exec_shell_command, write_file, edit_file, apply_diff, get_datetime<br/>(env: LLAMA_ARG_TOOLS) |
 | `--webui, --no-webui` | whether to enable the Web UI (default: enabled)<br/>(env: LLAMA_ARG_WEBUI) |
 | `--embedding, --embeddings` | restrict to only support embedding use case; use only with dedicated embedding models (default: disabled)<br/>(env: LLAMA_ARG_EMBEDDINGS) |
 | `--rerank, --reranking` | enable reranking endpoint on server (default: disabled)<br/>(env: LLAMA_ARG_RERANKING) |
index 81e360de4639cc0893219787b5bca5f18c314e9a..49bec4be4f33dd134b98f2255d05b6bdd6acca58 100644 (file)
@@ -693,6 +693,35 @@ struct server_tool_apply_diff : server_tool {
     }
 };
 
+//
+// get_datetime: returns the current date and time
+//
+
+struct server_tool_get_datetime : server_tool {
+    server_tool_get_datetime() {
+        name = "get_datetime";
+        display_name = "Get Date & Time";
+        permission_write = false;
+    }
+
+    json get_definition() override {
+        return {
+            {"type", "function"},
+            {"function", {
+                {"name", name},
+                {"description", "Returns the current date and time"},
+            }},
+        };
+    }
+
+    json invoke(json) override {
+        auto now = std::chrono::system_clock::now();
+        auto time = std::chrono::system_clock::to_time_t(now);
+
+        return {{"result", std::ctime(&time)}};
+    }
+};
+
 //
 // public API
 //
@@ -706,6 +735,7 @@ static std::vector<std::unique_ptr<server_tool>> build_tools() {
     tools.push_back(std::make_unique<server_tool_write_file>());
     tools.push_back(std::make_unique<server_tool_edit_file>());
     tools.push_back(std::make_unique<server_tool_apply_diff>());
+    tools.push_back(std::make_unique<server_tool_get_datetime>());
     return tools;
 }