SSD Nodes Learn 🎉 VPS from $4.99/mo
How to do am Matt ConnorBy Matt Connor · Updated 2026-08-07

How to Learn AI Agents from Scratch, Step by Step

Learn AI agents in six build-first stages: concepts, your own loop, tools, memory, loop design, and safety, with one project to build for each stage.

Di path for six stages

To learn AI agents from scratch, work through six stages in order: di concepts, your first loop, tools, memory, loop design, and safety. Each stage get one thing wey you go build with your own hands. If you jump ahead, na the commonest reason people dey stuck, because framework dey hide exactly di part wey you need see.

AI agent na loop around language model wey get permission to call tools. Na that sentence carry di whole subject. Everything wey follow na detail about wetin go enter di loop, wetin di tools fit touch, and how you go stop di loop if e start misbehave. If you fit explain di loop to another person, you don learn di main thing. If na only framework names you fit mention, you never learn am.

Di plan below assume say you learn by building. Read one stage, build di small thing, break am on purpose, then move go di next one. Stage wey you only read na stage wey you never do.

Wetin you actually need before stage 1

The honest prerequisite list short, and e shorter pass wetin most course pages dey suggest.

  • You fit read and write Python or TypeScript for the level of a fifty-line script.
  • You dey comfortable for Linux shell: install package, edit file, read log.
  • You get API key for hosted model, or machine wey fit run local model.

Na the complete list be that. You no need machine learning theory, and you no need don train model before. Nothing for agent work involve gradients or training data. Graphics card only matter if you decide to run the model by yourself. Na separate skill be that, and you fit learn am later from how to host Ollama on VPS to self-host LLM.

Wetin people dey underestimate na the shell part. Agents dey fail because of permissions, paths, environment variables, and processes wey dey die quietly. If stack trace about PATH or file mode make you close terminal, spend one weekend learn Linux basics first. E go save you one month later.

Stage 1: agent na wetin, and wetin e no be

Start with one API call and no loop. Send one prompt, print the reply, then check the token counts for the response. Now you understand the unit of cost and the unit of latency.

Next, learn tool use. Na the only genuinely new idea for this whole field. You describe one function to the model with a name, a description, and a JSON (JavaScript object notation) schema for the inputs. The model no run anything. E reply with one structured request: call run_command with these arguments. Your code run the function, send the output back as a message, then ask the model again. The model na planner wey dey read text and write text. Your code na the thing wey get hands.

Chatbot dey end after one reply. Agent dey repeat that exchange until the model stop asking for tools. Na this repetition be the whole difference, and na why the failure modes still differ. Chatbot fit give wrong answer once. Agent fit act on wrong answer several times before anybody notice.

Stage 2: write di loop by yourself, one time

No start with framework. Write about thirty lines of Python so you fit understand the shape of the thing yourself.

sudo apt update && sudo apt install -y python3-venv
python3 -m venv ~/agent
source ~/agent/bin/activate
pip install anthropic
export ANTHROPIC_API_KEY=your-key-here
import subprocess
import anthropic

client = anthropic.Anthropic()

tools = [{
    "name": "run_command",
    "description": "Run a read only shell command and return its output.",
    "input_schema": {
        "type": "object",
        "properties": {"command": {"type": "string"}},
        "required": ["command"],
    },
}]

messages = [{"role": "user", "content": "How much disk space is free here?"}]

while True:
    response = client.messages.create(
        model="claude-opus-5",
        max_tokens=4096,
        tools=tools,
        messages=messages,
    )
    if response.stop_reason != "tool_use":
        break
    messages.append({"role": "assistant", "content": response.content})
    results = []
    for block in response.content:
        if block.type == "tool_use":
            done = subprocess.run(
                block.input["command"], shell=True,
                capture_output=True, text=True, timeout=10,
            )
            results.append({
                "type": "tool_result",
                "tool_use_id": block.id,
                "content": done.stdout or done.stderr,
            })
    messages.append({"role": "user", "content": results})

print(next(b.text for b in response.content if b.type == "text"))

Run am with python3 agent.py. If everything dey work, e go print one paragraph wey name your filesystems and their free space, because the model ask for df -h, your code run am, and the second pass turn that table into one sentence. If e print nothing, the loop stop before any text block show. Add print(response.stop_reason) inside the loop and watch how the values dey change.

Now break am deliberately. Delete the tool_use_id line and read the error, because API go reject tool result wey no get matching id, and na the most common beginner bug for there. Ask question wey need two commands and watch the loop run twice. Ask something impossible and watch whether e give up or keep spinning forever.

One warning about this example. E pass model output straight into shell with shell=True. This one fit work for scratch machine wey you fit rebuild, but e wrong for everywhere else. Stage 6 go fix that. The concepts under the loop dey explain more fully for how to build your own AI agent on a VPS.

Stage 3: tools wey agent never get before

Your run_command tool dey work, but real agent need tools wey fit reach outside the machine: ticket system, database, repository. To write custom wrapper for every service and every agent no go scale.

The industry don settle on Model Context Protocol (MCP) as the answer. An MCP server dey expose set of tools through standard transport, and any MCP-aware agent fit use am without custom glue. The reference filesystem server na one command:

npx -y @modelcontextprotocol/server-filesystem /home/you/projects

This one need Node installed, and directory argument na the only path wey server go touch. Na this be the security model for small scale: server dey decide the boundary, no be model. Point client to am, and your agent go gain file reading and writing wey you never write yourself. How to run these properly under service account, with explanation of transport choices, dey covered for how to run MCP servers on a VPS for AI coding agents.

