summaryrefslogtreecommitdiff
path: root/source/net
diff options
context:
space:
mode:
authorMichael Peter Christen <mc@yacy.net>2026-02-08 21:44:04 +0100
committerMichael Peter Christen <mc@yacy.net>2026-02-08 21:44:04 +0100
commit2141aef2c882ee9d53a785c9570ac593018bd810 (patch)
treeacbdd1619862bbd0a1e0436269a3057ff91369d2 /source/net
parent9cd693a464b19f8788ba4438d68367b1aed4014b (diff)
added skill configuration: we present llm tools as "Skills" and make
them configurable in the YaCy GUI.
Diffstat (limited to 'source/net')
-rw-r--r--source/net/yacy/ai/ToolProvider.java130
-rw-r--r--source/net/yacy/ai/tools/CalculatorTool.java2
-rw-r--r--source/net/yacy/htroot/AILab.java7
-rw-r--r--source/net/yacy/htroot/SkillsConfig_p.java89
-rw-r--r--source/net/yacy/server/serverSwitch.java18
5 files changed, 222 insertions, 24 deletions
diff --git a/source/net/yacy/ai/ToolProvider.java b/source/net/yacy/ai/ToolProvider.java
index 9bef4b223..997b01602 100644
--- a/source/net/yacy/ai/ToolProvider.java
+++ b/source/net/yacy/ai/ToolProvider.java
@@ -20,6 +20,7 @@
package net.yacy.ai;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
@@ -43,6 +44,7 @@ import net.yacy.ai.tools.TableOpsTool;
import net.yacy.ai.tools.UnitConverterTool;
import net.yacy.ai.tools.WebFetchTool;
import net.yacy.ai.tools.WikipediaLinkCreatorTool;
+import net.yacy.search.Switchboard;
/**
* Central registry and dispatch utility for all built-in YaCy LLM tools.
@@ -55,32 +57,66 @@ import net.yacy.ai.tools.WikipediaLinkCreatorTool;
* </ul>
*/
public final class ToolProvider {
+ private static final String CONFIG_PREFIX = "ai.tools.";
+ private static final String DESCRIPTION_SUFFIX = ".description";
+ private static final String MAX_CALLS_SUFFIX = ".maxCallsPerTurn";
+
/**
- * Ordered list of built-in tool handlers. Order is preserved when exposing
- * definitions to providers.
+ * Tool handlers for different skill groups
*/
- private static final List<ToolHandler> TOOLS = Arrays.asList(
+ private static final List<ToolHandler> TOOLS_BASIC = Arrays.asList(
new DateTimeTool(),
new DateMathTool(),
new CalculatorTool(),
new NumberParserTool(),
new UnitConverterTool(),
- new WebFetchTool(),
new HttpJsonTool(),
new TableOpsTool(),
new SelfReflectTool(),
- new ChitChatTool(),
+ new ChitChatTool()
+ );
+ private static final List<ToolHandler> TOOLS_VISUALIZATION = Arrays.asList(
new PromptToMermaidTool(),
- new Mermaid2ASCIITool(),
- new WikipediaLinkCreatorTool()
+ new Mermaid2ASCIITool()
+ );
+ private static final List<ToolHandler> TOOLS_RETRIEVAL = Arrays.asList(
+ new WikipediaLinkCreatorTool(),
+ new WebFetchTool()
);
+
+ /**
+ * Ordered list of built-in tool handlers. Order is preserved when exposing
+ * definitions to providers.
+ */
+ private static final List<ToolHandler> TOOLS = new ArrayList<>();
+ static {
+ TOOLS.addAll(TOOLS_BASIC);
+ TOOLS.addAll(TOOLS_VISUALIZATION);
+ TOOLS.addAll(TOOLS_RETRIEVAL);
+ }
/**
* Lookup table for fast runtime dispatch by function/tool name.
*/
private static final Map<String, ToolHandler> TOOL_BY_NAME = buildToolIndex(TOOLS);
+ public static final class ToolConfig {
+ public final String name;
+ public final String description;
+ public final int maxCallsPerTurn;
+ public final int defaultMaxCallsPerTurn;
+ public final boolean enabled;
+
+ private ToolConfig(final String name, final String description, final int maxCallsPerTurn, final int defaultMaxCallsPerTurn) {
+ this.name = name;
+ this.description = description;
+ this.maxCallsPerTurn = Math.max(0, maxCallsPerTurn);
+ this.defaultMaxCallsPerTurn = Math.max(0, defaultMaxCallsPerTurn);
+ this.enabled = this.maxCallsPerTurn > 0;
+ }
+ }
+
/**
* Utility class; not instantiable.
*/
@@ -105,7 +141,8 @@ public final class ToolProvider {
}
// Merge registry definitions without duplicating by tool name.
for (ToolHandler tool : TOOLS) {
- JSONObject definition = tool.definition();
+ JSONObject definition = configuredDefinition(tool);
+ if (definition == null) continue;
addToolDefinitionIfMissing(tools, definition);
}
// Providers usually expect explicit tool-choice mode.
@@ -128,6 +165,7 @@ public final class ToolProvider {
if (name == null) return errorJson("Invalid tool call");
ToolHandler tool = TOOL_BY_NAME.get(name);
if (tool == null) return errorJson("Unknown tool: " + name);
+ if (maxCallsPerTurn(name) <= 0) return errorJson("Tool disabled: " + name);
// Tool implementations are responsible for argument parsing/validation.
return tool.execute(arguments);
}
@@ -143,8 +181,47 @@ public final class ToolProvider {
if (name == null) return 1;
ToolHandler tool = TOOL_BY_NAME.get(name);
if (tool == null) return 1;
- int max = tool.maxCallsPerTurn();
- return max <= 0 ? 1 : max;
+ int max = configuredMaxCalls(name, tool.maxCallsPerTurn());
+ return Math.max(0, max);
+ }
+
+ public static List<ToolConfig> listTools() {
+ return listToolConfigs(TOOLS);
+ }
+
+ public static List<ToolConfig> listBasicTools() {
+ return listToolConfigs(TOOLS_BASIC);
+ }
+
+ public static List<ToolConfig> listVisualizationTools() {
+ return listToolConfigs(TOOLS_VISUALIZATION);
+ }
+
+ public static List<ToolConfig> listRetrievalTools() {
+ return listToolConfigs(TOOLS_RETRIEVAL);
+ }
+
+ private static List<ToolConfig> listToolConfigs(final List<ToolHandler> source) {
+ final List<ToolConfig> configuredTools = new ArrayList<>();
+ for (ToolHandler tool : source) {
+ if (tool == null) continue;
+ try {
+ final JSONObject definition = tool.definition();
+ final String name = extractToolName(definition);
+ if (name == null || name.isEmpty()) continue;
+ final JSONObject fn = definition.optJSONObject("function");
+ final String defaultDescription = fn == null ? "" : fn.optString("description", "");
+ final int defaultMaxCalls = Math.max(0, tool.maxCallsPerTurn());
+ configuredTools.add(new ToolConfig(
+ name,
+ configuredDescription(name, defaultDescription),
+ configuredMaxCalls(name, defaultMaxCalls),
+ defaultMaxCalls));
+ } catch (JSONException e) {
+ // skip invalid definitions
+ }
+ }
+ return Collections.unmodifiableList(configuredTools);
}
/**
@@ -209,6 +286,39 @@ public final class ToolProvider {
return name == null ? null : name.trim();
}
+ private static JSONObject configuredDefinition(final ToolHandler tool) {
+ if (tool == null) return null;
+ try {
+ final JSONObject definition = tool.definition();
+ final String name = extractToolName(definition);
+ if (name == null || name.isEmpty()) return definition;
+ if (configuredMaxCalls(name, tool.maxCallsPerTurn()) <= 0) return null;
+ final JSONObject fn = definition.optJSONObject("function");
+ if (fn != null) {
+ final String defaultDescription = fn.optString("description", "");
+ fn.put("description", configuredDescription(name, defaultDescription));
+ }
+ return definition;
+ } catch (JSONException e) {
+ return null;
+ }
+ }
+
+ private static String configuredDescription(final String toolName, final String defaultDescription) {
+ if (toolName == null || toolName.isEmpty()) return defaultDescription == null ? "" : defaultDescription;
+ final Switchboard sb = Switchboard.getSwitchboard();
+ if (sb == null) return defaultDescription == null ? "" : defaultDescription;
+ return sb.getConfig(CONFIG_PREFIX + toolName + DESCRIPTION_SUFFIX, defaultDescription == null ? "" : defaultDescription);
+ }
+
+ private static int configuredMaxCalls(final String toolName, final int defaultMaxCalls) {
+ if (toolName == null || toolName.isEmpty()) return Math.max(0, defaultMaxCalls);
+ final Switchboard sb = Switchboard.getSwitchboard();
+ if (sb == null) return Math.max(0, defaultMaxCalls);
+ final int configured = sb.getConfigInt(CONFIG_PREFIX + toolName + MAX_CALLS_SUFFIX, defaultMaxCalls);
+ return Math.max(0, configured);
+ }
+
/**
* Builds a minimal error JSON string while avoiding propagation of secondary
* JSON construction failures.
diff --git a/source/net/yacy/ai/tools/CalculatorTool.java b/source/net/yacy/ai/tools/CalculatorTool.java
index 4c33d7194..334a08305 100644
--- a/source/net/yacy/ai/tools/CalculatorTool.java
+++ b/source/net/yacy/ai/tools/CalculatorTool.java
@@ -41,7 +41,7 @@ public class CalculatorTool implements ToolHandler {
tool.put("type", "function");
JSONObject fn = new JSONObject(true);
fn.put("name", NAME);
- fn.put("description", "Evaluate a mathematical formula. Supports operators (+,-,*,/,%,^), constants (pi,e,tau,phi), functions (sqrt,abs,ln,log,sin,cos,tan,asin,acos,atan,min,max,pow,root,...) and scientific notation. Use this as your calculator.");
+ fn.put("description", "Evaluate a mathematical formula. Supports operators (+, -, *, /, %, ^), constants (pi, e, tau, phi), functions (sqrt, abs, ln, log, sin, cos, tan, asin, acos, atan, min, max, pow, root, ...) and scientific notation. Use this as your calculator.");
JSONObject params = new JSONObject(true);
params.put("type", "object");
JSONObject props = new JSONObject(true);
diff --git a/source/net/yacy/htroot/AILab.java b/source/net/yacy/htroot/AILab.java
index 025bd6541..3ba072dad 100644
--- a/source/net/yacy/htroot/AILab.java
+++ b/source/net/yacy/htroot/AILab.java
@@ -74,7 +74,9 @@ public class AILab {
// Shield configuration: consider the shield page visit as completion
final boolean hasShield = "true".equalsIgnoreCase(sb.getConfig("ui.AIShield_p.visited", "false"));
- final boolean frontPageLinkActivated = sb.getConfigBool("ai.shield.show-chat-link", false);
+ final boolean hasToolsConfig = "true".equalsIgnoreCase(sb.getConfig("ui.SkillsConfig_p.visited", "false"))
+ || "true".equalsIgnoreCase(sb.getConfig("ui.SkilsConfig_p.visited", "false"))
+ || "true".equalsIgnoreCase(sb.getConfig("ui.ToolsConfig_p.visited", "false"));
prop.put("ailab_inference_status", hasEngine ? "ready" : "pending");
prop.put("ailab_model_status", hasEngine && hasModel ? "ready" : "pending");
@@ -83,7 +85,8 @@ public class AILab {
prop.putNum("ailab_index_count", indexDocs);
prop.putNum("ailab_index_needed", indexNeeded);
prop.put("ailab_rag_status", hasEngine && hasModel && (hasRagRole || ragVisited) ? "ready" : "pending");
- prop.put("ailab_shield_status", hasEngine && hasModel && hasShield && frontPageLinkActivated ? "ready" : "pending");
+ prop.put("ailab_tools_status", hasToolsConfig ? "ready" : "pending");
+ prop.put("ailab_shield_status", hasShield ? "ready" : "pending");
return prop;
}
diff --git a/source/net/yacy/htroot/SkillsConfig_p.java b/source/net/yacy/htroot/SkillsConfig_p.java
new file mode 100644
index 000000000..11e1adea9
--- /dev/null
+++ b/source/net/yacy/htroot/SkillsConfig_p.java
@@ -0,0 +1,89 @@
+/**
+ * SkillsConfig_p
+ * Copyright 2026 by Michael Peter Christen
+ * First released 08.02.2026 at https://yacy.net
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program in the file lgpl21.txt
+ * If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.yacy.htroot;
+
+import java.util.List;
+
+import net.yacy.ai.ToolProvider;
+import net.yacy.ai.ToolProvider.ToolConfig;
+import net.yacy.cora.protocol.RequestHeader;
+import net.yacy.search.Switchboard;
+import net.yacy.server.serverObjects;
+import net.yacy.server.serverSwitch;
+
+public class SkillsConfig_p {
+
+ private static final String CONFIG_PREFIX = "ai.tools.";
+ private static final String DESCRIPTION_SUFFIX = ".description";
+ private static final String MAX_CALLS_SUFFIX = ".maxCallsPerTurn";
+
+ public static serverObjects respond(@SuppressWarnings("unused") final RequestHeader header, final serverObjects post, final serverSwitch env) {
+ final Switchboard sb = (Switchboard) env;
+ final serverObjects prop = new serverObjects();
+ sb.setConfig("ui.SkillsConfig_p.visited", "true");
+
+ int invalidMaxCalls = 0;
+ if (post != null && post.containsKey("save")) {
+ for (final ToolConfig tool : ToolProvider.listTools()) {
+ final String descKey = CONFIG_PREFIX + tool.name + DESCRIPTION_SUFFIX;
+ final String maxKey = CONFIG_PREFIX + tool.name + MAX_CALLS_SUFFIX;
+ final String configuredDescription = post.get(descKey, tool.description);
+ int configuredMaxCalls = tool.maxCallsPerTurn;
+ final String maxCallsString = post.get(maxKey, Integer.toString(tool.maxCallsPerTurn)).trim();
+ try {
+ configuredMaxCalls = Integer.parseInt(maxCallsString);
+ } catch (final NumberFormatException e) {
+ invalidMaxCalls++;
+ }
+ if (configuredMaxCalls < 0) configuredMaxCalls = 0;
+ sb.setConfig(descKey, configuredDescription);
+ sb.setConfig(maxKey, Integer.toString(configuredMaxCalls));
+ }
+ prop.put("status", "1");
+ } else {
+ prop.put("status", "0");
+ }
+
+ prop.putNum("status_invalidMaxCalls", invalidMaxCalls);
+ prop.put("status_hasInvalidMaxCalls", invalidMaxCalls > 0 ? "1" : "0");
+
+ putToolGroup(prop, "basic_tools", ToolProvider.listBasicTools());
+ putToolGroup(prop, "visualization_tools", ToolProvider.listVisualizationTools());
+ putToolGroup(prop, "retrieval_tools", ToolProvider.listRetrievalTools());
+
+ return prop;
+ }
+
+ /*
+ * Naming note: internally these are called "tools", but in the UI we call
+ * them "skills". Both terms refer to the same feature set.
+ */
+ private static void putToolGroup(final serverObjects prop, final String keyPrefix, final List<ToolConfig> tools) {
+ int row = 0;
+ for (final ToolConfig tool : tools) {
+ prop.putHTML(keyPrefix + "_" + row + "_name", tool.name);
+ prop.putHTML(keyPrefix + "_" + row + "_description", tool.description);
+ prop.putNum(keyPrefix + "_" + row + "_maxCallsPerTurn", tool.maxCallsPerTurn);
+ row++;
+ }
+ prop.put(keyPrefix, row);
+ }
+}
diff --git a/source/net/yacy/server/serverSwitch.java b/source/net/yacy/server/serverSwitch.java
index f2eea88b0..17c0c8904 100644
--- a/source/net/yacy/server/serverSwitch.java
+++ b/source/net/yacy/server/serverSwitch.java
@@ -117,17 +117,13 @@ public class serverSwitch {
}
});
- // remove all values from config that do not appear in init
- this.configRemoved = new ConcurrentHashMap<>();
- final Iterator<String> i = this.configProps.keySet().iterator();
- String key;
- while (i.hasNext()) {
- key = i.next();
- if (!(initProps.containsKey(key))) {
- this.configRemoved.put(key, this.configProps.get(key));
- i.remove();
- }
- }
+ /*
+ * Keep unknown keys from yacy.conf.
+ * Some dynamic features (for example ai.tools.* settings) intentionally
+ * store keys that are not present in defaults/yacy.init.
+ */
+ this.configRemoved = new ConcurrentHashMap<>();
+ String key;
// merge new props from init to config
// this is necessary for migration, when new properties are attached