Avoid repeating earlier Holmes storage checks
This commit is contained in:
parent
11734c10d2
commit
8e2d7c502e
|
|
@ -136,6 +136,14 @@ def last_bash_command(messages):
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
def seen_bash_command(message, history):
|
||||||
|
"""Detect a model retry of an earlier command, not just the last one."""
|
||||||
|
for entry in history:
|
||||||
|
if isinstance(entry, dict) and same_as_last_call(message, [entry]):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def complete(request, bash_mode):
|
def complete(request, bash_mode):
|
||||||
"""Retry an initial prose-only answer once; never fabricate a tool call."""
|
"""Retry an initial prose-only answer once; never fabricate a tool call."""
|
||||||
if bash_mode:
|
if bash_mode:
|
||||||
|
|
@ -192,7 +200,7 @@ def complete(request, bash_mode):
|
||||||
"Do not request the procedure again or repeat the PV lookup."}]
|
"Do not request the procedure again or repeat the PV lookup."}]
|
||||||
retried = translate(query_ollama(retry), request["tools"])
|
retried = translate(query_ollama(retry), request["tools"])
|
||||||
print("resource_decision_retry", "tool_call=" + str(bool(retried["choices"][0]["message"].get("tool_calls"))), flush=True)
|
print("resource_decision_retry", "tool_call=" + str(bool(retried["choices"][0]["message"].get("tool_calls"))), flush=True)
|
||||||
if same_as_last_call(retried["choices"][0]["message"], messages):
|
if seen_bash_command(retried["choices"][0]["message"], messages):
|
||||||
retried["choices"][0]["message"] = {"role": "assistant", "content":
|
retried["choices"][0]["message"] = {"role": "assistant", "content":
|
||||||
"JEANNIE_STOP_REPEATED_TOOL_CALL: Holmes repeated the preceding command; investigation is incomplete."}
|
"JEANNIE_STOP_REPEATED_TOOL_CALL: Holmes repeated the preceding command; investigation is incomplete."}
|
||||||
retried["choices"][0]["finish_reason"] = "stop"
|
retried["choices"][0]["finish_reason"] = "stop"
|
||||||
|
|
@ -209,7 +217,7 @@ def complete(request, bash_mode):
|
||||||
retried = translate(query_ollama(retry), request["tools"])
|
retried = translate(query_ollama(retry), request["tools"])
|
||||||
accepted = safe_initial_call(retried["choices"][0]["message"], request["tools"], users[-1]["content"])
|
accepted = safe_initial_call(retried["choices"][0]["message"], request["tools"], users[-1]["content"])
|
||||||
print("resource_extract_retry", "accepted=" + str(accepted), flush=True)
|
print("resource_extract_retry", "accepted=" + str(accepted), flush=True)
|
||||||
if accepted and not same_as_last_call(retried["choices"][0]["message"], messages):
|
if accepted and not seen_bash_command(retried["choices"][0]["message"], messages):
|
||||||
return retried
|
return retried
|
||||||
if bash_mode and same_as_last_call(message, messages):
|
if bash_mode and same_as_last_call(message, messages):
|
||||||
retry = dict(request)
|
retry = dict(request)
|
||||||
|
|
|
||||||
|
|
@ -117,6 +117,14 @@ class ToolAdapterTests(unittest.TestCase):
|
||||||
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")
|
||||||
|
|
||||||
|
def test_seen_bash_command_checks_earlier_calls(self):
|
||||||
|
def call(command):
|
||||||
|
return {"function": {"name": "bash", "arguments": json.dumps({"command": command})}}
|
||||||
|
history = [{"role": "assistant", "tool_calls": [call("kubectl get pvc")]},
|
||||||
|
{"role": "assistant", "tool_calls": [call("kubectl get pv")]}]
|
||||||
|
self.assertTrue(PROXY.seen_bash_command({"tool_calls": [call("kubectl get pvc")]}, history))
|
||||||
|
self.assertFalse(PROXY.seen_bash_command({"tool_calls": [call("kubectl get pod")]}, history))
|
||||||
|
|
||||||
def test_retry_cannot_turn_a_plan_into_a_mutating_command(self):
|
def test_retry_cannot_turn_a_plan_into_a_mutating_command(self):
|
||||||
tools = [{"type": "function", "function": {"name": "bash", "parameters": {
|
tools = [{"type": "function", "function": {"name": "bash", "parameters": {
|
||||||
"type": "object", "properties": {"command": {"type": "string"},
|
"type": "object", "properties": {"command": {"type": "string"},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue