PromptisePromptise
Docs
GitHub
Promptise - AI Framework LogoPromptise

The foundation layer for agentic intelligence. Build, secure and operate autonomous AI systems with Promptise Foundry.

pip install promptise

[01] Foundry

  • MCPcast
  • The Promptise Agent
  • Reasoning Engine
  • MCP
  • Agent Runtime
  • Prompt Engineering
  • Execution Engine
  • Agent Identity

[02] Resources

  • Documentation
  • GitHub
  • Guides
  • Learning Paths
  • Questions

[03] Company

  • About
  • Terms of Service
  • Privacy Policy
  • Cookie Policy
  • Subprocessors

© 2026 Promptise by Manser Ventures. All rights reserved.

Open source · Python

← Guides> Building AI agents in Python

What Is an AI Agent? Definition, How It Works, Examples

What an AI agent is: a model that calls tools in a loop until a goal is met. How the loop works, a real example, agents vs chatbots and workflows, FAQs.

Level
Beginner
Reading time
7 min
Published
Oct 18, 2026
Last updated
Oct 18, 2026
By
Promptise Team
  • Agent Loop
  • Tool Calling
Contents · 7 sections↓
  1. 01What is an AI agent?
  2. 02How does an AI agent work?
  3. 03An AI agent example
  4. 04AI agent vs chatbot, workflow and assistant
  5. 05Common misconceptions about AI agents
  6. 06Frequently asked questions
  7. 07Next steps

"AI agent" can mean a chatbot, a workflow tool or a fully autonomous system, depending on who is selling it. This glossary page gives developers a precise definition of an AI agent, shows how the agent loop works, walks through one real run, and compares agents with chatbots, workflows and assistants. At the end you will know what makes a program an agent and where to go to build one.

[01]

What is an AI agent?

An AI agent is a program in which a large language model (LLM) decides, step by step, what to do to reach a goal. It calls tools such as APIs, databases or code, reads each result, and picks the next step until it can answer or hits a limit. The model chooses the actions; your code runs them.

Key takeaways:

  • The loop is what makes it an agent. A single model call is a completion. A model that keeps choosing tools until the task is done is an agent.

  • The model never runs anything. It writes a structured request ("call get_order with A-1042"). Your application executes it and sends back the result.

  • Agents trade control for flexibility. A workflow follows a path you wrote. An agent picks its own path, which handles messy tasks better and fails in less predictable ways.

  • Limits are part of the design. Every agent needs a cap on rounds, time or cost, and a human check before risky actions.

Anthropic's Building effective agents draws the same line: workflows run LLMs and tools "through predefined code paths", while agents are systems where LLMs "dynamically direct their own processes and tool usage". Simon Willison's shorter version is that an LLM agent "runs tools in a loop to achieve a goal".


[02]

How does an AI agent work?

Every agent is built from four parts:

  • A model that reads the conversation and decides the next step.

  • Instructions (the system prompt) that set the goal, the rules and the tone.

  • Tools: functions the model may ask for, each described by a name, a description and a JSON schema for its arguments.

  • A loop in your code that sends the model's tool requests to the right function, adds each result to the conversation, and calls the model again.

Text
1
2
3
4
5
6
7
8
9
10
11
12
13
 user goal
     │
     ▼
┌──────────────┐  "call get_order(A-1042)"  ┌──────────────────┐
│    model     │ ─────────────────────────▶ │ your code runs   │
│ (decides the │                            │ the tool         │
│  next step)  │ ◀───────────────────────── │                  │
└──────────────┘     tool result added      └──────────────────┘
     │                to the conversation
     │  repeats until the model answers,
     │  or a limit (rounds, time, cost) stops it
     ▼
 final answer

Most agents add three more things as they grow. Memory keeps facts across conversations. Retrieval gives the agent a search tool over your documents (see agentic RAG). Guardrails and approvals check inputs, outputs and risky tool calls. The code around the model that handles all of this, from the loop to limits and context management, is often called the agent harness.

