This commit is contained in:
Timothy Jaeryang Baek
2026-03-07 17:24:17 -06:00
parent b04de83c20
commit 7cdff6b1e2

View File

@@ -173,6 +173,9 @@ def get_citation_source_from_tool_result(
Returns a list of sources (usually one, but query_knowledge_files may return multiple).
"""
_EXPECTS_LIST = {"search_web", "query_knowledge_files"}
_EXPECTS_DICT = {"view_knowledge_file"}
try:
try:
tool_result = json.loads(tool_result)
@@ -181,6 +184,12 @@ def get_citation_source_from_tool_result(
if isinstance(tool_result, dict) and "error" in tool_result:
return []
# Validate tool_result type based on what the branch expects
if tool_name in _EXPECTS_LIST and not isinstance(tool_result, list):
return []
elif tool_name in _EXPECTS_DICT and not isinstance(tool_result, dict):
return []
if tool_name == "search_web":
# Parse JSON array: [{"title": "...", "link": "...", "snippet": "..."}]
results = tool_result