Advance Holmes past repeated storage checks
This commit is contained in:
parent
82ae3cf18a
commit
7c88b42c61
|
|
@ -169,6 +169,16 @@ def complete(request, bash_mode):
|
||||||
if users:
|
if users:
|
||||||
retry = dict(request)
|
retry = dict(request)
|
||||||
previous = last_bash_command(messages)
|
previous = last_bash_command(messages)
|
||||||
|
if re.search(r"\bget\s+(?:pv|persistentvolume)\b", previous):
|
||||||
|
# Preserve the tool results: after the volume check Holmes must
|
||||||
|
# evaluate them, not be sent back to the PVC indefinitely.
|
||||||
|
retry["messages"] = messages + [{"role": "user", "content":
|
||||||
|
"Use the collected results and the supplied recovery procedure to decide the next action. "
|
||||||
|
"If its prerequisites are met, call bash for the targeted repair and then validate it. "
|
||||||
|
"Otherwise state what evidence is missing. Do not repeat the PVC or PV lookup."}]
|
||||||
|
retried = translate(query_ollama(retry), request["tools"])
|
||||||
|
print("resource_decision_retry", "tool_call=" + str(bool(retried["choices"][0]["message"].get("tool_calls"))), flush=True)
|
||||||
|
return retried
|
||||||
next_check = ("The PVC was already inspected. Check the bound PV by its actual PV name; use kubectl get pv, not get pvc. "
|
next_check = ("The PVC was already inspected. Check the bound PV by its actual PV name; use kubectl get pv, not get pvc. "
|
||||||
if re.search(r"\bget\s+(?:pvc|persistentvolumeclaim)\b", previous) else
|
if re.search(r"\bget\s+(?:pvc|persistentvolumeclaim)\b", previous) else
|
||||||
"Check the named PVC or PV using kubectl get. ")
|
"Check the named PVC or PV using kubectl get. ")
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,20 @@ class ToolAdapterTests(unittest.TestCase):
|
||||||
self.assertFalse(PROXY.is_resource_extract({"content": "Diagnosis: bad pod. Mitigation: none. Validation: unavailable."}))
|
self.assertFalse(PROXY.is_resource_extract({"content": "Diagnosis: bad pod. Mitigation: none. Validation: unavailable."}))
|
||||||
self.assertTrue(PROXY.is_resource_extract({"content": '```json\n{"name":"fetch_pvc_details","arguments":{"pvc_name":"n8n-data"}}\n```'}))
|
self.assertTrue(PROXY.is_resource_extract({"content": '```json\n{"name":"fetch_pvc_details","arguments":{"pvc_name":"n8n-data"}}\n```'}))
|
||||||
|
|
||||||
|
def test_pv_result_leads_to_decision_with_tool_history(self):
|
||||||
|
tools = [{"type": "function", "function": {"name": "bash", "parameters": {
|
||||||
|
"type": "object", "properties": {"command": {"type": "string"},
|
||||||
|
"suggested_prefixes": {"type": "array", "items": {"type": "string"}}},
|
||||||
|
"required": ["command", "suggested_prefixes"]}}}]
|
||||||
|
previous = {"role": "assistant", "tool_calls": [{"function": {"name": "bash", "arguments": json.dumps({"command": "kubectl get pv pvc-123"})}}]}
|
||||||
|
history = [{"role": "user", "content": "investigate"}, previous, {"role": "tool", "content": "volume output"}]
|
||||||
|
echo = {"choices": [{"message": {"content": '{"kind":"PersistentVolume"}'}}]}
|
||||||
|
decision = {"choices": [{"message": {"content": "Diagnosis: missing evidence. Mitigation: none. Validation: unavailable."}}]}
|
||||||
|
with patch.object(PROXY, "query_ollama", side_effect=[echo, decision]) as query:
|
||||||
|
result = PROXY.complete({"tools": tools, "messages": history}, True)
|
||||||
|
self.assertEqual(query.call_args_list[1].args[0]["messages"][:-1], history)
|
||||||
|
self.assertIn("missing evidence", result["choices"][0]["message"]["content"])
|
||||||
|
|
||||||
def test_last_bash_command_reads_recorded_tool_arguments(self):
|
def test_last_bash_command_reads_recorded_tool_arguments(self):
|
||||||
messages = [{"role": "assistant", "tool_calls": [{"function": {"name": "bash", "arguments": json.dumps({"command": "kubectl -n n8n get pvc n8n-data"})}}]}, {"role": "tool", "content": "ok"}]
|
messages = [{"role": "assistant", "tool_calls": [{"function": {"name": "bash", "arguments": json.dumps({"command": "kubectl -n n8n get pvc n8n-data"})}}]}, {"role": "tool", "content": "ok"}]
|
||||||
self.assertEqual(PROXY.last_bash_command(messages), "kubectl -n n8n get pvc n8n-data")
|
self.assertEqual(PROXY.last_bash_command(messages), "kubectl -n n8n get pvc n8n-data")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue