Skip to content
AI Playbooks · 9 min read

AI Agents Playbook: How Agents Work and How to Build Your First One (2026)

AI agents playbook for beginners: learn how agents work, build a minimal agent loop, add tools, memory and guardrails, and handle long waits.

AI agents playbook: CodeSpy AI Playbook cover explaining how AI agents work

Meera works as a developer in Pune. Last Monday her manager walked over and said, “Can we build an AI agent for order support?” Meera smiled and said yes. Then she went back to her desk and quietly searched, “what is an AI agent?”

She found fifty articles. Every one of them used words she did not know. If that sounds like you, this AI agents playbook is for you. We will follow Meera through her week, and by Friday you will understand what an agent is, how it works, and how to build a safe one. No jargon without a plain explanation first.

Last verified: 27 October 2026. AI tools change fast; check the linked sources for anything newer.

Who this playbook is for: anyone who can read a little code and has chatted with an AI tool, but has never built an agent. You do not need to know anything else. Time needed: about 45 minutes.

What is an AI agent? Think of a new colleague

Imagine you ask a chatbot, “Where is order 4412?” It can only guess, because it cannot look anything up. It answers once and stops.

Now imagine you ask a new colleague the same thing. They open the order system, find the courier, check the tracking page, and then tell you, “It is stuck at the Pune hub, it will arrive tomorrow.” They did several small steps to get you an answer.

That is an AI agent. It is an AI that does not just talk. It takes steps, uses tools, looks at what happened, and decides what to do next until the job is done.

Why agents are everywhere right now

Companies want AI that finishes tasks, not just answers questions. That is why most new AI tools this month are about agents. For example, AWS and UC Berkeley just released Infinity, a tool for running huge numbers of agents. You do not need to follow every launch. If you understand the basics below, every new tool will make sense.

The playbook at a glance

  1. Meet the four parts of an agent
  2. See the loop that makes it work
  3. Give it tools, carefully
  4. Help it remember without getting overloaded
  5. Let it wait without wasting resources
  6. Test it before customers do

Play 1: Meet the four parts of an agent

On Monday evening Meera drew four boxes on a sheet of paper. Every agent, big or small, has these four parts.

  • The brain. This is the AI model, also called an LLM (large language model). It reads the situation and decides what to do next. It can only think and write. It has no hands.
  • The hands (tools). These are normal functions your team writes, like “look up an order” or “send an email”. The brain asks, and your code does the work.
  • The notebook (memory). The conversation so far. The brain forgets everything between turns, so we hand it the notebook every time.
  • The routine (loop). Think, act, look at the result, repeat. We build this part ourselves.

You are done when you can explain these four boxes to a friend using the new colleague example.

Play 2: See the loop that makes it work

On Tuesday Meera looked at the routine. It is shorter than she expected. Here it is in plain steps:

  1. Give the brain the goal: “Where is order 4412?”
  2. The brain says, “Please run the tool get_order_status for 4412.”
  3. Your code runs the tool and writes the result in the notebook: “shipped, at the Pune hub.”
  4. The brain reads the notebook and answers: “Your order is at the Pune hub and arrives tomorrow.”

As code, it looks like this. The function call_model stands for whichever AI service you use; each service has its own format, so treat this as a picture of the idea.

def run_agent(goal, call_model, tools, max_steps=8):
    notebook = [goal]
    for step in range(max_steps):
        reply = call_model(notebook)          # the brain thinks
        if reply.wants_tool:
            result = tools[reply.tool](**reply.arguments)   # the hands act
            notebook.append(result)           # write it down
        else:
            return reply.text                 # the brain is done
    return "Stopped: too many steps"

Notice max_steps. It is a safety net. If the brain gets confused and keeps going in circles, the loop stops anyway. If you use Java, our Spring AI agent tutorial builds the same loop with a framework.

You are done when you can point at the line where the agent decides it has finished.

Play 3: Give it tools, carefully

On Wednesday Meera wanted to give her agent a “refund customer” tool. Her senior colleague Arjun stopped her. “Would you give a new joiner the refund button on day one?” he asked. Meera laughed and said no.

That is the rule for tools. Start with tools that only look, and add tools that change things later.

  1. Give every tool a clear name and one sentence saying what it does. The brain picks tools by reading these.
  2. Always check what the brain sends to a tool. It can make mistakes, just like a person typing in a hurry.
  3. Start with look-only tools, like checking an order. Add risky tools like refunds only after approval is in place.

For a worked example, see Spring AI function calling. When many apps need the same tools, a standard called MCP lets them share, explained in building an MCP server with Spring AI.

You are done when every tool is labelled “look only” or “changes things”.

Play 4: Help it remember without getting overloaded

