SSD Nodes Learn Hosting plans →
How to do am Matt ConnorBy Matt Connor · Updated 2026-08-29

How to Learn AI Agents From Scratch, Naija Guide

Learn AI agents from scratch with 6 build stages: concepts, your own loop, tools, memory, loop design, and safety, plus one project for every stage.

The path for six stages

If you wan learn AI agents from scratch, follow these six stages one after another: the concepts, your first loop, tools, memory, loop design, and safety. For each stage, you go build one thing by yourself. The commonest reason people stop for road na say framework hide exactly the part wey you need see.

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

The plan below assume say you dey learn by building. Read one stage, build the small thing, deliberately make am fail, then move go the next one. If you only read a stage, you never do that stage.

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 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 one.

Na the complete list be that. You no need machine learning theory, and you no need to don train model before. Nothing for agent work dey involve gradients or training data. Graphics card only matter if you decide to run the model by yourself. Na separate skill wey you fit learn later from hosting 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 die quietly. If stack trace about PATH or file mode make you close terminal, spend weekend learn Linux basics first. E go save you one month later.

Stage 1: wetin agent be, 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. You don understand the cost unit and the latency unit.

Then learn tool use. Na the only genuinely new idea for the whole field be this. You describe one function to the model with a name, description, and JSON (JavaScript object notation) schema for its 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. The code for your side of that exchange get one name once you start compare designs: na the agent harness, the loop, tools, and permissions wey you wrap around a model wey get none of its own.

Chatbot dey stop 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 dey different too. Chatbot fit give wrong answer once. Agent fit act on wrong answer several times before anybody notice.

Stage 2: write di loop by yourself, just once

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 e work well, e go print one paragraph wey name your filesystems and dem free space, because the model ask for df -h, your code run am, then the second pass turn that table into 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 on purpose. 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 two times. Ask something wey no possible and watch whether e give up or dey spin forever.

One warning about this example. E pass model output straight into shell with shell=True. This one acceptable for scratch machine wey you fit rebuild, but e wrong for everywhere else. Stage 6 go fix am. The concepts under this loop dey explain more fully for how to build your own AI agent for 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 dey scale.

The Model Context Protocol (MCP) na the answer wey industry don settle on. MCP server dey expose some 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

Node need dey installed for this, and directory argument na the only path wey server go touch. This na the security model for short: server dey decide the boundary, no be model. Point client go am, and your agent gain file reading and writing wey you never write yourself. How to run these properly, under service account and with explanation of transport choices, dey covered for how to run MCP servers for VPS for AI coding agents. For another server wey point to real data instead of scratch directory, how to self-host openGym, workout tracker ship one wey read-only, so you fit practise asking questions about your own training history without giving agent anything wey e fit spoil.

The lesson for this stage be say tool design na the real work. Vague description go make model guess. Tool wey 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 quickly choose vector database for here. No do 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 get two separate problems. The first one na wetin fit enter context window now. You fit manage am by summarising, trimming old tool output, and caching the stable prefix of your prompt so you go pay small part of the price for am. The second one na wetin go 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 fit enter context window again, and no use dem before that.

Stage 5: loop na di product

By now, you fit make 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 unattended agent alone. Wetin go trigger am, so e no go run without reason. Wetin be di boundary wey e go operate inside, so mistake no go spread far. How you go verify di result, because agent wey dey mark im own homework go always pass. Wetin be di budget wey go stop am, whether na tokens or total running time. To design these four things deliberately na di discipline wey loop engineering, and wetin dat definition cover describe.

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

Stage 6: safety, secrets, and cost

This stage no be optional. E dey last only because you no fit feel the risk until you 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 stop for one directory instead of the whole machine. Keep credentials away from the model, because anything wey dey inside the context window fit come out through a tool call. The fix na short-lived tokens with limited scope behind a helper, as how to keep secrets away from your AI agents explain. Set a hard spending limit, because unattended loop go charge for every iteration when nobody dey watch. The caps and batching wey keep am under control dey for how to control AI agent cost on an always-on VPS.

If your agent dey run inside a harness instead of a script wey you write yourself, some parts of this stage go be configuration instead of code. DeepSeek Harness plugins wey worth installing cover plenty of the same work with budget caps, tool permission rules, and injection scanning.

Cost need one clear number. As of July 2026, Claude Opus 5 dey charge $5 per million input tokens and $25 per million output tokens. A chatty agent wey dey resend a conversation as e dey grow fit push a few hundred thousand tokens through one task. Prompt caching and a smaller model for routine steps go change the calculation much more than any prompt adjustment.

Prompt injection dey belong here too. If your agent dey read a web page, issue tracker, or inbox, the person wey write that text dey also write instructions for your agent. Web search na usually the first tool wey open this door. how to point an agent at your own SearXNG instance show the wiring and the injection surface side by side. The defence no be to write a smarter system prompt. Na the boundary matter, because agent wey no fit delete a repository no fit be talked into deleting one.

Wich map you suppose follow?

Pick 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 match the stages above well. Roundups of trending agent repositories dey useful to see wetin dey available, but dem no too useful as syllabus, because list wey stars sort am dey arranged by popularity, no be by teaching order.

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

How long dis one go take?

For person wey already dey program, stages 1 and 2 fit take one evening. Stage 3 fit take one weekend. Most of the time go tool descriptions, no be protocol. Stages 4 and 5 fit take some weeks of real use, because na as you dey watch your agent forget things you go learn wetin e dey forget. Stage 6 no really dey finish. Every new capability wey you give am fit open the work again.

Two months of steady evening work fit help most people build agent wey dey work, get clear limits, and dey useful. People wey take one year na usually people 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 call model through API and connect the tool requests to real functions. Na normal application programming be this. You no need touch training, gradients, or datasets. The skills wey determine 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 requirements.

Make I 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. This one convenient after you understand wetin e replace, but e fit confuse you before that. When your agent misbehave, you need reason directly about message list and tool results. This 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?

E cost less than most people expect, if you put limit. 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 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 model locally, token bill go comot, but you go need the right hardware.

Wetin be the difference between AI agent and chatbot?

Chatbot dey answer once. Agent dey repeat cycle: model request tool, your code run am, result go back, then model decide wetin to do next. This repetition na wetin allow agent finish task wey get several steps. Na also 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