From 585e9a4713184944bbe39c64d2eda87813577eec Mon Sep 17 00:00:00 2001 From: Solaria Date: Sat, 14 Mar 2026 09:29:01 +0000 Subject: [PATCH] Make LLM timeout configurable via AgentConfig (#37) --- opus_orchestrator/config.py | 1 + opus_orchestrator/utils/llm.py | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/opus_orchestrator/config.py b/opus_orchestrator/config.py index d41f7c9..d62df0d 100644 --- a/opus_orchestrator/config.py +++ b/opus_orchestrator/config.py @@ -28,6 +28,7 @@ class AgentConfig(BaseModel): temperature: float = Field(default=0.7, ge=0.0, le=2.0) max_tokens: Optional[int] = Field(default=None, description="Max tokens per response") max_iterations: int = Field(default=10, description="Max iterations per agent task") + timeout: float = Field(default=120.0, description="HTTP timeout in seconds") # Provider configuration provider: str = Field(default="minimax", description="LLM provider: minimax, openai, anthropic") diff --git a/opus_orchestrator/utils/llm.py b/opus_orchestrator/utils/llm.py index 1bb5804..df8a103 100644 --- a/opus_orchestrator/utils/llm.py +++ b/opus_orchestrator/utils/llm.py @@ -27,6 +27,7 @@ class LLMClient: model: str = "MiniMax/MiniMax-M2.1", base_url: Optional[str] = None, max_retries: int = 3, + timeout: float = 120.0, ): """Initialize LLM client. @@ -40,6 +41,7 @@ class LLMClient: self.api_key = api_key or os.environ.get("MINIMAX_API_KEY") or os.environ.get("OPENAI_API_KEY") self.provider = provider self.model = model + self.timeout = timeout # Normalize model name for MiniMax if provider == "minimax": @@ -57,7 +59,7 @@ class LLMClient: self.base_url = "https://api.openai.com/v1" # Async client - self._async_client = httpx.AsyncClient(timeout=120.0) + self._async_client = httpx.AsyncClient(timeout=self.timeout) # Initialize retry handler retry_config = RetryConfig( @@ -237,7 +239,7 @@ class LLMClient: f"{self.base_url}/v1/messages", headers={**headers, "Content-Type": "application/json"}, json=payload, - timeout=120, + timeout=self.timeout, ) if response.status_code != 200: @@ -288,7 +290,7 @@ class LLMClient: f"{self.base_url}/chat/completions", headers=headers, json=payload, - timeout=120, + timeout=self.timeout, ) response.raise_for_status() @@ -307,4 +309,5 @@ def get_llm_client(config: Optional[Any] = None) -> LLMClient: api_key=cfg.agent.api_key, provider=cfg.agent.provider, model=cfg.agent.model, + timeout=cfg.agent.timeout, )