From 52f7c511119f761f2c5698a1a2322632eecb36cb Mon Sep 17 00:00:00 2001 From: "juvenal.diaz" Date: Sat, 14 Nov 2026 13:06:14 -0600 Subject: [PATCH] Support fenced local model tool requests --- docs/doctor-overview.md | 3 ++- infra/ai-stack/holmes-skills/k3s-stale-volume/SKILL.md | 5 +++++ scripts/ollama-tool-call-adapter.py | 7 ++++++- tests/jeannie/test_ollama_tool_call_adapter.py | 2 ++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/docs/doctor-overview.md b/docs/doctor-overview.md index 5f3b0a9..cc728b1 100644 --- a/docs/doctor-overview.md +++ b/docs/doctor-overview.md @@ -99,7 +99,8 @@ per-tool memory limit; `LAB_HOLMES_REPAIR_MAX_STEPS`, override these limits. These are limits, not a guarantee that Holmes will complete or that every tool can run within them. When `LAB_HOLMES_MODEL` selects `ollama_chat/...`, repair mode starts a -temporary loopback proxy that translates a single bare JSON tool request into +temporary loopback proxy that translates a single JSON tool request, optionally +in one Markdown JSON fence, into an OpenAI-style tool call only if the requested name and arguments pass the tool's supplied JSON Schema. Other responses are passed through. It uses the Holmes pipx Python environment for `jsonschema`; override that interpreter with diff --git a/infra/ai-stack/holmes-skills/k3s-stale-volume/SKILL.md b/infra/ai-stack/holmes-skills/k3s-stale-volume/SKILL.md index 4115450..067166a 100644 --- a/infra/ai-stack/holmes-skills/k3s-stale-volume/SKILL.md +++ b/infra/ai-stack/holmes-skills/k3s-stale-volume/SKILL.md @@ -35,6 +35,11 @@ fresh mounts. Immediately re-check the pod UID and owner before deleting it. Use `kubectl -n delete pod `; never use force or zero grace period. Do not delete, recreate, reformat or modify the PVC, PV, data, configuration or encryption keys. Do not regenerate an application key. +When calling the Bash tool, include both required fields: `command` is the exact +command and `suggested_prefixes` is an array containing `kubectl`. For example, +the arguments are `{"command":"kubectl -n demo delete pod example-123", +"suggested_prefixes":["kubectl"]}`. Substitute only the verified namespace +and current pod name; this example is not an instruction to act on demo. If the pod is not controller-managed, mounts remain busy, the volume is not confirmed, or the delete fails, stop and report what remains unknown. diff --git a/scripts/ollama-tool-call-adapter.py b/scripts/ollama-tool-call-adapter.py index 1e1e167..7efddd4 100644 --- a/scripts/ollama-tool-call-adapter.py +++ b/scripts/ollama-tool-call-adapter.py @@ -4,6 +4,7 @@ This is a testing utility: it never executes a tool or starts a network service. """ import json +import re import sys import jsonschema @@ -29,8 +30,12 @@ def has_external_reference(value): def convert(content, tools): """Return a structured call only for a single exact, schema-valid request.""" + if not isinstance(content, str): + return None try: - request = json.loads(content, object_pairs_hook=unique_object) + text = content.strip() + fenced = re.fullmatch(r"```(?:json)?[ \t]*\r?\n(.*?)\r?\n```", text, re.IGNORECASE | re.DOTALL) + request = json.loads(fenced.group(1) if fenced else text, object_pairs_hook=unique_object) except (TypeError, ValueError): return None if not isinstance(request, dict) or set(request) != {"name", "arguments"}: diff --git a/tests/jeannie/test_ollama_tool_call_adapter.py b/tests/jeannie/test_ollama_tool_call_adapter.py index b27d0f1..7fd1b41 100644 --- a/tests/jeannie/test_ollama_tool_call_adapter.py +++ b/tests/jeannie/test_ollama_tool_call_adapter.py @@ -20,9 +20,11 @@ class ToolAdapterTests(unittest.TestCase): def test_valid_call(self): result = ADAPTER.convert(json.dumps({"name": "get_status", "arguments": {"service": "demo"}}), self.tools) self.assertEqual(result["function"]["arguments"], {"service": "demo"}) + self.assertIsNotNone(ADAPTER.convert('```json\n{"name":"get_status","arguments":{"service":"demo"}}\n```', self.tools)) def test_invalid_or_ambiguous_calls_are_not_translated(self): for value in ('prefix {"name":"get_status","arguments":{}}', + 'prose\n```json\n{"name":"get_status","arguments":{"service":"demo"}}\n```', '{"name":"unknown","arguments":{}}', '{"name":"get_status","arguments":{"service":42}}', '{"name":"get_status","arguments":{"service":"demo","extra":1}}',