The lesson for this stage be say tool design na the real work. Vague description go make model guess. Tool wey dey return forty thousand characters go poison context window. Tool wey fit delete things go eventually delete things.

Stage 4: memory, wey mostly na files

Beginners dey rush go use vector database for here. No use am yet, at least for now.

Agent no get memory between calls. You go resend the complete conversation every time, na why long session dey cost more per turn pass short one. So memory divide into two problems. The first one na wetin fit enter context window right now. You manage am by summarising, trimming old tool output, and caching the stable prefix of your prompt, so you go pay only small part of the price for am. The second one na wetin survive restart. Na storage be that.

For the second problem, ordinary markdown file wey agent fit read and write better pass vector database for almost every first project. Give am one file. Tell am the format. Tell am to read the file before e start and update am whenever e learn something. You go get most of the benefit, and you fit open the file to see wetin your agent believe. Use embeddings and retrieval when the notes no longer fit inside context window, and no use dem before then.

Stage 5: loop na di product

By now you fit build agent wey dey work when you dey watch am. Stage 5 na to make am work when you no dey watch am.

Four questions dey decide whether e safe to leave agent wey nobody dey supervise. Wetin dey trigger am, so e no go run without reason. Which boundary e dey work inside, so mistake no go big. How you go verify the result, because agent wey dey mark im own work go always pass. Which budget go stop am, whether na token or wall-clock time. To design these four things deliberately na the discipline wey loop engineering, and wetin that definition cover describe.

The exercise: take your Stage 2 agent, give am task wey need four or five steps, then add hard iteration cap. After that, remove the cap and watch wetin unbounded loop go do to your token bill. Do am once with small budget, so you no go do am by mistake with big one.

Stage 6: safety, secrets, and cost

This stage no be optional, and e dey last only because you no fit feel the risk until you don build something wey dey work.

Run the agent as e own unprivileged user. Never run am as root or as your own account. This one make the blast radius remain one directory instead of the whole machine. Keep credentials away from the model reach, because anything wey dey inside context window fit come out through a tool call. The fix na short-lived tokens wey helper dey control, as e dey explained for how to keep secrets away from your AI agents. Set hard limit for spending, because unattended loop go charge money for every iteration when nobody dey monitor am. The caps and batching wey fit keep spending under control dey for AI agent cost control for an always-on VPS.

Cost need one clear number. As of July 2026, Claude Opus 5 dey charge $5 for every million input tokens and $25 for every million output tokens. Agent wey dey send back growing conversation fit push few hundred thousand tokens through one task. Prompt caching and smaller model for routine steps fit change this calculation much more than any prompt adjustment.

Prompt injection belong here too. If your agent dey read web page, issue tracker, or inbox, anybody wey write that text dey also write instructions for your agent. The defence no be cleverer system prompt. Na boundary be the defence, because agent wey no fit delete repository no fit let person talk am into deleting one.

Wich roadmap you suppose follow?

Choose one curriculum and finish am instead of sampling six. The Microsoft ai-agents-for-beginners repository na the most complete free one, an eighteen-lesson course wey don pass 70,000 stars as of July 2026, and e map well to the stages above. Roundups of trending agent repositories dey useful to see wetin dey available, but dem no too useful as syllabus, because list wey sort by stars dey sort by popularity, no be by teaching order.

When you want real project to practise with, coding agent na the best first target: feedback dey immediate, tools dey clear, and mistakes cheap to undo. Run coding AI agent for VPS explain one end-to-end setup. If you prefer study working systems instead of building from zero, comparison for the best self-hosted AI agents show how different projects solve the same loop in different ways.

How long this one go take?

For person wey don dey program before, stages 1 and 2 fit take one evening. Stage 3 fit take one weekend, and na tool descriptions take most of the time, no be protocol. Stages 4 and 5 fit take some weeks of real use, because na only when you watch your agent forget something you go learn wetin e dey forget. Stage 6 no really ever finish, because every new capability wey you give am go open the matter again.

Two months of steady evening work fit carry most people reach working, bounded, useful agent. People wey take one year usually na the ones wey continue to read instead of building.

FAQ

I need know machine learning before I fit build AI agent?

No. To build agent mean say you go call model through API and connect the tool requests to real functions. Na ordinary application programming be that. You no go touch training, gradients, or datasets. The skills wey decide whether your agent go work na tool schema design, error handling, and Linux permissions. Machine learning theory only become relevant if you later fine tune model. That one na different work with different prerequisites.

I suppose start with framework like LangChain or CrewAI?

Write one raw loop first, then adopt framework. Framework dey replace the thirty lines for stage 2 with configuration object. That one convenient after you understand wetin e replace, but e fit confuse you before then. When your agent dey misbehave, you need reason about the message list and tool results directly. That one harder if you never see dem before. After you write one loop by yourself, framework go save time instead of hiding the mechanism.

How much e cost to learn AI agents?

If you set limit, e cost less than most people expect. Hosted API key and small VPS fit cover everything for these six stages. The real risk no be hourly rate. Na unbounded loop wey dey bill every iteration while you dey sleep. Set hard spend limit for your API account on day one. Add iteration cap to every loop wey you write. Use cheaper model for routine steps. If you run the model locally, token bill go comot, but you go need the correct hardware.

Wetin be the difference between AI agent and chatbot?

Chatbot dey answer once. Agent dey repeat one cycle: model ask for tool, your code run am, result go back, and model decide wetin to do next. Na this repetition dey allow agent finish task wey get several steps. Na why agents need boundaries wey chatbots no need. Wrong answer from chatbot na bad paragraph. Wrong answer from agent na bad paragraph plus anything wey e do because of am.

#ai-agents#learning#curriculum#mcp#self-hosting