Add server tool timeout protection
This commit is contained in:
@@ -58,6 +58,7 @@ class DuplexPipeline:
|
||||
_SENTENCE_CLOSERS = frozenset({'"', "'", "”", "’", ")", "]", "}", ")", "】", "」", "』", "》"})
|
||||
_MIN_SPLIT_SPOKEN_CHARS = 6
|
||||
_TOOL_WAIT_TIMEOUT_SECONDS = 15.0
|
||||
_SERVER_TOOL_TIMEOUT_SECONDS = 15.0
|
||||
_DEFAULT_TOOL_SCHEMAS: Dict[str, Dict[str, Any]] = {
|
||||
"search": {
|
||||
"name": "search",
|
||||
@@ -984,7 +985,18 @@ class DuplexPipeline:
|
||||
tool_results.append(result)
|
||||
continue
|
||||
|
||||
result = await execute_server_tool(call)
|
||||
try:
|
||||
result = await asyncio.wait_for(
|
||||
execute_server_tool(call),
|
||||
timeout=self._SERVER_TOOL_TIMEOUT_SECONDS,
|
||||
)
|
||||
except asyncio.TimeoutError:
|
||||
result = {
|
||||
"tool_call_id": call_id,
|
||||
"name": self._tool_name(call) or "unknown_tool",
|
||||
"output": {"message": "server tool timeout"},
|
||||
"status": {"code": 504, "message": "server_tool_timeout"},
|
||||
}
|
||||
await self._emit_tool_result(result, source="server")
|
||||
tool_results.append(result)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user