1
0

fix: log Ollama disconnections with specific error handling (#92)

- BaseAgent.run(): catch httpx.ConnectError/ReadError/ConnectionError,
  log 'Ollama disconnected: <error>' at ERROR level, then re-raise
- session.py: distinguish Ollama disconnects from other errors in
  chat(), chat_with_tools(), continue_chat() — return specific message
  'Ollama appears to be disconnected' instead of generic error
- 11 new tests covering all disconnect paths
This commit is contained in:
2026-03-14 18:40:15 -04:00
parent 8a14bbb3e0
commit bce6e7d030
3 changed files with 329 additions and 2 deletions

View File

@@ -14,6 +14,7 @@ import logging
from abc import ABC, abstractmethod
from typing import Any
import httpx
from agno.agent import Agent
from agno.models.ollama import Ollama
@@ -120,8 +121,15 @@ class BaseAgent(ABC):
Returns:
Agent response
"""
result = self.agent.run(message, stream=False)
response = result.content if hasattr(result, "content") else str(result)
try:
result = self.agent.run(message, stream=False)
response = result.content if hasattr(result, "content") else str(result)
except (httpx.ConnectError, httpx.ReadError, ConnectionError) as exc:
logger.error("Ollama disconnected: %s", exc)
raise
except Exception as exc:
logger.error("Agent run failed: %s", exc)
raise
# Emit completion event
if self.event_bus: