diff --git a/agentic_security/config.py b/agentic_security/config.py index a586298..e642640 100644 --- a/agentic_security/config.py +++ b/agentic_security/config.py @@ -140,6 +140,8 @@ use_disk_cache = false [network] retry = 3 +timeout_connect = 30 +timeout_response = 90 """.replace( "$HOST", host ) diff --git a/agentic_security/http_spec.py b/agentic_security/http_spec.py index 4cba0da..544ebb1 100644 --- a/agentic_security/http_spec.py +++ b/agentic_security/http_spec.py @@ -49,14 +49,21 @@ class LLMSpec(BaseModel): except Exception as e: raise InvalidHTTPSpecError(f"Failed to parse HTTP spec: {e}") from e + def timeout(self): + return ( + settings_var("network.timeout_connect", 30), + settings_var("network.timeout_response", 90), + ) + async def _probe_with_files(self, files): - async with httpx.AsyncClient() as client: + transport = httpx.AsyncHTTPTransport(retries=settings_var("network.retry", 3)) + async with httpx.AsyncClient(transport=transport) as client: response = await client.request( method=self.method, url=self.url, headers=self.headers, files=files, - timeout=(30, 90), + timeout=self.timeout(), ) return response @@ -100,7 +107,7 @@ class LLMSpec(BaseModel): url=self.url, headers=self.headers, content=content, - timeout=(30, 90), + timeout=self.timeout(), ) return response