fix: rimuove model-based tool calling, usa solo intent detection

Il model-based tool calling causava comportamenti imprevedibili con modelli locali. Ora usa solo intent detection.
This commit is contained in:
opencode committed 2026-03-23 19:00:46 +01:00
1 parent f8ebfb65ab
commit 34d6623cb2
1 file changed
+6 -34
+6 -34
View File
@@ -424,10 +424,8 @@ For other questions, just answer normally without tools."""
# Try to detect intent directly first
detected_tool = self._detect_intent(user_content)
print(f"OLLAMA_AGENT: detected_tool={detected_tool}")
if detected_tool:
result = self._execute_tool(detected_tool)
print(f"OLLAMA_AGENT: result type={type(result)}, value={result}")
# Format result as a clean response
response_text = ""
@@ -448,41 +446,15 @@ For other questions, just answer normally without tools."""
except Exception as e:
response_text = str(result) if not response_text else response_text
print(f"OLLAMA_AGENT: response_text={response_text}")
return {"messages": self.messages, "response": response_text}
# Loop principale: risposta -> parse tools -> esegui -> ripeti
iteration = 0
final_response = None
# Se nessun intent detectato, usa il modello per rispondere normalmente
# (senza tool calling per ora - i modelli locali non lo supportano bene)
response = self.llm.invoke(self.messages)
self.messages.append(response)
while iteration < self.max_iterations:
iteration += 1
# Genera risposta dal modello
response = self.llm.invoke(self.messages)
self.messages.append(response)
response_text = response.content if hasattr(response, 'content') else str(response)
# Parse le chiamate tool
tool_calls = self._parse_tool_calls(response_text)
if not tool_calls:
# Nessuna chiamata tool, questa è la risposta finale
final_response = response_text
break
# Esegui i tool e aggiungi i risultati
for tool_call in tool_calls:
result = self._execute_tool(tool_call)
tool_result_text = self._format_tool_result(tool_call, result)
self.messages.append(HumanMessage(content=tool_result_text))
# Se non abbiamo una risposta (troppe iterazioni)
if final_response is None:
final_response = "Ho raggiunto il numero massimo di iterazioni. Qualcosa potrebbe essere andato storto."
return {"messages": self.messages, "response": final_response}
response_text = response.content if hasattr(response, 'content') else str(response)
return {"messages": self.messages, "response": response_text}
def clear_history(self):
"""Pulisci la cronologia ma mantieni il system prompt"""