AgentLabWatch it run

Stop 2 · Watch it run, in slow motion

Each press advances the real run by one step. The button label says what that step does.

STEP 1/7

Everything starts with an empty array

The panel on the right is an X-ray: it shows the real data that will be sent to the , not an interface built for people. Right now the is empty — nothing has happened yet. The system prompt at the top is the job description for the model (who it is, which tools it may use, which rules to follow). In code it is a separate parameter, sent along with every request. Remember this picture: everything that follows is just appending elements to this array.

🐣 Beginner question: Why does the array matter so much?

The API keeps no state between calls: every request is handled as if it were the first. What people call the conversation, the context, or the memory is literally this array. You keep the full history yourself and hand the whole thing over every time. Once you understand this, an agent is no longer mysterious.

Chat — what the user sees
No messages yet. Start with "Send the task".
X-ray — the messages array sent to the APIlength: 0
parametersystem
You are a local file assistant; you can list directories and read files with tools.
Loop round 0stop_reason: 0 tokens
The code — that step was these linesagent.js · 32 lines
agent.js
1import Anthropic from "@anthropic-ai/sdk";
2const client = new Anthropic(); // API key comes from an env var — never hardcode it
3
4// ① An array: the agent's entire memory
5const messages = [];
6
7// Your task becomes the array's first element
8messages.push({ role: "user", content: task });
9
10// ② A loop
11while (true) {
12 // Send the whole array to the model (all of it, every round)
13 const res = await client.messages.create({
14 model: "claude-sonnet-5",
15 max_tokens: 4096, // max length of one reply: required, omitting it returns 400
16 system: "You are a local file assistant…", // system prompt: a separate param
17 tools, // the tool list: which tools the model may ask for
18 messages, // ← the array itself
19 });
20
21 // Push the model's reply back into the array, as-is
22 messages.push({ role: "assistant", content: res.content });
23
24 // No tool request in the reply? The task is done — exit
25 if (res.stop_reason !== "tool_use") break;
26
27 // Tool requested → run it on your machine (the model has no hands)
28 const results = await runTools(res.content);
29
30 // Push results back into the array, loop again
31 messages.push({ role: "user", content: results });
32}

These 32 lines are a complete agent. Nothing essential is left out. At the next stop you write them yourself.

Space next step · back