Skip to main content
NullClaw supports edge deployment with a hybrid architecture that separates network I/O from core agent logic.

Architecture

Edge deployment uses a two-layer pattern:
  1. Edge Host (JavaScript/TypeScript): Handles HTTP, secrets, API calls, webhook parsing
  2. WASM Core (Zig): Contains agent decision logic, policy selection, feature extraction
This keeps secrets and network operations in the trusted edge host while the agent logic remains portable and swappable.

Cloudflare Worker Example

The examples/edge/cloudflare-worker/ directory demonstrates a complete edge deployment.

What It Does

1

Receive webhook

Cloudflare Worker receives Telegram webhook update
2

Extract features

JavaScript host extracts text features (length, question marks, keywords)
3

Call WASM policy

WASM choose_policy() returns response policy (concise/detailed/urgent)
4

Build prompt

Host builds system prompt based on selected policy
5

Call LLM

Send request to OpenAI Chat Completions API
6

Send response

Reply sent back to Telegram chat

WASM Core

The agent logic is a tiny Zig module compiled to WASM:
agent_core.zig

Build WASM

Compile the Zig module to WASM:
Or use the build script:
The resulting WASM module is < 10 KB.

Worker Implementation

The edge host loads the WASM module and calls it for each request:
worker.mjs

Wrangler Configuration

wrangler.toml

Prerequisites

  • Cloudflare account
  • Wrangler CLI
  • Zig 0.15.2
  • Telegram bot token (or other webhook provider)
  • OpenAI API key

Deployment

1

Build WASM core

2

Configure secrets

3

Create KV namespace (optional dedup)

Add to wrangler.toml:
4

Deploy

5

Set webhook

Why WASM?

Separation of Concerns

  • Host owns secrets: API keys, tokens, credentials stay in edge environment variables
  • Host owns network: HTTP calls, webhooks, rate limiting handled by Worker
  • WASM owns logic: Decision trees, policy selection, feature extraction

Portability

The same WASM module can run on:
  • Cloudflare Workers
  • Deno Deploy
  • AWS Lambda@Edge
  • Fastly Compute@Edge
  • Any WASI-compatible runtime

Security

WASM provides sandboxing:
  • No filesystem access
  • No network access
  • No system calls
  • Pure function execution

Size

Zig’s ReleaseSmall optimization produces tiny WASM modules:
  • agent_core.wasm: < 10 KB
  • Faster cold starts on edge platforms
  • Fits in Cloudflare’s 1 MB Worker script limit with room to spare

Feature Extraction

The host extracts simple features from text:
These features are passed to WASM as integers (no string marshalling overhead).

Policy-Based Prompts

The worker selects system prompts based on WASM policy:

Deduplication with KV

Telegram webhooks retry on failure. Use Cloudflare KV to deduplicate:
KV has eventual consistency. This is best-effort dedup, not a strict guarantee.

Monitoring

Cloudflare Workers provide built-in analytics:
  • Request rate
  • Error rate
  • CPU time
  • Edge location distribution
Access in Cloudflare dashboard under Workers > Analytics.

Evolution Strategy

To update agent behavior:
  1. Edit agent_core.zig
  2. Run ./build_wasm.sh
  3. Run wrangler deploy
No changes to the Worker host required if the exported function signature stays the same.

Limitations

Edge deployments are stateless. They cannot:
  • Maintain long-running agent sessions
  • Execute local tools (filesystem, shell)
  • Store large context windows
Use edge deployment for:
  • Webhook handlers
  • Request routing
  • Policy selection
  • Simple Q&A bots
Use full runtime deployment for autonomous agents.