The loop pattern is older than today's chat models. The ReAct paper (Yao et al., 2022) showed that interleaving reasoning steps with actions improved results on question answering and interactive tasks. Modern tool calling APIs build that pattern into the model's output format. AI agent reasoning patterns covers ReAct and its successors.


[03]

An AI agent example

Here is a support agent with two tools, built with Promptise Foundry. To answer "When will order A-1042 arrive?" it needs two steps, and only the first result tells it what the second step is.

Pythonagent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import asyncio

from langchain_core.tools import tool
from promptise import build_agent

ORDERS = {"A-1042": {"status": "shipped", "carrier": "UPS", "tracking": "1Z999"}}
TRACKING = {"1Z999": "Out for delivery, expected today by 6 pm"}


@tool
def get_order(order_id: str) -> dict:
    """Look up an order by its ID."""
    return ORDERS.get(order_id, {"error": f"No order {order_id}"})


@tool
def track_package(tracking_number: str) -> str:
    """Get the latest carrier update for a tracking number."""
    return TRACKING.get(tracking_number, "Unknown tracking number")


async def main():
    agent = await build_agent(
        model="openai:gpt-5-mini",
        instructions="You are a support agent. Use your tools, then answer in one sentence.",
        extra_tools=[get_order, track_package],
        max_agent_iterations=10,
    )
    try:
        result = await agent.ainvoke(
            {"messages": [{"role": "user", "content": "When will order A-1042 arrive?"}]}
        )
        for msg in result["messages"][1:]:  # skip the user's message
            for call in getattr(msg, "tool_calls", None) or []:
                print(f"model asks for  {call['name']}({call['args']})")
            if msg.type == "tool":
                print(f"tool returns    {msg.content}")
            elif msg.content:
                print(f"final answer    {msg.content}")
    finally:
        await agent.shutdown()


asyncio.run(main())

Real output from one run with gpt-5-mini:

Output
model asks for  get_order({'order_id': 'A-1042'})
tool returns    {"status": "shipped", "carrier": "UPS", "tracking": "1Z999"}
model asks for  track_package({'tracking_number': '1Z999'})
tool returns    Out for delivery, expected today by 6 pm
final answer    Your order A-1042 is out for delivery and is expected to arrive today by 6 PM.

Nobody told the agent to call track_package. The first tool result contained a tracking number, and the model decided that the next step was to look it up. That decision is what separates an agent from a script. The max_agent_iterations=10 argument is the limit from the diagram: if the model kept calling tools, the run would stop.

The tools here are plain functions. In a real system they would often live in an MCP server, so the same tools work across agents and apps; What is MCP explains how. To build a complete agent step by step, follow How to build an AI agent in Python.


[04]

AI agent vs chatbot, workflow and assistant

Term

Who decides the steps

Uses tools

Example

---|---|---|---

Chatbot

Nobody: one model reply per message

Usually not

A FAQ bot answering from its training data

LLM workflow

You, in code (fixed path)

Yes, at fixed points

Classify a ticket, then route it, then draft a reply

AI assistant

The user, turn by turn

Sometimes

A chat app that searches the web when asked

AI agent

The model, within limits you set

Yes, in a loop

A support agent that looks up an order, tracks it and answers

Multi-agent system

Several agents, one delegating to others

Yes

A coordinator that hands research to one agent and writing to another

The lines blur in products. A chat assistant that calls several tools in a row is running an agent loop inside each turn. A workflow can contain an agent as one of its steps. The useful question is not "is it an agent?" but "who decides the next step, and what stops it?". For several agents working together, see multi-agent systems.


[05]

Common misconceptions about AI agents

"An agent is a smarter model." The model is the same one you use for chat. The agent is the loop, the tools and the limits around it. A better model makes better decisions inside the loop, but it doesn't create the loop.

"Agents work on their own, so you don't need to watch them." Agents get stuck repeating a call, misread a tool result or take an action nobody intended. Production agents need a cap on rounds and cost, traces of every tool call, and a human approval step for actions such as refunds or deletes. AI agent stuck in a loop shows what happens without them.

