AgentLabWrite one yourself

Stop 3 · Write one yourself

The skeleton is ready. You fill in the 8 key blanks. Each blank teaches the concept it needs before it asks, and a wrong answer gets a specific explanation.

Blank 1/8

The agent memory starts out empty. How do you write an empty array?

New conceptAn array = a row of numbered slots that you can keep appending to. It is written with square brackets: ["apple", "banana"] has two slots, and [] is empty — no slots yet. Our agent uses one array as its memory.
agent.js — the file you are writing0/8 blanks filled
agent.js
1import Anthropic from "@anthropic-ai/sdk";
2const client = new Anthropic();
3
4// ① An array: the agent's entire memory
5const messages = two characters;
6
7// Your task goes into the array
8messages.push({ role: ____, content: "look around this folder" });
9
10// ② A loop
11while (____) {
12 // Send the whole array to the model
13 const res = await client.messages.create({
14 model: "claude-sonnet-5",
15 max_tokens: 4096,
16 system: "You are a local file assistant",
17 tools,
18 ____,
19 });
20
21 // Push the model's reply back into the array
22 messages.push({ role: "assistant", content: ____ });
23
24 // No tool request in the reply? The task is done
25 if (res.stop_reason !== ____) ____;
26
27 // Tool requested → you run it (the model has no hands)
28 const results = await runTools(res.content);
29
30 // Push the result back, next round
31 messages.push({ role: ____, content: results });
32}

The grey ____ are blanks that come later. The glowing line holds the current blank. Answer it in the input box above.

Check yourself

A look back: what it is

Two questions. Neither asks what the text said; both apply what you just read to a specific situation.

Nothing is scored here. Every question can be answered again, and a wrong answer names the idea it came from.

  1. Your code has just run ls and has a directory listing. You append a message to the array to hand it to the model.What is that message's role?
  2. This round the model's reply contains both a sentence for a human to read ("Let me look at the directory first") and a tool_use block. stop_reason is tool_use.What should your code do next?