---
title: What Is an AI Agent? Definition, Examples, Python Demo
url: https://www.masaischool.com/resources/what-is-an-ai-agent
description: An AI agent plans, uses tools, checks results and repeats until done. Agent vs chatbot vs workflow, real agents to try, MCP, risks and a runnable Python demo.
updated: 2026-11-17
publisher: Masai (https://www.masaischool.com)
---

# What Is an AI Agent? A Plain Definition, the Agent Loop, Real Agents to Try and a Python Toy You Can Run

> **Short answer**
>
> An AI agent is a program that uses an AI model to pursue a goal in a loop: it picks a tool, acts, reads the result and decides the next step until it finishes or hits a limit. A chatbot only replies. A workflow follows fixed steps. Claude Code, Codex and Cursor are agents students can try today.

Many searches ask the same thing: Claude Code works as an AI agent, so what is an AI agent? This page answers with the definition vendors use, the loop every agent runs, five real agents you can try with their free access checked on 11 November 2026, the risks, and a short Python program that runs the loop offline so you can see it.

For a longer guide to one product family, see the Masai blog post [What Is a Claude AI Agent? How It Works and Real Uses (2026)](https://www.masaischool.com/blog/what-is-a-claude-ai-agent-the-complete-beginners-guide-to-how-it-works-key-features-real-use-cases-2026/). For examples across industries, see [agentic AI examples](https://www.masaischool.com/resources/agentic-ai-examples).

1. **Goal** - what you asked for
2. **Decide** - model picks the next action
3. **Act** - a tool runs
4. **Observe** - read the result
5. **Stop or repeat** - done, blocked or step limit
The agent loop: decide, act, observe, repeat until a stop condition.

## What is an AI agent? A plain definition

An AI agent is a system where a language model chooses its own next steps and uses tools to carry them out. Anthropic, in its guide to [building effective agents](https://www.anthropic.com/engineering/building-effective-agents), draws the line this way: in a workflow, models and tools are run through predefined code paths. In an agent, the model dynamically directs its own process and tool use. Anthropic calls both kinds agentic systems, which is the umbrella term behind the phrase agentic AI.

A tool is anything the model can call: search the web, read a file, run code, click a button, query a database. The model does not run the tool itself. It asks for it, your program runs it and returns the result, and the model reads that result before deciding again. That cycle is the whole idea.

Claude Code is a good example. Its [documentation](https://code.claude.com/docs/en/overview) describes an agentic coding tool that reads your codebase, edits files, runs commands and connects to your development tools. Each of those is a tool call inside a loop.

## The agent loop: goal, tools, observe, decide

1. **Goal:** you state the outcome, such as fix this failing test.
2. **Decide:** the model picks one action, usually a tool call with arguments.
3. **Act:** your program runs the tool and captures the output.
4. **Observe:** the result goes back into the model's context. Anthropic stresses that the agent must get ground truth from the environment at each step, such as a tool result or code execution, to judge its progress.
5. **Stop or repeat:** the task ends when the goal is met, when the agent is blocked and asks you, or at a stopping condition such as a maximum number of iterations.

Good agents pause for human feedback at checkpoints or when they hit a blocker. That is a design choice you control, and it matters for safety, covered below.

## Agent vs chatbot vs workflow

|  | Chatbot | Workflow | Agent |
|---|---|---|---|
| Who decides the steps | You, one message at a time | The developer, fixed in code | The model, at run time |
| Uses tools | Sometimes | Yes, in a set order | Yes, and chooses which |
| Example | Asking a free chatbot to explain recursion | An app that extracts invoice fields, then emails them | Claude Code finding and fixing a failing test |
| Main risk | A wrong answer | Breaks on cases nobody planned for | A wrong action with real effects |
| Cost and time | Low and short | Predictable | Variable, and runs can be long |

Use the simplest option that works. If the steps never change, build a workflow. Reach for an agent when the path depends on what the tools return.

## Real agents students can try, checked on 11 November 2026

| Agent | What it does | Free access | Catch |
|---|---|---|---|
| [Claude Code](https://claude.com/pricing) (Anthropic) | Reads your codebase, edits files and runs commands, in a terminal, IDE, desktop app or browser | No. Needs Pro at $17 a month billed annually ($200 up front) or $20 monthly | Usage limits every 5 hours and every week |
| [Codex](https://developers.openai.com/codex/cloud) (OpenAI) | Takes coding tasks in the cloud, each in its own workspace that keeps working while your computer sleeps. You review changes and open a pull request | ChatGPT Free lists limited Codex access. Plus is ₹1,999 a month for expanded use | Free limits are not published |
| [Google Antigravity](https://antigravity.google/pricing) | Agentic development platform with an app, a terminal CLI, an IDE and an SDK | Individuals plan at $0 with a variety of agent models and unlimited tab completions | Basic weekly rate limits, no numbers shown |
| [Cursor](https://cursor.com/pricing) | AI editor whose Agent works on tasks in your project. Cloud agents and automations come with Premium at $30 a month | Free plan at $0 with limited agent requests | Third-party models are billed separately |
| [GitHub Copilot](https://docs.github.com/en/copilot/get-started/plans) | Plans and edits code, reviews pull requests and automates repository tasks | Copilot Free has limited access. Copilot Student is free for verified students | The newer cloud agent experience is for paid plans since 28 Oct 2026 |

More free options are on the [free AI coding agents](https://www.masaischool.com/resources/tools/free-ai-coding-agents) and [free agentic AI tools](https://www.masaischool.com/resources/tools/free-agentic-ai-tools) lists.

### Which Claude agent do people mean?

There is no single product called the Claude agent. On Anthropic's pricing page the agent-style features are Claude Code, Claude in Chrome (it reads the page you are signed in to, then clicks, types and fills forms) and handing off or scheduling tasks. All three need a paid plan. The Free plan has none of them.

## Memory, tools and MCP

A model forgets everything between calls unless your program sends the history again, so an agent keeps a running record of goals, actions and results. That record is its short-term memory, and it is limited by the context window. Some products add saved memory across chats: Claude's Free plan lists memory across conversations, and ChatGPT Free lists limited memory.

The Model Context Protocol (MCP) solves the tools side. Its documentation calls it an open-source standard for connecting AI applications to external systems, a bit like a USB-C port for AI. An MCP server wraps a tool, such as your files or a database, so any compatible agent can use it. Try it with the guide to [connecting MCP servers to your editor](https://www.masaischool.com/resources/build/connect-mcp-servers-to-your-editor) and the list of [MCP servers for coding agents](https://www.masaischool.com/resources/tools/best-mcp-servers-for-coding-agents). To give an agent standing instructions for your repository, see [writing an AGENTS.md file](https://www.masaischool.com/resources/build/write-an-agents-md-file).

## Failure modes and safety

OWASP, the security community's reference for LLM risks, calls the core danger [excessive agency](https://genai.owasp.org/llmrisk/llm062025-excessive-agency/): damaging actions triggered by unexpected, ambiguous or manipulated model output. It names three root causes: too much functionality, too many permissions and too much autonomy.

- **Wrong action, not just a wrong answer.** A chatbot that is wrong wastes a minute. An agent that is wrong can delete a file or send an email.
- **Prompt injection.** Text inside a web page or document can try to steer the agent. Anthropic's Claude in Chrome page names this as a risk for browser agents, for example tricking an agent into sharing private data.
- **Runaway loops and cost.** Agents that retry forever burn tokens. Set a step limit and a budget.
- **Compounding errors.** One bad observation early on can send every later step the wrong way.

Basic rules: give the agent the least access it needs, require your approval for anything irreversible, keep secrets out of its reach, and test it on a set of examples before trusting it. For code from agents, read [fixing bugs in AI-generated code](https://www.masaischool.com/resources/build/fix-bugs-in-ai-generated-code) and [securing a vibe-coded app](https://www.masaischool.com/resources/build/secure-a-vibe-coded-app).

## Run a toy agent in Python, no API key needed

This is a toy, and an honest one. The model is a fake: fake_model is a few if-statements that read the goal and the history. A real agent replaces that one function with a call to a language model that returns the next tool call. Everything else, the tools, the loop, the observations and the step limit, works the same way. It uses only the standard library.import ast import operator import re PRICES = {"notebook": 45, "pen": 10, "stapler": 120} # made-up prices in rupees def lookup_price(item): return PRICES.get(item, f"error: no price for {item}") def calculator(expr): ops = {ast.Add: operator.add, ast.Mult: operator.mul} def ev(node): if isinstance(node, ast.Constant): return node.value if isinstance(node, ast.BinOp) and type(node.op) in ops: return ops[type(node.op)](ev(node.left), ev(node.right)) raise ValueError("unsupported expression") return ev(ast.parse(expr, mode="eval").body) TOOLS = {"lookup_price": lookup_price, "calculator": calculator} def fake_model(goal, history): """A rule-based stand-in for an LLM: reads the goal and what happened so far, returns the next action.""" wanted = re.findall(r"(\d+) (\w+?)s?\b", goal) # [("3", "notebook"), ("2", "pen")] known = {a["args"]["item"]: obs for a, obs in history if a["tool"] == "lookup_price"} for qty, item in wanted: if item not in known: return {"tool": "lookup_price", "args": {"item": item}} if isinstance(known[item], str): return {"final": f"I could not find a price for {item}."} if not any(a["tool"] == "calculator" for a, _ in history): expr = " + ".join(f"{qty}*{known[item]}" for qty, item in wanted) return {"tool": "calculator", "args": {"expr": expr}} return {"final": f"Total: Rs {history[-1][1]}"} def run_agent(goal, max_steps=6): print("GOAL:", goal) history = [] for step in range(1, max_steps + 1): action = fake_model(goal, history) if "final" in action: print(f" step {step}: FINAL -> {action['final']}") return action["final"] tool = TOOLS.get(action["tool"]) obs = tool(**action["args"]) if tool else "error: unknown tool" print(f" step {step}: {action['tool']}({action['args']}) -> {obs}") history.append((action, obs)) print(" stopped: step limit reached") run_agent("What do 3 notebooks and 2 pens cost?") run_agent("What do 2 staplers and 1 pen cost?") run_agent("What does 1 laptop cost?") 

Running it prints this:GOAL: What do 3 notebooks and 2 pens cost? step 1: lookup_price({'item': 'notebook'}) -> 45 step 2: lookup_price({'item': 'pen'}) -> 10 step 3: calculator({'expr': '3*45 + 2*10'}) -> 155 step 4: FINAL -> Total: Rs 155 GOAL: What do 2 staplers and 1 pen cost? step 1: lookup_price({'item': 'stapler'}) -> 120 step 2: lookup_price({'item': 'pen'}) -> 10 step 3: calculator({'expr': '2*120 + 1*10'}) -> 250 step 4: FINAL -> Total: Rs 250 GOAL: What does 1 laptop cost? step 1: lookup_price({'item': 'laptop'}) -> error: no price for laptop step 2: FINAL -> I could not find a price for laptop.

- **Decide:**fake_model returns either a tool call or a final answer.
- **Act and observe:**run_agent runs the tool, prints the result and adds it to history.
- **Handle failure:** for the unknown item the tool returns an error, the model reads it and stops with an honest answer instead of guessing.
- **Stop:**max_steps stops a model that never finishes.

To make it real, swap fake_model for a call to a language model through one of the [free LLM APIs](https://www.masaischool.com/resources/tools/free-llm-apis-for-developers), and describe your tools to the model as functions. Hugging Face's free [AI Agents course](https://huggingface.co/learn/agents-course/unit0/introduction) teaches how to build one with real frameworks.

## Frequently asked questions

### What is an AI agent in simple words?

An AI agent is software that uses an AI model to work toward a goal by itself. It chooses a tool, such as search or running code, uses it, looks at the result and decides what to do next, repeating until the task is done or it must stop and ask you.

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

A chatbot answers one message at a time and you decide what happens next. An agent takes a goal, picks its own steps, uses tools and checks the results. That makes agents more useful for multi-step work and also riskier, because their mistakes can have real effects.

### Is agentic AI the same as an AI agent?

Not exactly. Anthropic uses agentic systems as the umbrella term. It covers workflows, where the steps are fixed in code, and agents, where the model chooses its steps and tools. An AI agent is one kind of agentic system.

### Is Claude Code an AI agent?

Yes. Anthropic describes Claude Code as an agentic coding tool that reads your codebase, edits files and runs commands. Each action is a tool call in a loop. It is not on Claude's Free plan: Pro is $17 a month billed annually, or $20 monthly.

### What is a Claude agent, and where is agent mode?

Claude has no single agent product. The agent-style features on Anthropic's pricing page are Claude Code, Claude in Chrome, and handing off or scheduling tasks, all on paid plans. We found no setting called agent mode on that page, so check which product you are using.

### What are examples of AI agents?

Coding agents such as Claude Code, Codex, Cursor and Google Antigravity, research agents such as Gemini Deep Research, and browser agents such as Claude in Chrome. See the page on agentic AI examples for ten sourced ones across industries.

### Are AI agents safe to use?

They are safe when you limit what they can touch. OWASP lists excessive agency as a core risk: too much functionality, permissions or autonomy. Give least access, require approval for irreversible actions, set a step limit and test before trusting the output.

## Sources checked

- [Workflow vs agent definitions, ground truth, stopping conditions](https://www.anthropic.com/engineering/building-effective-agents)
- [Claude Code description and surfaces](https://code.claude.com/docs/en/overview)
- [Claude plans, Claude Code and Claude in Chrome access](https://claude.com/pricing)
- [Claude in Chrome behaviour and prompt injection warning](https://claude.com/chrome)
- [Codex cloud tasks](https://developers.openai.com/codex/cloud.md)
- [ChatGPT Free and Plus in rupees, Codex access](https://chatgpt.com/pricing/)
- [Antigravity Individuals plan](https://antigravity.google/pricing)
- [Cursor plans and agent access](https://cursor.com/pricing)
- [Copilot plans](https://docs.github.com/en/copilot/get-started/plans)
- [MCP definition](https://modelcontextprotocol.io/docs/getting-started/intro)
- [Excessive agency root causes](https://genai.owasp.org/llmrisk/llm062025-excessive-agency/)
- [Free agents course](https://huggingface.co/learn/agents-course/unit0/introduction)
