Skip to content

examples/rlm: Add a structured RLM example - #122

Open
scuffi wants to merge 2 commits into
mainfrom
example/rlm
Open

examples/rlm: Add a structured RLM example#122
scuffi wants to merge 2 commits into
mainfrom
example/rlm

Conversation

@scuffi

@scuffi scuffi commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Summary

This adds an end-to-end example of building a recursive language model (RLM) with Cloudflare Computer.

The example keeps long context in a Computer Workspace, uses bounded model calls for semantic interpretation, and uses generated JavaScript for validation and aggregation. This pattern is useful for tasks that need to classify, extract, or compare information across more data than should be placed in one model prompt.

What this adds

The example runs the same official Oolong task through three strategies: direct context, generated JavaScript with Workspace access, and a Structured RLM with Workspace access plus ws:model.

The RLM uses the public WorkerJavaScriptBackend and native executor tool. Generated code receives a read-only Workspace and one trusted model interface:

new WorkerJavaScriptBackend({
  access: "read",
  egress: { mode: "none" },
  trustedModules: {
    "ws:model": createModelCapability(model, hooks),
  },
});

This lets a generated module map model calls across Workspace partitions and reduce their structured results with ordinary JavaScript:

const mapped = await callModel("batch", requests);
const totals = validateAndSum(mapped);
return { answer: largestLabel(totals) };

The UI compares the three approaches side by side and shows the generated module, model workers, token use, duration, and Oolong score. The RLM starts first, then overlaps its map work with both baselines to keep the comparison responsive.

Usage

npm install
npm run build --workspace @cloudflare/computer
npx wrangler login
npm run dev --workspace @cloudflare/example-rlm

Open the Vite URL and run Classify 2,433 records. Workers AI is remote, and a complete comparison can use more than 200,000 model tokens.

The example README covers the architecture, core source files, capability bounds, additional tasks, data provenance, and optional deployment.

Show how Computer Workspaces, generated JavaScript, and a bounded trusted model module can implement map/reduce over long context.

Compare direct context, JavaScript-only execution, and Structured RLM on official Oolong tasks with observable scoring and usage.
@changeset-bot

changeset-bot Bot commented Aug 25, 2026

Copy link
Copy Markdown

鈿狅笍 No Changeset found

Latest commit: 866c7bb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your interest in Cloudflare Computer.

This repository does not accept unsolicited pull requests. Please use one of the accepted contribution paths instead:

If a maintainer asked you to open this pull request, they can add the allow-pr label and reopen it.

@github-actions github-actions Bot closed this Aug 25, 2026
@scuffi scuffi added the allow-pr Allow a PR to remain open. label Aug 25, 2026
@scuffi scuffi reopened this Aug 25, 2026
@pkg-pr-new

pkg-pr-new Bot commented Aug 25, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@cloudflare/computer@122

commit: 866c7bb

Keep successful JavaScript executions visible when their returned shape cannot be scored. Sanitize invalid output into a metadata-only summary and explain the semantic capability mismatch in the comparison UI.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

allow-pr Allow a PR to remain open.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant