# How AI Agents Work

By Morgan Linton · Published 2026-03-16 · X No. 8 · 1,278 words · https://blog.morganlinton.com/on-x/how-ai-agents-work/

![](../../assets/on-x/HDirsyNbUAANudR.jpg)

Okay, so I've found myself explaining AI Agents to more people every week. Sometimes it's technical people who want to go deep, and now I'm finding, plenty of times, it's friends and family, who might not be technical, but still want to understand how AI Agents work at a deeper level.

This article is for people that might be a bit in the middle, you're not a software engineer coding every single day, but you're also not completely non-technical.

Oh and before I go any further, if you are a software engineer, and do want to dive deeper into how agents work, I'd suggest probably not reading this, and instead looking at the little open source AI Agent I built, here's the gh repo: [https://github.com/morganlinton/SimpleAgent](https://github.com/morganlinton/SimpleAgent)

Personally, I think, if you know how to code, the best way to learn about things like agents, is to look at the code for a simple agent. But like I said, that's not who this article is meant for. If you're still reading, hopefully that means you're interested in learning more about how AI Agents work under-the-hood, but you're not someone who can just jump into a Github repo.

Since I've been explaining this so much lately, my goal here is to make it easy for everyone, technical or not, to understand how AI Agents work. And also hopefully, now I can point people to this article in the future when they ask me and save us both some time!

Okay, enough preamble, if you're still here, cool - let's dive in. I'm going to cover each core piece in the AI Agent puzzle, starting at the very beginning.

## Tool Definitions & Schemas

Before an AI Agent can do anything, it needs to know what tools it has. This is what tool definitions are for, they let the agent know, before it starts answering questions or running an agentic task, what kind of super powers it has.

It's important to note, this is different from what the model was trained on and already knows. A good example is - a basic LLM might know simple things, but once you ask it for say, the weather in Berkeley, CA, it has no idea.

And when models have no idea - they guess. We all have seen what happens when models guess, they hallucinate, and the answers often don't make a ton of sense. Tools allow models to take questions that they'd normally need to guess the answer, when answering, and gives them a way to actually answer them accurately.

A tool definition usually has three core parts:

1. Name - what's the tool called?
2. Description - a short description of what the tool does and when to use it

3. Parameter schema - what inputs to send the tool

Here's an example of a simple tool definition for a tool that helps an agent find the weather.

```json
{
  "name": "get_weather",
  "description": "Returns the current weather for a given city. Use this when the user asks about weather conditions.",
  "input_schema": {
    "type": "object",
    "properties": {
      "city": {
        "type": "string",
        "description": "The name of the city, e.g. 'Berkeley'"
      },
      "units": {
        "type": "string",
        "enum": ["celsius", "fahrenheit"],
        "description": "Temperature units to return"
      }
    },
    "required": ["city"]
  }
}
```

The important thing to understand about tool definitions is that they are passed to the model with every request along with the conversation.

But, and this is an important but, the model does not have to access the code for the tool, just the schema. It just needs to know it exists and when to use it.

## Tool Call/LLM Request Cycle

Okay, so the model know the tool exists, now it needs to be able to use it. I'm getting ready to grab a Gordo burrito and then a hike in Tilden, now I really do need to know the weather in Berkeley.

**Step 1 — The Request**

Your application sends a request to the LLM. This request contains:

1. The system prompt (instructions about how the model should behave)
2. The conversation history (prior messages)

3. The tool definitions (the schemas from Part 1)
4. The user's latest message

**Step 2 — The Model Decides**

Now, it's the moment of truth, the model has to decide, can it answer this accurately without a tool, or would a tool make a difference?

If it decides to use a tool, it doesn't actually *call* anything yet. Instead, it returns a structured **tool call** object, essentially the model saying "I want to run this tool with these arguments" - here's an example:

```json
{
  "type": "tool_use",
  "name": "get_weather",
  "input": {
    "city": "Berkeley",
    "units": "fahrenheit"
  }
}
```

Now this is where I find a lot of people get confused, and I get it, it's a little confusing. The model isn't actually running any code or making network requests at this point. It just creates this text, in JSON usually, describing what it wants to do.

## The Agent Runtime & Orchestration Loop

Now here's where things get interesting. A single tool call is neat, but what makes something a true **agent** is the ability to chain multiple steps together, i.e. planning, acting, observing results, and deciding what to do next.

This is handled by the **agent loop**, sometimes called the orchestration loop.

```typescript
while not done:
    response = call_llm(conversation_history, tools)

    if response is final answer:
        return response

    if response contains tool_calls:
        for each tool_call:
            result = execute(tool_call)
            append result to conversation_history

        continue loop
```

The loop keeps running, calling the model, executing tools, feeding results back, until the model produces a response with no tool calls, signaling that it's done.

What makes this powerful is that the model can adapt mid-task. If it calls a search tool and the results suck, it might call a different tool, refine its query, or ask the user for clarification. The conversation history accumulates all of this context, and the model reasons over the full picture each time.

Okay, but let's talk about memory, because everyone has experienced those weird moments where their trusty agent seems to have amnesia.

Each call to the LLM is stateless, i.e. the model has no memory between calls on its own. It's the runtime that is responsible for maintaining the conversation thread and passing it in full with every request. As agent tasks grow longer, this history can get large, and production runtimes often have to manage context window limits, summarize older steps, or use external memory stores.

This is also why frontier model companies are always increasing their context window, it makes life easier for the runtime, and helps your little AI Agent buddy remember more.

## Real API Execution & the HTTP Layer

Now we're at my personal favorite part - this is where the action happens. When a tool actually runs, it typically does one of a few things: calls an external API, reads/writes to a database, executes code, or interacts with a filesystem.

As a simple(ish) example - here's what happens at the HTTP layer for a typical API call.

```python
def get_weather(city: str, units: str = "celsius") -> dict:
    response = requests.get(
        "https://api.weather.com/v1/current",
        params={"q": city, "units": units},
        headers={"Authorization": f"Bearer {API_KEY}"}
    )
    response.raise_for_status()
    return response.json()
```

Don't worry if you don't understand the code above. This is just normal application code, in this case, a simple Python function that calls a weather API and gets the weather.

The key concept to understand here is that it's in this execution layer that your tool actually performs the function it's designed to do.

Once it runs, the results are fed back to the model which will reason over them, and decide if it needs to call more tools, or if it's ready to return the response to the user.

The orchestration loop is what repeats this cycle until the task is complete.

And that's it, fin - done. If you read all of this, you now know how an AI Agent works. Thanks for reading!
