Il bug era che langcode.py prendeva l'ultimo messaggio dalla cronologia invece del campo 'response' che OllamaToolAgent restituisce.
3.5 KiB
3.5 KiB
Stato Debug LangCode Agent - 23 Marzo 2026
Situazione Attuale
L'agente funziona a livello di esecuzione tool, ma non mostra il risultato all'utente.
Cosa Funziona
- Intent Detection: Rileva correttamente "che SO sto usando" come richiesta di system_info
- Tool Execution: Il tool
system_infoviene eseguito e restituisce il risultato corretto - Response Generation:
response_textcontiene i dati corretti
Debug Output Osservato (CORRETTO):
OLLAMA_AGENT: user_content='che so sto usando'
OLLAMA_AGENT: detected_tool=ToolCall(id='intent', name='system_info', arguments={})
_execute_tool: name=system_info, args={}
_execute_tool: got result type=<class 'str'>, value=OS: Linux 6.17.4-2-pve...
OLLAMA_AGENT: result type=<class 'dict'>, value={'result': 'OS: Linux 6.17.4-2-pve...'}
OLLAMA_AGENT: response_text=OS: Linux 6.17.4-2-pve
Python: 3.12.3
Current dir: /root/tryout/langcode_agent
User: root
Problema
Nonostante response_text sia corretto, l'output mostra:
🤖 LangCode: che so sto usando
Invece di:
🤖 LangCode: OS: Linux 6.17.4-2-pve
Python: 3.12.3...
Ipotesi
- L'agente viene chiamato due volte: Prima con SimpleAgent (fallback) e poi con OllamaToolAgent
- L'eccezione viene mangiata: Il blocco try/except in main.py potrebbe nascondere l'errore
- Bufferizzazione output: I print() non vengono visualizzati prima dell'eco
Codicemain.py (main loop)
while True:
user_input = input("\n👤 You: ").strip()
if not user_input:
continue
# Check if it's a command (starts with /)
if process_command(user_input):
continue
# Otherwise, treat it as a chat message
try:
print("MAIN: before invoke", flush=True)
result = agent.invoke({"messages": [HumanMessage(content=user_input)]})
print(f"MAIN: after invoke, result type={type(result)}", flush=True)
# Extract the AI's response
if result and "response" in result:
response_text = result["response"]
else:
ai_message = result["messages"][-1]
response_text = ai_message.content if hasattr(ai_message, 'content') else str(ai_message)
print(f"\n🤖 LangCode: {response_text}")
except Exception as e:
print(f"\n❌ Errore: {str(e)}")
Osservazioni Critiche
-
MAIN: before invokeNON viene mai visualizzato -
Questo significa che
agent.invoke()potrebbe:- Essere chiamato ma stampare prima di return
- Sollevare un'eccezione che viene catturata
- Restituire qualcosa di inaspettato
-
L'eco
🤖 LangCode: che so sto usandoè identico all'input👤 You: che so sto usando- Questo suggerisce che l'agent sta restituendo l'input invece del risultato
Prossimi Passi Suggeriti
- Verificare quale agente viene creato: Aggiungere print in
create_langcode_agent() - Verificare il tipo di agent restituito: Stampare
type(agent)dopo la creazione - Forzare output non bufferizzato: Usare
sys.stdout.flush()dopo ogni print - Verificare se l'eccezione viene mangiata: Stampare SEMPRE l'eccezione, anche se vuota
File Principali
main.py- Entry point, main loopollama_agent.py- OllamaToolAgent con intent detectionlangcode.py- CLI entry point
Comandi di Test
# Sul server
cd ~/tryout/langcode_agent
source venv/bin/activate
python langcode.py
# Testare: "che SO sto usando"
# Osservare: Il debug output dell'agente MA NON l'output MAIN