Skip to content

R2

Last updated View as MarkdownAgent setup

skills.r2() reads Agent Skills from an R2 bucket. Use it to share one set of skills across many agents, or to manage skills outside your Worker's code.

Store skills in a bucket

The bucket uses the same layout as a skills folder, under a key prefix. Every <prefix><name>/SKILL.md object is a skill, and the objects beside it are its resources:

skills/release-notes/SKILL.md
skills/release-notes/references/style-guide.md
skills/release-notes/scripts/format-release-notes.js
skills/pirate-voice/SKILL.md

Upload skills with any R2 interface. For example, with Wrangler:

npx wrangler r2 object put my-agent-skills/skills/pirate-voice/SKILL.md --file ./pirate-voice/SKILL.md --remote

Read skills from the bucket

Bind the bucket to your Worker:

{
	"r2_buckets": [{ "binding": "SKILLS_BUCKET", "bucket_name": "my-agent-skills" }],
}
[[r2_buckets]]
binding = "SKILLS_BUCKET"
bucket_name = "my-agent-skills"

Return the source from getSkills():

src/server.jsjs
import { Think, skills } from "@cloudflare/think";

export class MyAgent extends Think {
	getSkills() {
		return [skills.r2(this.env.SKILLS_BUCKET, { prefix: "skills/" })];
	}
}
src/server.tsts
import { Think, skills } from "@cloudflare/think";

export class MyAgent extends Think<Env> {
	getSkills() {
		return [skills.r2(this.env.SKILLS_BUCKET, { prefix: "skills/" })];
	}
}

Options

Option Default Description
prefix "" Key prefix that holds the skill directories
skills all skills Only serve these skill names
refreshIntervalMs 60000 How long to reuse a bucket listing before listing again. 0 lists on every call
id r2:<prefix> Source id used in diagnostics

Each SKILL.md is checked against the specification when the bucket is listed. Skills that break a rule load with a warning, and skills with no description are skipped and logged.

Run skill scripts

R2 stores files but cannot run them. To run scripts from R2 skills, set the experimental script runner, which adds the run_skill_script tool. To store and run skills as files, use a Computer Workspace instead.

Example

The r2-skills example ↗︎ loads skills from a bucket, runs a script with the script runner, and lets you upload and delete skills from the UI.

Was this helpful?