Building AI Agents: A Developer Guide from Model to Tools

by Fahim Mahmud Chisti

Building AI agents as a developer starts with one idea: an agent is a language model in a loop. It reads a goal, decides which tool to call, looks at the result and repeats until the job is done. The model is only one part; the tools you expose, the limits you set and how you check the output decide whether an agent is useful or just expensive. This guide maps the path from a first local model to an agent that does real work, with a tutorial for each stage.

Quick answer: This guide covers the four parts of every agent, when to use a local or hosted model, a build order that keeps risk low, and the guardrails to add before an agent touches real systems. New to agents? Start by running a model locally with Ollama, then follow the stages in order:

  1. Run a model locally and call it from a script.
  2. Add one tool and let the model decide when to use it.
  3. Give the agent an interface, such as a Telegram bot.
  4. Add your own documents with retrieval (RAG).
  5. Split work across several agents only when one agent with good tools is not enough.
In this guide
  1. The Four Parts of an Agent
  2. Local or Hosted Models: Which to Start With
  3. Stage 1: Talk to a Local Model over HTTP
  4. A Build Order That Keeps Risk Low
  5. Guardrails to Add Before an Agent Touches Real Systems
  6. Tutorials in This Guide
  7. Frequently Asked Questions
  8. Next Steps

The Four Parts of an Agent

  • Model. The language model that plans and writes. It can run locally through Ollama or come from a hosted API.
  • Tools. Functions the model is allowed to call: search a database, send a message, read a file, call an API.
  • Memory. The conversation so far, plus anything you retrieve from your own data and add to the prompt.
  • Control loop. Your code. It passes tool results back to the model, enforces step and time limits, and decides when to stop.

Local or Hosted Models: Which to Start With

Local models keep data on your machine, cost nothing per request and work offline. They need memory: as a rough guide, a quantised (compressed) 7 to 8 billion parameter model wants about 8 GB of free RAM or VRAM, and larger models need proportionally more. Hosted models are usually stronger at long, multi-step reasoning and tool use, and you pay per token.

A common setup is to prototype locally, then move only the steps that need more capability to a hosted model. Model names change quickly, so pick a current small instruction-tuned model from the Ollama library for local work and check your provider’s model list for hosted work.

Stage 1: Talk to a Local Model over HTTP

Ollama exposes an HTTP API on port 11434, so any language that can send a POST request can use a local model. Install Ollama, download a model with ollama pull (this example uses llama3; any chat model works if you change the model field), then run this in a terminal on the same machine:

curl http://localhost:11434/api/chat -d '{
  "model": "llama3",
  "stream": false,
  "messages": [
    { "role": "system", "content": "You are a concise assistant for developers." },
    { "role": "user", "content": "Explain what a webhook is in two sentences." }
  ]
}'

What you should see: a single JSON object, with the answer in message.content. The first request can take a while because Ollama loads the model into memory; later requests are faster. Set "stream": true, or leave the field out, to receive the answer as a stream of JSON lines instead.

If curl reports that the connection was refused, Ollama is not running: start the Ollama app or run ollama serve. If the response says the model was not found, run ollama pull with the same name you put in the model field. The full setup, hardware notes and more fixes are in Run LLMs Locally with Ollama.

A Build Order That Keeps Risk Low

  1. Run a model locally and call it from a script, as above.
  2. Add one tool and let the model decide when to use it. Keep the tool’s description short and precise. How to set up an AI agent locally with Ollama and CrewAI builds a two-agent workflow with a file tool that cannot write outside its folder.
  3. Give it an interface so you can use it away from the terminal. Build a Telegram AI chatbot with Node.js covers BotFather, per-user memory and an allow-list so strangers cannot spend your credits.
  4. Add your own data with retrieval: search your documents first and pass only the relevant passages to the model. The RAG architecture checklist walks through each stage and how to measure retrieval.
  5. Chain steps or split work across several agents only when a single agent with good tools is clearly not enough. More agents mean more cost and more ways to fail. The local content marketing agent shows a simple research, outline and write chain in Node.js.

Guardrails to Add Before an Agent Touches Real Systems

  • Give each tool the least access it needs. A read-only database user is safer than a full one.
  • Set a maximum number of steps and a timeout for every run.
  • Log every prompt, tool call and result so you can see why the agent did something.
  • Ask for confirmation before anything that cannot be undone: sending email, deleting data, spending money.
  • Treat text from web pages, files and emails as untrusted. It can contain instructions aimed at your agent (prompt injection).

Tutorials in This Guide

Frequently Asked Questions

Do I need a GPU to build an AI agent?

No. Small quantised models run on a normal CPU through Ollama if you have enough free RAM, about 8 GB for a 7 to 8 billion parameter model. Answers are slower than on a GPU, which is fine for learning and for background jobs.

Should I use an agent framework or write my own loop?

Start with your own loop: a script that calls the model, runs the tool it asks for and sends back the result. It teaches you how agents fail. Move to a framework such as CrewAI when you need several agents, task hand-offs or built-in tool wiring.

How much does it cost to run an AI agent?

A local model has no per-request fee; you pay for hardware and electricity. Hosted models charge per token, and agents use more tokens than chat because every step sends the conversation and tool results again. Step limits keep costs predictable.

Are AI agents safe to connect to email, files or databases?

Only with guardrails. Give tools the least access they need, require confirmation for anything irreversible, log every action, and treat content the agent reads as untrusted, because a web page or email can contain instructions that try to take over the agent.

Next Steps

Run the curl example above, then work through the stages in order, one tutorial at a time. When your agent needs to call other services or receive events, the API integrations and webhooks guide covers the plumbing, and the self-hosted tools guide covers the server it runs on.

all_in_one_marketing_tool