From f678a6f20da1b5bcd6c22d204898d92af28106dc Mon Sep 17 00:00:00 2001 From: opencode Date: Mon, 23 Mar 2026 19:06:58 +0100 Subject: [PATCH] Rimuovi debug print e aggiungi pattern write_file - Rimuovi print di debug da _execute_tool e invoke - Aggiungi pattern intent per write_file (scrivi, crea, salva) --- ollama_agent.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/ollama_agent.py b/ollama_agent.py index cf966b0..251c554 100644 --- a/ollama_agent.py +++ b/ollama_agent.py @@ -300,7 +300,6 @@ For other questions, just answer normally without tools.""" def _execute_tool(self, tool_call: ToolCall) -> Any: """Esegui un singolo tool""" - print(f"_execute_tool: name={tool_call.name}, args={tool_call.arguments}") if tool_call.name not in self.tools: available = ", ".join(self.tools.keys()) return { @@ -317,8 +316,6 @@ For other questions, just answer normally without tools.""" else: result = tool.invoke({}) - print(f"_execute_tool: got result type={type(result)}, value={result}") - # Converti result in stringa per il modello if result is None: return {"result": "Tool executed successfully"} @@ -328,7 +325,6 @@ For other questions, just answer normally without tools.""" return {"result": str(result)} except Exception as e: - print(f"_execute_tool: exception={e}") return {"error": str(e)} def _format_tool_result(self, tool_call: ToolCall, result: Any) -> str: @@ -390,6 +386,27 @@ For other questions, just answer normally without tools.""" if has_read_keyword and file_path: return ToolCall(id='intent', name='read_file', arguments={'path': file_path}) + # Write file patterns + write_keywords = ['scrivi', 'scrivere', 'crea', 'creare', 'salva', 'salvare', + 'write', 'create', 'save', 'make file'] + has_write_keyword = any(k in text_lower for k in write_keywords) + + if has_write_keyword: + # Try to extract path and content + path_match = re.search(r'(?:file|file\s+)(\S+\.\w+)', text_lower) + content_match = re.search(r'["\']([^"\']+)["\']', text) + + if path_match: + file_path = path_match.group(1) + # Try to get content from quoted text or description + if content_match: + content = content_match.group(1) + else: + # Try to extract content from the text + content = text.replace('"', "'").split("'")[1] if "'" in text else "Content not specified" + + return ToolCall(id='intent', name='write_file', arguments={'path': file_path, 'content': content}) + # Execute command patterns exec_patterns = [ 'esegui', 'eseguire', 'run', 'run command', 'lanciare', @@ -408,8 +425,6 @@ For other questions, just answer normally without tools.""" L'agente può fare multiple iterazioni tool-call prima di rispondere. """ - print("OLLAMA_AGENT: invoke() CALLED") - # Estrai il messaggio utente user_message = input_dict.get("messages", [])[-1] if hasattr(user_message, 'content'): @@ -417,8 +432,6 @@ For other questions, just answer normally without tools.""" else: user_content = str(user_message) - print(f"OLLAMA_AGENT: user_content='{user_content}'") - # Aggiungi il messaggio utente alla cronologia self.messages.append(HumanMessage(content=user_content))