An agent calls an external search tool to gather context before generating a code fix. The search tool has a 30-second timeout but occasionally takes longer than that under high load, causing the tool call to time out. When this happens, the agent raises an unhandled exception and terminates the entire task. What is the correct pattern to handle this scenario?
Select an answer to reveal the explanation.
Short Explanation
When an optional search tool times out, you don't let it kill the whole job. You catch that timeout and keep going with cached or existing context, noting the search was unavailable. That graceful fallback keeps the task alive instead of crashing.
Full Explanation
External tool calls in agentic workflows are often for gathering optional or supplemental context rather than for mandatory inputs. When such a call times out, the correct response is graceful degradation — the agent acknowledges the unavailable data and proceeds with whatever context it already has, possibly noting reduced confidence or limited context in its output. The implementation pattern is: catch the timeout exception specifically, log it with sufficient detail for debugging, and continue execution with a fallback path such as cached results, empty context, or a note that the search was skipped. This keeps the overall task alive and produces partial value rather than complete failure. Increasing the tool timeout to 120 seconds reduces timeout frequency but does not address what happens when a timeout does occur. Under heavy load, even a 120-second timeout may be exceeded, so the fundamental problem — an unhandled exception on timeout — remains. Wrapping the entire agent task in a try/catch block so the task silently fails without logging the timeout is the opposite of the correct fix. Silent failure hides the timeout from monitoring and debugging, produces no output and no log, and makes the failure invisible. The task should be logged and should produce partial output, not silence. Removing the external search tool from the agent's tool list eliminates the timeout risk by removing capability rather than handling it gracefully. Removing a useful tool to avoid its failure is the least desirable engineering approach because it degrades the agent's capability rather than making it resilient. Graceful fallback keeps optional-tool failures from becoming task-terminating failures.