Lab GuideMeet your Droid and your Coding Agent
14:30 17:00

LAB GUIDE / SECTION 06

Meet your Droid and your Coding Agent

In Phase 2 your Worker gets a new route, POST /api/chat. The Hub will send the same question to everyone's Droid at once, and each Droid answers in character.

Your Droid is a little protocol droid you program to play your Star Wars Character: think of a droid doing its best Darth Vader impression, in whatever tone you give it.

This time you won't type the code yourself. You'll write the one creative part by hand, your Droid's Tone Prompt, and direct a Coding Agent to build the rest. You wrote Phase 1 by hand, so you'll recognise everything it writes.

Note

Two different AIs are involved today, so keep them apart:

  • Your Coding Agent runs on your laptop and writes code for you.
  • Your Droid runs on Cloudflare and answers questions in the Rounds. It's what the agent builds.

6.1 The contract#

Every Droid must speak the same "language" so the Hub can talk to all of them:

http
POST /api/chat
Content-Type: application/json

{ "round": "intro", "question": "Introduce yourself to the class in under 280 characters." }

Your Droid must answer within 8 seconds with:

json
{ "answer": "Rrraaargh! Chewbacca here, guardian of a very dramatic nebula..." }

Answers longer than 280 characters get cut off by the Hub. That's the Contract: as long as you follow it, your Droid can work any way you like inside.

6.2 Your Droid's personality#

Your Droid's persona is built from two ingredients. Only the second one is yours to write:

IngredientWhere it comes fromWho does it
CharacterYour own getCharacter(env.CHARACTER_ID) from Mission 2: name, homeworld, birth year, films. Turned into a prompt by buildSystemPrompt in src/prompt.jsPre-built, plus your Mission 2
Tone PromptHow your Droid talks: pirate, grumpy professor, sports commentator…You, by hand (Mission 3)

So the work you did in Mission 2 pays off twice: it fills your ID card, and it tells your Droid who it is. buildSystemPrompt({ character, tone }) glues the Character and your tone into one system prompt.

Your Character is the one you picked in Mission 1. Want a different one? Change CHARACTER_ID in wrangler.jsonc any time (the table is in section 3.2).

6.3 Your Droid's model#

Your Droid answers with Workers AI on your own free account: a small, cheap chat model, set as MODEL at the top of src/droid.js (@cf/meta/llama-3.2-3b-instruct). It runs on Cloudflare's network, next to your Worker, with no API key.

Tip

The free plan includes 10,000 Workers AI Neurons a day. One answer from your Droid costs about 2.5 Neurons, roughly 4,000 answers a day. Run every Round and test as much as you like.

Your Coding Agent uses a different model: whichever one its harness gives you. That model writes your code; the Workers AI model answers the Rounds.

6.4 Set up your Coding Agent#

Already use a Coding Agent, like Claude Code, Cursor, Codex or GitHub Copilot? Keep it, and follow its page on Cloudflare Agent setup. You only need its Skills step (6.4.2 below). Skip the MCP server.

No Coding Agent yet? Use OpenCode: it's free, open source, and runs in your terminal.

6.4.1 Install OpenCode (skip if you have an agent)#

sh
npm install -g opencode-ai
opencode --version

Tip

Started this during the break? Even better: it's probably done.

6.4.2 Teach it Cloudflare#

From the root of your repo (the folder with wrangler.jsonc):

sh
npx skills add https://github.com/cloudflare/skills

When it asks, select your agent and accept the defaults. Skills are instructions your agent loads only when it needs them: how to write a Worker, how wrangler works, how to call Workers AI. They make its code right the first time, which saves time and tokens.

6.4.3 Start it in your repo#

sh
opencode

Pick one of the free models it offers (type /models to see the list). Then give it a first, tiny prompt:

txt
In two sentences: what does this Worker do, and which file would I edit to build /api/chat?

It should mention your ID card page, your Star Wars Character, and src/droid.js. It found that out by reading AGENTS.md, a short file in your repo written for Coding Agents: what the project is, which files to touch, and how to test. Open it and have a look. Because the agent doesn't have to explore the whole repo, it uses far fewer tokens, and free models have small limits.

Warning

Your agent may send whatever it reads to its model provider, and free models often log what they receive. Don't paste passwords or keys into the chat. AGENTS.md tells it never to commit secrets.

Check#

  • Your Coding Agent runs in your repo and answered the first prompt
Agent not working?
ProblemFix
opencode: command not foundClose and reopen the terminal. Still missing? npx opencode-ai runs it without installing
A free model is "rate limited" or very slowSwitch to another free model with /models. Many people are using the same free models right now
npx skills add asks many questionsChoose your agent and accept the defaults
Nothing works after 5 minutesRaise your hand, and meanwhile do Mission 3 by hand: section 7 has the full solution

Next: Build your Droid

Checks are saved automatically on this browser.

Your project

Pick your Droid Name first. Add the rest when you know it; every field is optional. These details stay in this browser and are never sent anywhere.

A nickname, not your full name. Used for your Student Worker and repo. Lowercase letters, numbers and hyphens; up to 40 characters.

The workers.dev subdomain you choose at signup. Same naming rules as your Droid Name.

Add this later, or paste a GitHub repo URL to fill your username and Droid Name.

My URL is different

Optional. Use your public https://…workers.dev URL. Paths and trailing slashes are removed. Leave blank to use your Droid Name and subdomain.

LIVE PREVIEW

Your droid will live at https://<your-droid-name>.<your-subdomain>.workers.dev

Your repo: github.com/<your-github-user>/<your-droid-name>