kodeagent.tools.download_file#

kodeagent.tools.download_file(url: str, save_name: str | None = None, save_dir: str | None = None) dict[source]#

Download a file from the internet and save it locally. Use this for downloading images, PDFs, data files, or any binary content.

For reading webpage content as text, use ‘read_webpage’ instead. For extracting content from PDFs/DOCX/XLSX, use ‘extract_as_markdown’ instead.

Examples

Parameters:
  • url – The complete URL of the file to download (must start with http:// or https://).

  • save_name – Optional filename to save with. If not provided, uses the filename from URL.

  • save_dir – Optional directory (path) to save the file. If not provided, saves to a temporary file in a temporary directory. Recommended to specify absolute path.

Returns:

  • path: str or None – Final path to the downloaded file.

  • orig_name: str or None – Original filename.

  • size: str or None – Formatted file size.

  • content_type: str or None – Content type of the file.

  • error: str or None – Error message if download fails (mutually exclusive with others).

Return type:

A dictionary with the following fields