"More tools make a more capable agent." Each tool's schema is sent to the model on every call. Dozens of similar tools cost tokens and make the model pick the wrong one more often. A few clear tools beat many vague ones.

"Every LLM feature should be an agent." If you can write the steps down in advance, a workflow is cheaper, faster and easier to test. Use an agent when the next step depends on what the previous one found.


[06]

Frequently asked questions

What is an AI agent in simple terms?

An AI agent is a program that uses a language model to decide which actions to take, such as looking up an order or searching documents, and keeps going until the task is done. The model chooses each step, and ordinary code carries it out and reports back what happened.

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

A chatbot answers each message with one model reply. An AI agent can take several actions before it answers: it calls tools, reads their results and decides what to do next. A chatbot that can look things up and act on them, in a loop, is an agent.

Do AI agents run the tools themselves?

No. The model only writes a structured request with a tool name and arguments. Your application, or the agent framework you use, runs the function and sends the result back to the model. That is why you can check, approve or block every action before it happens.

What are examples of AI agents?

Common examples are support agents that look up orders and issue refunds, coding agents that read files, run tests and edit code, research agents that search and summarize sources, and operations agents that check monitoring data and open tickets. Each one combines a model, a few tools and a loop.

Do I need a framework to build an AI agent?

No. A minimal agent loop is about 30 lines of code against a model API. A framework helps once you need tool servers, retries, limits, approvals, tracing and memory, because you would otherwise write and maintain all of that yourself. Python AI agent frameworks compared helps you choose.

Are AI agents safe to use in production?

They can be, with the right controls: least-privilege tools, a cap on rounds and spending, guardrails on inputs and outputs, traces of every call, and human approval for actions that are expensive or hard to undo. Treat every tool result as untrusted input, because it can contain instructions aimed at the model.


[07]

Next steps

  • Build one: How to build an AI agent in Python.

  • Understand the code around the model: What is an agent harness?

  • Give it tools: What is MCP?

  • Keep a human in charge of risky actions: AI agent human in the loop.

  • All guides on the topic: the AI agents hub.

  • Reference: Building agents in the Promptise docs.

Contents

  1. 01What is an AI agent?
  2. 02How does an AI agent work?
  3. 03An AI agent example
  4. 04AI agent vs chatbot, workflow and assistant
  5. 05Common misconceptions about AI agents
  6. 06Frequently asked questions
  7. 07Next steps

Learning paths

Want more structure? Paths put guides in order, like a short course.

See the paths →

> Building AI agents in Python

Related guides

All guides in this topic →
  • // 01Beginner · 20 minHow to Build an AI Agent in Python (2026 Guide)Build an AI agent in Python step by step: write the tool loop, serve tools over MCP, add model fallback, approvals and limits. Runnable code, real output.
  • // 02Intermediate · 18 minWhat Is an Agent Harness? Parts and How to Build OneWhat an agent harness is and how to build one: the tool loop, context compaction, token budgets, loop guards and verification, with runnable code.
  • // 03Intermediate · 24 minSystem Prompt Best Practices for AI Agents in PythonBuild agent system prompts from reusable blocks, switch them by conversation phase, and test them like code. Real Python runs, honest limits.
  • // 04Intermediate · 22 minBest LLM for AI Agents: Test and Switch Models in PythonFind the best LLM for your AI agent with a tool-calling eval, then switch between OpenAI, Anthropic, Azure, Bedrock, Gemini and Ollama in one line.
  • // 05Intermediate · 18 minAI Agent YAML: Define and Run an Agent From a Config FileDefine an AI agent in a YAML file: model, instructions and MCP servers. Validate it, run it from the CLI or Python, keep secrets out, review it in Git.
  • // 06Intermediate · 14 minStreaming LLM Responses with FastAPI: Tokens and Tool CallsStream an AI agent's tool calls and answer from FastAPI to a web page with Server-Sent Events, with cancellation, errors and an EventSource page.

Keep going.

Browse every guide by topic and level, or follow a learning path that puts them in order.

All guidesLearning paths