mirror of
https://github.com/agent0ai/agent-zero.git
synced 2026-12-03 03:55:12 +00:00
Handle missing search results safely
Guard against a None result or missing 'results' key by iterating over (result or {}).get('results', []) instead of result['results']. This prevents exceptions when the search backend returns no data and yields an empty output list while preserving existing behavior of limiting to SEARCH_ENGINE_RESULTS.
This commit is contained in:
parent
2cf73c4b4a
commit
b5a6402e72
1 changed files with 1 additions and 1 deletions
|
|
@ -32,7 +32,7 @@ class SearchEngine(Tool):
|
|||
return f"{source} search failed: {str(result)}"
|
||||
|
||||
outputs = []
|
||||
for item in result["results"]:
|
||||
for item in (result or {}).get("results", []):
|
||||
outputs.append(f"{item['title']}\n{item['url']}\n{item['content']}")
|
||||
|
||||
return "\n\n".join(outputs[:SEARCH_ENGINE_RESULTS]).strip()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue