Chapter 1: An agent is a for loop
ChatGPT, Claude Code, AWS Kiro, and other agents are just while loops.
They look like this.
let chatHistory = [];
while (true) {
const userInput = await getUserInput();
chatHistory = append(chatHistory, userInput);
const chatbotResponse = await sendChatRequestToLlm([...chatHistory, userInput]);
chatHistory = append(chatHistory, chatbotResponse);
}
There are a couple of integrations into the filesystem. But those also work off the chatHistory. I won't show those here, but I will show them soon.