Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿค– Cloudflare Autonomous Computer Agent

Cloudflare Workers Durable Objects Cloudflare Computer License: MIT

An autonomous documentation update agent built on Cloudflare Computer (@cloudflare/computer) and Durable Objects. The agent inspects source code files on an edge-native Virtual Filesystem (VFS), parses function signatures and docstrings, and autonomously syncs Markdown documentation on Cloudflare's global edge network.

Important

๐Ÿ’ก Problem to be Solved

The Ephemeral State Problem: In traditional serverless AI architectures, worker execution state is wiped between requests. When an AI coding agent writes or refactors code, it loses memory of files and intermediate state once the serverless function completes.
The Cloudflare Computer Solution: By binding a stateful Virtual Filesystem backed by SQLite Durable Objects, this agent maintains a persistent edge workspace. It automatically detects code changes, extracts docstrings, and updates API reference documentation persistently without external database dependencies.


๐Ÿ—๏ธ Architecture & Execution Flow

+-------------------------------------------------------------------+
|                        Cloudflare Worker                          |
|                                                                   |
|  +-------------------------------------------------------------+  |
|  |                 DocAgentDurableObject                       |  |
|  |                                                             |  |
|  |  +-------------------------------------------------------+  |  |
|  |  |         Cloudflare Computer Workspace VFS             |  |  |
|  |  |                 (SQLite Backed DO)                    |  |  |
|  |  |                                                       |  |  |
|  |  |  [workspace.fs.readFile] -> Extract Function Signatures |  |  |
|  |  |  [workspace.fs.writeFile] -> Update docs/API_REF.md    |  |  |
|  |  |  [workspace.runtime.exec] -> Execute Isolate Checks   |  |  |
|  |  +-------------------------------------------------------+  |  |
|  +-------------------------------------------------------------+  |
+-------------------------------------------------------------------+
                                 |
                                 v
                     [ Narrative Output: outputs.md ]

โšก Installation & Setup

Prerequisites

  • Node.js (v18.0 or higher)
  • npm (Package Manager)

Step 1: Install Dependencies

Open your project directory in the terminal and install @cloudflare/computer:

# Install Cloudflare Computer package
npm install @cloudflare/computer

Step 2: Run Live Agent File Watcher

Start the live file watcher to automatically process Python files (.py) in src/:

# Start live watcher mode
npm run watch

Whenever a .py file inside src/ is added or edited, the agent logs telemetry in the terminal and updates docs/API_REFERENCE.md and outputs.md.

Step 3: Run Standalone Test Pipeline

To run a one-off execution of the doc agent pipeline:

# Execute local test run
npm run test:run

Step 4: Run Local Emulator (Wrangler Dev)

Emulate the Cloudflare Worker and Durable Object SQLite storage locally:

# Start local Wrangler dev server on localhost
npm run dev

โ˜๏ธ Optional Cloud Deployment

To deploy the worker and Durable Object SQLite storage to Cloudflare's global edge network:

# Authenticate with Cloudflare
npx wrangler login

# Deploy to Cloudflare Network
npm run deploy

๐Ÿ’ป Code Architecture & Integration

Configuration (wrangler.json)

{
  "name": "cloudflare-computer-doc-agent",
  "main": "src/index.js",
  "compatibility_date": "2026-08-01",
  "compatibility_flags": [
    "nodejs_compat"
  ],
  "durable_objects": {
    "bindings": [
      {
        "name": "MY_DURABLE_OBJECT",
        "class_name": "DocAgentDurableObject"
      }
    ]
  },
  "migrations": [
    {
      "tag": "v1",
      "new_sqlite_classes": [
        "DocAgentDurableObject"
      ]
    }
  ]
}

Workspace Operations (src/index.js)

import { Workspace } from '@cloudflare/computer';

export class DocAgentDurableObject {
  async fetch(request) {
    // 1. Initialize persistent Cloudflare Computer Workspace
    const workspace = await Workspace.get(this.env.MY_DURABLE_OBJECT, "doc-workspace");

    // 2. Read source code from edge VFS
    const code = await workspace.fs.readFile("/src/calculator.py", "utf-8");

    // 3. Autogenerate & write Markdown documentation
    await workspace.fs.writeFile("/docs/API_REFERENCE.md", "# Generated Docs...");

    // 4. Verify runtime execution via Isolate Shell
    const check = await workspace.runtime.exec("python3 --version", { backend: "isolate-shell" });

    return new Response("Doc Sync Complete");
  }
}

๐Ÿ“ Repository Structure

.
โ”œโ”€โ”€ .gitignore          # Git exclusion rules
โ”œโ”€โ”€ package.json        # Project metadata and script definitions
โ”œโ”€โ”€ wrangler.json       # Cloudflare Worker & Durable Object configuration
โ”œโ”€โ”€ README.md           # Master project documentation
โ””โ”€โ”€ src/
    โ””โ”€โ”€ index.js        # Main Autonomous Documentation Agent & DO handler

๐Ÿ“Š Project Execution Outputs

Running npm run watch or npm run test:run scans Python source files and produces structured outputs:

  1. docs/API_REFERENCE.md: Autogenerated Python API reference document with function signatures and docstrings.
  2. outputs.md: Full telemetry execution report detailing VFS file reads, function extraction counts, and runtime status.

๐ŸŽฏ 5 Real-World Use Cases

  1. Continuous Documentation Sync: Automatically sync API documentation whenever a coding agent edits function signatures or exports.
  2. Edge Code Sandbox Verification: Execute code snippets inside Cloudflare Workers Isolates to verify code examples before publishing docs.
  3. Multi-File PDF Pipeline: Generate Markdown docs on the Isolate backend and pass them to Container backends running pandoc for PDF export.
  4. Autonomous PR Reviewer: Inspect incoming PR code changes in a temporary Durable Object workspace and generate architectural change notes.
  5. AI Chat Memory & Scratchpad: Store multi-turn agent workspace state, prompt history, and artifact builds persistently on the edge.

๐Ÿ”ฎ 5 Future Features

  1. Git Integration via ws:git: Direct commits and push operations of autogenerated docs to GitHub repositories.
  2. AST Parsing for TypeScript & Python: Advanced language parsers running inside Dynamic Worker Isolates.
  3. Container-Based Pandoc PDF Export: Direct integration with @cloudflare/computerd container for automated PDF rendering.
  4. Webhook Event Listeners: Automatic execution triggers upon GitHub push webhooks.
  5. Interactive UI Visualizer: Web interface for viewing live VFS file trees and agent task logs side-by-side.

๐Ÿท๏ธ Keywords

Cloudflare Computer Cloudflare Workers Durable Objects SQLite VFS AI Agents Agent Sandbox Serverless AI Edge Computing Wrangler CLI Autonomous Coding Agent Node.js JavaScript


๐Ÿ“œ License

MIT License. See LICENSE for full details.

About

Cloudflare Computer Dropped: Workspace For AI Agents! - Persistent edge VFS workspace for AI agents using Cloudflare Computer (@cloudflare/computer) and Durable Objects.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages