Skip to main content
← Back to Projects
AI Agents Mock-tested Tutorial companion repo

AI Agent in 10 Minutes

Companion code for the post: Claude, a tool loop and memory in one file

Companion repo for my AI agent tutorial: a one-file Node.js agent with the Anthropic SDK, a tool-use loop, conversation memory and offline tests.

Solo build, written for the tutorial

ClaudeAnthropic SDKNode.jsTool UseTutorial
01 / Problem

The problem

My post How to Build an AI Agent in 10 Minutes walks through an agent built with the Anthropic SDK, memory and a tool. The repo that went with it had drifted: it was a LangChain and OpenAI chat with no memory and no tools. Readers who cloned it got different code from the code they had just read.

02 / Solution

What I built

I rebuilt the repo to match the post. It is one file, agent.js, that talks to Claude through the official Anthropic SDK, keeps the conversation in memory, and lets Claude call a tool, get_current_time, which reads your machine's clock. You can chat in the terminal with npm start or run npm run demo, which tells the agent your name, asks for the time (the tool) and then asks for your name back (the memory).

03 / Demo

See it running

Demo coming

A recorded walkthrough of AI Agent in 10 Minutes is on the way. Until then, the write-up and the diagram below show how it works.

04 / Architecture

How it fits together

AI Agent in 10 Minutes

The agent loop: memory, Claude, one tool

  1. Terminal chatNode.js on your machinenpm startnpm run demo
    your message
  2. MemoryconversationHistory array in agent.jsSent with every request
    history + tools
  3. ClaudeAnthropic API, messages.create + toolstool_use or end_turn
    tool_use
  4. Toolget_current_time, runs locallyMax 5 roundsResult back to memory
The tool result goes back into memory and Claude is asked again until it answers in text.
05 / Write-up

How it works

Every message is pushed onto a conversationHistory array, and the whole array goes to messages.create with the tool list. When Claude stops with tool_use, the full assistant reply is kept unchanged, each requested tool runs, and all results go back in one user message. Then Claude is asked again, until it answers in text:

        // Keep the FULL assistant content (text, thinking and tool_use blocks), unchanged.
        conversationHistory.push({ role: 'assistant', content: response.content });

        if (response.stop_reason !== 'tool_use') {
          const text = textOf(response.content);
          return response.stop_reason === 'max_tokens' ? `${text}\n(Reply cut off: max_tokens reached.)` : text;
        }

That excerpt is from agent.js in the updated repo. A safety break stops the loop after 5 tool rounds in a row, a failed turn is removed from memory so the history stays valid, and bad keys, rate limits and network errors print a short explanation instead of a crash. Adding a tool means one definition in tools and one function with the same name in toolFunctions.

The tests run offline with Node's built-in test runner and a stubbed client: tool round trips, parallel tool calls, failing tools, memory, the safety break and refusals.

Stack: Node.js 20 or newer, @anthropic-ai/sdk, dotenv, and node --test.

Status and links

The updated code is in the public GitHub repo (merged on 4 October 2026, replacing the older LangChain version). It passes its offline tests but has not yet been run against the live API with my key; that is the next step. The post linked above is the walkthrough it matches.

Work with me

Need something like this built?

I build AI automations, agents and Salesforce solutions for teams. Tell me what you want to automate and I’ll tell you honestly whether it’s a fit.

Share
Discussion

Comments

Loading comments...

Add a comment

Comments are reviewed before they appear.