Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions hermes_cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,15 @@ def ensure_hermes_home():
"url": None,
"password": False,
"category": "setting",

},
"OPENAI_LLM_TIMEOUT": {
"description": "Timeout in seconds for LLM calls when using custom OpenAI-compatible provider",
"prompt": "LLM timeout for custom provider",
"url": None,
"password": False,
"category": "setting",
"advanced": True,
},
}

Expand Down
10 changes: 9 additions & 1 deletion run_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2390,11 +2390,19 @@ def _build_api_kwargs(self, api_messages: list) -> dict:
if self.provider_data_collection:
provider_preferences["data_collection"] = self.provider_data_collection

# Determine timeout based on provider and environment variable
timeout = 900.0
if self.provider == "custom" and os.getenv("OPENAI_LLM_TIMEOUT"):
try:
timeout = float(os.getenv("OPENAI_LLM_TIMEOUT"))
except ValueError:
pass # Keep default if invalid

api_kwargs = {
"model": self.model,
"messages": api_messages,
"tools": self.tools if self.tools else None,
"timeout": 900.0,
"timeout": timeout,
}

if self.max_tokens is not None:
Expand Down
38 changes: 37 additions & 1 deletion tests/test_run_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,12 +490,48 @@ def test_basic_kwargs(self, agent):
assert kwargs["messages"] is messages
assert kwargs["timeout"] == 900.0

def test_timeout_custom_provider_with_env(self, agent, monkeypatch):
import os

monkeypatch.setenv("OPENAI_LLM_TIMEOUT", "120.0")
agent.provider = "custom"
messages = [{"role": "user", "content": "hi"}]
kwargs = agent._build_api_kwargs(messages)
assert kwargs["timeout"] == 120.0

def test_timeout_custom_provider_without_env(self, agent):
import os

os.environ.pop("OPENAI_LLM_TIMEOUT", None)
agent.provider = "custom"
messages = [{"role": "user", "content": "hi"}]
kwargs = agent._build_api_kwargs(messages)
assert kwargs["timeout"] == 900.0

def test_timeout_openrouter_ignores_env(self, agent, monkeypatch):
import os

monkeypatch.setenv("OPENAI_LLM_TIMEOUT", "120.0")
agent.provider = "openrouter"
messages = [{"role": "user", "content": "hi"}]
kwargs = agent._build_api_kwargs(messages)
assert kwargs["timeout"] == 900.0

def test_timeout_invalid_env_value(self, agent, monkeypatch):
import os

monkeypatch.setenv("OPENAI_LLM_TIMEOUT", "invalid")
agent.provider = "custom"
messages = [{"role": "user", "content": "hi"}]
kwargs = agent._build_api_kwargs(messages)
assert kwargs["timeout"] == 900.0

def test_provider_preferences_injected(self, agent):
agent.providers_allowed = ["Anthropic"]
messages = [{"role": "user", "content": "hi"}]
kwargs = agent._build_api_kwargs(messages)
assert "provider" in kwargs.get("extra_body", {})
assert kwargs["extra_body"]["provider"]["only"] == ["Anthropic"]

def test_reasoning_config_default_openrouter(self, agent):
"""Default reasoning config for OpenRouter should be medium."""
messages = [{"role": "user", "content": "hi"}]
Expand Down