Skip to content

1. Hello agent

Checkpoint 1 of 69 minutes

Hello agent

Give FieldTrip its first instructions, deploy it, and have a conversation it can remember.

Your team asks you to organise an offsite in Lisbon. There are dates to agree on, places to find, and a group to keep happy. Let’s build an assistant to help: FieldTrip.

Right now, your app can only say pong. In this step, you give FieldTrip a job description and connect it to an AI model so it can reply in the chat. Each conversation keeps its own message history, so your next question can build on the last one.

What you’ll add: instructions for the planner, a model to generate replies, and a connection between the chat page and the agent.

Under the hood: how Flue runs the agent

An agent is an exported, capitalized function whose file starts with 'use agent'. Flue re-runs that function before every model call. useModel selects the model. The function name FieldTrip generates FlueFieldTripAgent and the FLUE_FIELD_TRIP_AGENT binding. Each conversation ID selects a separate Durable Object: Cloudflare storage that keeps that conversation’s history.

Terminal window
git status --short
git branch --show-current

Start from main with no local changes. Keep the claimed temporary account’s ID exported in the terminal where you will run npm run deploy.

Run this command in your terminal to remove the starter’s placeholder file:

Terminal window
rm src/agents/.gitkeep

Then switch to your code editor, such as VS Code. In its file sidebar, open src → agents and create a new file named field-trip.ts. Paste the Complete file code below into that file’s editing pane and save it.

  • src
    • agents
      • field-trip.ts

Create this file. Create the parent folders if needed. In your code editor (for example, VS Code), open the file named above. Copy the code in Complete file, paste it into that file's editing pane, and save.

src/agents/field-trip.ts
'use agent';
import { useModel } from '@flue/runtime';
export function FieldTrip() {
useModel('cloudflare/@cf/google/gemma-4-26b-a4b-it');
return `You are FieldTrip, a helpful team-offsite planner. You help groups plan memorable offsites by understanding their destination, dates, headcount, budget, and interests.`;
}

Connect the chat page to FieldTrip in src/app.ts:

  • src
    • app.ts

Replace the entire contents of this file. In your code editor (for example, VS Code), open the file named above. Copy the code in Complete file, paste it into that file's editing pane, and save.

src/app.ts
import { Hono } from 'hono';
import { createAgentRouter } from '@flue/runtime/routing';
import { FieldTrip } from './agents/field-trip.ts';
import chatUi from './ui/index.html?raw';
// src/app.ts is the Flue route map. Its default export owns every HTTP request
// the Worker receives. Agents get mounted here with createAgentRouter(...)
// starting in checkpoint 1.
const app = new Hono();
// A small chat UI for trying the agent in a browser, locally and on workers.dev.
app.get('/', (c) => c.html(chatUi));
app.get('/api/ping', (c) => c.text('pong'));
app.route('/agents/field-trip', createAgentRouter(FieldTrip));
export default app;

Give Cloudflare a place to store each conversation by adding the agent’s first storage setup entry (a migration) in wrangler.jsonc:

  • wrangler.jsonc

Replace the entire contents of this file. In your code editor (for example, VS Code), open the file named above. Copy the code in Complete file, paste it into that file's editing pane, and save.

wrangler.jsonc
{
"$schema": "./node_modules/wrangler/config-schema.json",
"name": "field-trip-agent",
// Flue requires nodejs_compat and a compatibility_date of 2026-04-01 or newer.
"compatibility_date": "2026-09-01",
"compatibility_flags": ["nodejs_compat"],
// Workers AI binding: powers `cloudflare/@cf/...` models. No API keys needed.
// AI always runs remotely (even in `vite dev`), so `remote: true` is explicit.
"ai": {
"binding": "AI",
"remote": true
},
// Durable Object migrations. Flue generates one DO class per agent
// (FieldTrip -> FlueFieldTripAgent), but YOU own the migration history.
// Checkpoint 1 adds the first entry here. Append; never rewrite deployed entries.
"migrations": [
{
"tag": "v1",
"new_sqlite_classes": ["FlueFieldTripAgent"]
}
]
}

Account selection comes from CLOUDFLARE_ACCOUNT_ID, set in your terminal during Session setup. Use the temporary account you claimed, and keep its account ID out of wrangler.jsonc.

Terminal window
npm run deploy
sleep 5
npm run smoke -- https://field-trip-agent.<subdomain>.workers.dev cp1-live "Hi, who are you? Two sentences."
npm run smoke -- https://field-trip-agent.<subdomain>.workers.dev cp1-live "What was the first thing I asked you? One sentence."

Use the exact URL printed by the deploy command. The deployment should list the AI binding and FlueFieldTripAgent Durable Object. The first command should end with ✔ completed; the second should recall your introduction question.

Save your workers.dev subdomain to open this test ↗https://field-trip-agent.<subdomain>.workers.dev/?id=cp1-live

This opens the same conversation as the smoke test. If you repeat this checkpoint, before copying its commands.

Verification gate

Prove it works

  • FieldTrip introduces itself as your offsite planner.
  • A second message with cp1-live recalls the first.
  • The browser-test link opens your deployed chat and the same conversation.
Optional mini quizCheck your understanding: meet FieldTrip3 questions instant feedback
1What job have we given FieldTrip?
2What generates the words in its replies?
3Why can FieldTrip recall your first question?
Recovery lane

Get back on track in under a minute

If a dev server is running, stop it first. Uncommitted work is stashed and the current commit gets a backup branch before anything moves.

Option 01

Restart this exercise

Return to main, rebuild this exercise, then use its Live deploy verification tab. Stop any running dev server with Ctrl+C before switching.

Terminal
git stash push --include-untracked -m "workshop recovery"
git fetch origin
git branch -f workshop-backup HEAD
git switch --no-track -C workshop origin/main
npm ci
Option 02

Catch up with the room

Jump to cp/1-hello-agent, then use this checkpoint's Live deploy verification tab. Stop any running dev server with Ctrl+C before switching.

Terminal
git stash push --include-untracked -m "workshop recovery"
git fetch origin
git branch -f workshop-backup HEAD
git switch --no-track -C workshop origin/cp/1-hello-agent
npm ci

Next: Give FieldTrip a trip notebook →