Fosowl/agenticSeek · error · ConnectionError
{str(e)} Connection to {self.server_ip} failed.
Error message
{str(e)}
Connection to {self.server_ip} failed. What it means
In respond(), a ConnectionError raised while calling the provider's llm(history, verbose) is re-raised with an appended '\nConnection to {self.server_ip} failed.' so the developer knows which endpoint was unreachable. It means the HTTP request to the LLM backend (local server or cloud endpoint) could not establish/receive a connection.
Source
Thrown at sources/llm_provider.py:88
load_dotenv()
url = os.getenv("DOCKER_INTERNAL_URL")
if not url: # running on host
return "http://localhost", False
return url, True
def respond(self, history, verbose=True):
"""
Use the choosen provider to generate text.
"""
llm = self.available_providers[self.provider_name]
self.logger.info(f"Using provider: {self.provider_name} at {self.server_ip}")
try:
thought = llm(history, verbose)
except KeyboardInterrupt:
self.logger.warning("User interrupted the operation with Ctrl+C")
return "Operation interrupted by user. REQUEST_EXIT"
except ConnectionError as e:
raise ConnectionError(f"{str(e)}\nConnection to {self.server_ip} failed.")
except AttributeError as e:
raise NotImplementedError(f"{str(e)}\nIs {self.provider_name} implemented ?")
except ModuleNotFoundError as e:
raise ModuleNotFoundError(
f"{str(e)}\nA import related to provider {self.provider_name} was not found. Is it installed ?")
except Exception as e:
if "try again later" in str(e).lower():
return f"{self.provider_name} server is overloaded. Please try again later."
if "refused" in str(e):
return f"Server {self.server_ip} seem offline. Unable to answer."
raise Exception(f"Provider {self.provider_name} failed: {str(e)}") from e
return thought
def is_ip_online(self, address: str, timeout: int = 10) -> bool:
"""
Check if an address is online by sending a ping request.
"""
if not address:View on GitHub (pinned to ae57a23577)
Solutions
- Start/verify the local LLM server and confirm it listens on the host:port in self.server_ip (curl the endpoint).
- Correct the server IP/port configuration (get_internal_url result) for your environment, especially inside Docker (use host.docker.internal or the service name).
- Read the original str(e) above the appended message — it contains the underlying request failure (refused/timeout/DNS).
- Retry with backoff if the server was temporarily restarting; verify with the same URL from the same network context as the app.
Example fix
// before
provider = LLMProvider("ollama") # server_ip points at localhost:11434 but nothing is listening
result = provider.respond(history) # ConnectionError: ... Connection to 127.0.0.1 failed.
// after (terminal)
$ ollama serve & # start the backend
$ curl http://localhost:11434/api/tags # verify reachable
then rerun provider.respond(history) Defensive patterns
Strategy: retry
Validate before calling
import socket
def server_reachable(host_port) -> bool:
host, port = host_port.rsplit(":", 1)
try:
with socket.create_connection((host, int(port)), timeout=3):
return True
except OSError:
return False
assert server_reachable(provider.server_ip), f"LLM server {provider.server_ip} is down" Try / catch
import time
for attempt in range(3):
try:
return provider.respond(history)
except ConnectionError as e:
if attempt == 2:
raise
time.sleep(2 ** attempt) Prevention
- Start the local LLM server (e.g. ollama serve) before launching the app; health-check it in a startup script.
- In Docker, use host.docker.internal or the compose service name instead of localhost for self.server_ip.
- Add exponential-backoff retries around respond() for transient connection drops.
- Log provider.server_ip at startup and curl it once to confirm reachability in the same network context.
When it happens
Trigger: Calling sync_llm_request/respond while the local inference server (e.g. Ollama, LM Studio) is not running or listening on a different port than self.server_ip; wrong host/port in provider config; server crashed mid-session; network/firewall blocking the endpoint; container networking where in_docker host resolution fails (get_internal_url picked the wrong URL).
Common situations: Forgetting to start `ollama serve` before running the agent; using localhost inside Docker when the server runs on the host; the model server bound to 127.0.0.1 while accessed from another container; wrong port after a version update of the local server.
Understand the failure class
Background: ECONNREFUSED and "connection refused" / "could not connect to server" errors: what they mean and how to fix them — this error's family across 44 libraries.
Related errors
- Ollama connection failed. is the server running ?
- Ollama connection failed at {host}. Check if the server is
- Model not set
- Missing or malformed Authorization header
- Invalid API token
AI-assisted analysis of Fosowl/agenticSeek@ae57a23577 (2026-08-30).
Data as JSON: /api/errors/b92fe34071e0ad3e.
Report an issue: GitHub.