Back to Course|Claude Computer Use: Building Autonomous Desktop & Browser Agents
Lab

Build a File Organizer Agent

45 min
Intermediate
3 Free Attempts

Instructions

Objective

Build a Python agent that uses Claude's Computer Use capability to organize files in a messy Downloads folder by moving them into categorized subfolders.

Background

This lab combines visual GUI automation with bash commands for an efficient hybrid approach. The agent should use bash for bulk file operations while using the computer tool for visual verification.

Requirements

Create a class FileOrganizerAgent with the following methods:

1. analyze_folder(path: str) -> dict

Scans the folder and returns file counts by category:

{
    "images": ["photo1.jpg", "screenshot.png"],
    "documents": ["report.pdf", "notes.txt"],
    "videos": ["clip.mp4"],
    "archives": ["backup.zip"],
    "other": ["random.xyz"]
}

2. create_category_folders(base_path: str) -> list[str]

Creates subfolders for each category if they don't exist. Returns list of created folder paths.

3. organize_files(path: str) -> dict

Moves files to appropriate category folders. Returns summary:

{
    "moved": 15,
    "skipped": 2,
    "errors": []
}

4. generate_tool_calls(path: str) -> list[dict]

Returns the sequence of Computer Use tool calls needed to:

  • Open file manager at the specified path
  • Verify the organization visually
  • Take a screenshot of the result

File Categories

Category Extensions
images .jpg, .jpeg, .png, .gif, .bmp, .svg, .webp
documents .pdf, .doc, .docx, .txt, .md, .xlsx, .pptx
videos .mp4, .avi, .mkv, .mov, .webm
audio .mp3, .wav, .flac, .aac, .ogg
archives .zip, .tar, .gz, .rar, .7z
code .py, .js, .ts, .html, .css, .json
other everything else

Expected Tool Call Format

{
    "type": "tool_use",
    "name": "computer",
    "input": {
        "action": "type",
        "text": "nautilus /home/user/Downloads"
    }
}

Hints

  • Use os.path.splitext() to get file extensions
  • Use shutil.move() for moving files
  • The bash tool is faster for file operations than GUI clicks
  • Use Computer Use for visual verification at the end

Grading Rubric

analyze_folder correctly categorizes files by extension25 points
create_category_folders creates directories safely20 points
organize_files moves files and handles errors properly30 points
generate_tool_calls produces valid Computer Use format25 points

Your Solution

This lab requires Python
🐍Python(required)
3 free attempts remaining