Skip to content

How to Create an AI Agent is published by General Action, the company that makes Emdash. When we recommend Emdash, we are recommending our own product. About this site

How to Create an AI Agent

An AI agent is a language model with tools, run in a loop until a job is done. Here is how to build your first one, step by step, in Python or without writing code.

An AI agent is a language model that has been given tools and is run in a loop, so that it chooses its own next action, sees the result, and carries on until the job is finished.

Creating one means supplying three parts: a model, a set of tools, and the loop that connects them. Everything else on this page is about choosing those parts well and keeping the result under control.

An agent is the most flexible way to use a language model, and also the slowest and most expensive. Anthropic’s guide to building effective agents recommends “finding the simplest solution possible, and only increasing complexity when needed”. Use this table before you write anything.

Your task Build this Why
One input, one output: summarise, classify, extract A single model call One request is cheap, quick and easy to check
The same steps in the same order every time A workflow: several model calls in an order your code fixes You keep control of the path, so results are predictable
Steps you cannot list in advance, because each depends on the last result An agent The model has to choose the path as it goes

If your task is in the third row, carry on. What is an AI agent? explains the difference in more depth.

Write one sentence that says what the agent does and for whom: “Answer staff questions from the notes folder and name the file each answer came from.” Then write the test: ten or twenty real requests, each with the answer or outcome you would accept.

Do this before choosing any technology. The test tells you which tools the agent needs, and later it tells you whether a change made things better or worse. Testing and guardrails shows how to turn the list into a repeatable check.

Any model that supports tool use will do. Anthropic documents the feature as tool use and says all of its current models support it. OpenAI and Google call it function calling (OpenAI’s guide, Google’s Gemini guide).

Start with a capable model, get the agent passing your test, and only then try a cheaper one against the same test. Doing it in the other order means you cannot tell whether a failure is your design or the model.

A tool is a function you write, plus a description the model can read: a name, a sentence or two on what it does, and a schema for its inputs. The model never runs the function. It asks for a call, your code runs it, and the result goes back to the model.

Begin with two or three tools that only read. Add tools that write, send or delete once the read-only version passes its test. For services that already publish tools, the Model Context Protocol saves you from writing them yourself. Both are covered in Tools and MCP.

The loop is the agent. In plain terms:

  1. Send the model the task and the tool descriptions.
  2. If it replies with a tool request, run the tool and send back the result.
  3. Repeat until it replies with an answer instead of a request, or until a step limit is reached.

You have three ways to get that loop, compared below. For a first agent, write it yourself once: Build an AI agent in Python walks through every line.

5. Add memory and context only if a test demands it

Section titled “5. Add memory and context only if a test demands it”

The list of messages your loop keeps is already a short-term memory: the model sees everything that has happened in the current run. That is enough for most first agents.

Add more only when a test fails for lack of it. Long-term memory is usually a tool that reads and writes a file or a database. More is not better here: Anthropic’s piece on context engineering describes the work as curating what goes into a limited context window, since every extra document the model must read is one more thing competing for its attention.

An agent acts on what it reads, and some of what it reads will be wrong or hostile. Four controls cover most of the risk:

  • Least privilege. Give each tool the narrowest access that does the job: one folder, a read-only database user, a test account.
  • A step limit. Stop the loop after a fixed number of turns.
  • Human approval before anything that cannot be undone, such as sending, paying or deleting.
  • Distrust of tool results. Text that comes back from a web page or an email may contain instructions aimed at your agent. OWASP lists this risk, prompt injection, first in its Top 10 for LLM applications.

Details are in Testing and guardrails.

Run every task from step 1, more than once, because the same input can produce different runs. Check the outcome, not the agent’s own report of it, and read the full record of the runs that failed. Fix one thing, then run the whole set again.

An agent is an ordinary program, so it runs wherever its trigger lives: a schedule, a webhook, a chat message. Keep the API key in an environment variable or a secrets manager, never in the code. Log every tool call with its inputs and result, and set a spending limit with your model provider if it offers one. Re-run the test set whenever you change the prompt, the tools or the model.

Consideration Write it yourself Use a framework Use a no-code builder
What you write The loop and the tools, against a provider’s SDK The tools and some configuration Nothing: you connect blocks on a canvas
You need Basic Python or TypeScript The same, plus time to learn the framework An account on the platform
Good for Learning, and small agents you want to understand fully Approval steps, resuming long runs, several agents Automations between apps you already use
Main cost You build extras such as tracing yourself A layer between you and the model’s actual requests Less control over testing, versions and cost
Guide Python walkthrough Frameworks compared Without code

Prices change, so this is the shape of the bill and not a quote.

  • Model usage is billed per token, in and out. Tool descriptions count as input on every request, according to Anthropic’s tool use pricing notes.
  • Steps multiply the cost. Each turn of the loop sends the conversation so far again, so the input grows with every step and a long run costs much more than a short one.
  • No-code platforms add their own subscription or usage charge on top of, or bundled with, the model.

A step limit and a provider-side spending cap are the two cheapest protections against a surprise bill.

  • A vague job. “Help with customer support” cannot be tested. “Draft a reply to refund requests using the order record” can.
  • Too many tools at once. Every extra tool is another way to pick the wrong one.
  • Write access on day one. Prove the agent reads and reasons correctly before it can change anything.
  • Several agents before one works. Multi-agent designs multiply the cost and the failure modes. Get a single loop passing its test first.

Frequently asked questions

How do I create an AI agent?

Pick one narrow job and write down how you will know it was done correctly. Choose a model that supports tool use, describe two or three tools to it, and run the model in a loop that executes each tool it asks for and sends the result back. Then limit what the tools can touch, test the agent on prepared tasks, and only after that run it on real work.

Can I create an AI agent without coding?

Yes. Automation platforms such as n8n, Zapier and Make let you assemble an agent from a model, instructions and tools in a visual editor, with no programming. You give up some control over testing and cost, and you are limited to the integrations the platform offers.

Which programming language is best for building an AI agent?

Python and TypeScript have the widest support. Anthropic and OpenAI publish official SDKs for both, and most agent frameworks support at least Python. Use whichever one you already read comfortably, because the agent loop itself is short in either.

Is it free to create an AI agent?

The code can be free, since the official SDKs and most frameworks are open source. The model is not. Each step of the loop is an API request billed by the number of tokens sent and received, so an agent that takes many steps costs more than a single chat reply. Check the provider's pricing page before you run anything in bulk.

Do I need a framework such as LangGraph or CrewAI?

Not for a first agent. A working tool-calling loop is roughly 75 lines against a provider's SDK, and writing it once teaches you what every framework does underneath. Reach for a framework when you need something the plain loop lacks, such as pausing for approval, resuming after a crash, or coordinating several agents.

What is the difference between an AI agent and a chatbot?

A chatbot replies with text and waits for you. An agent can also act, by calling tools such as a search, a database query or a file write, and it decides for itself which tool to call next based on what the last one returned. It keeps going until the task is finished or a limit stops it.