fix: convert crawl_tool dict return to JSON string for type consistency (#636)

Keep fixing #631
This pull request updates the crawl_tool function to return its results as a JSON string instead of a dictionary, and adjusts the unit tests accordingly to handle the new return type. The changes ensure consistent serialization of output and proper validation in tests.
This commit is contained in:
Willem Jiang
2025-10-21 10:00:33 +08:00
committed by GitHub
parent e2ff765460
commit d30c4d00d3
2 changed files with 10 additions and 6 deletions

View File

@@ -1,6 +1,7 @@
# Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
# SPDX-License-Identifier: MIT
import json
import logging
from typing import Annotated
@@ -22,7 +23,7 @@ def crawl_tool(
try:
crawler = Crawler()
article = crawler.crawl(url)
return {"url": url, "crawled_content": article.to_markdown()[:1000]}
return json.dumps({"url": url, "crawled_content": article.to_markdown()[:1000]})
except BaseException as e:
error_msg = f"Failed to crawl. Error: {repr(e)}"
logger.error(error_msg)