Here is something that surprised Meera. The brain has no memory. Every time it is called, it only knows what is in the notebook you hand it. If the notebook grows to a hundred pages, it becomes slow, expensive and confusing, like asking someone to read a whole novel before answering a simple question.

  • Keep the notebook short. Remove old details and summarise long parts.
  • Keep big knowledge in a cupboard. Company documents and past cases live outside the notebook. The agent fetches only the page it needs. This idea is called RAG, and our first RAG app guide explains it step by step.

You are done when you know roughly how long your notebook is on the first turn and the eighth turn, and you have a rule for trimming it.

Play 5: Let it wait without wasting resources

On Thursday a real problem appeared. Some refunds need a manager’s approval, and managers take hours or even days. If the agent just sits and waits, it holds on to memory and a connection the whole time. Multiply that by thousands of customers and the bill grows for nothing.

Think of a restaurant waiter. A good waiter takes your order, goes to the kitchen, and serves other tables. They do not stand next to the stove until your dish is ready. When the food is ready, someone calls them back.

Agents can work the same way. Save the notebook, let the agent go to sleep, and wake it up when the answer arrives. The new AWS tool Infinity does exactly this. AWS says a sleeping agent takes about 100 KB, so around 75,000 of them fit in 8 GB of memory. AWS also says Infinity is an early research release, not a finished product. For you, the lesson matters more than the tool: a waiting agent should cost almost nothing.

  1. Find the tools that can take a long time, such as approvals.
  2. Split each into two steps: “ask” (answers immediately with a ticket number) and “result arrives” (comes back later).
  3. Make sure the same result arriving twice does no harm. Messages sometimes get delivered twice.

You are done when every slow tool has an “ask” step and a “result arrives” step.

Play 6: Test it before customers do

On Friday Meera wrote twenty sample questions with the right answers, including awkward ones like “Where is my order?” with no order number. She ran them every time she changed something. This habit is called an eval, and it is what separates a demo from something you can trust.

  1. Write 20 questions and the answers you expect.
  2. Run them after every change and count how many pass.
  3. Set limits: a maximum number of steps, a time limit, and a spending limit per task.
  4. Keep a log of every tool the agent used, so you can replay what happened.

You are done when you can re-run your twenty questions in one click and see a pass rate.

Do you even need an agent?

Often, no. Pick the simplest option that works.

Your taskUse thisWhy
One question, one answerA single AI callNothing more is needed
The steps are always the sameA fixed workflow that uses AI in some stepsCheaper and more predictable
The steps change each timeAn agentThe AI chooses what to do next
Thousands of agents waiting for daysAn agent on a tool like InfinitySleeping agents cost almost nothing

Mistakes to avoid

  • Using an agent for everything. A simple workflow is easier to trust.
  • No step limit. A confused agent can loop and burn money.
  • Trusting what the brain sends to tools. Always check it.
  • Giving risky tools on day one. Start look-only.
  • Skipping tests. Without a test list you cannot tell if a change helped or hurt.

How to know it is working

  • How many of your test questions pass.
  • How many steps and how much money a typical task needs. The Gemini 4 Argon cost playbook shows how to work out cost.
  • How often a human has to fix the agent’s work.

Your checklist

  • ☐ I can explain brain, hands, notebook and routine
  • ☐ I have run a small agent loop
  • ☐ Every tool is labelled look-only or changes things
  • ☐ I have a rule for keeping the notebook short
  • ☐ Slow tools have an ask step and a result step
  • ☐ I have twenty test questions and a step limit

Frequently asked questions

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

A chatbot answers one message. An agent works toward a goal in several steps, using tools along the way.

Do I need a framework?

No. The loop above is plain code. Frameworks like Spring AI save effort later, and they are easier to use once you understand the loop.

Which programming language should I use?

Use the one you already know. Java developers can start with our Spring AI getting started guide.

Do I need to learn AWS Infinity?

Not as a beginner. It matters when you run a very large number of agents that wait a long time. It is also an early research release.

Are AI agents safe to use at work?

They can be, if you add limits: look-only tools first, human approval for risky actions, checks on inputs, step limits, logs and a test list.

What Meera did next

By Friday evening Meera had a small agent that could check an order, a step limit, and twenty test questions. She told her manager honestly what it could and could not do, and that refunds would wait until approval was ready. Her manager said, “That is exactly what I wanted.” Your turn: build the small loop from Play 2 with one tool of your own today.

Sources: AWS Open Source Blog, Introducing Infinity (23 October 2026); Infinity project site. Keep learning: building an MCP client with Spring AI.

Leave a Reply

Your email address will not be published. Required fields are marked *

Newsletter

Get the next guide before anyone else.

One email a week with new playbooks and tutorials. No spam, unsubscribe anytime.