What Is an AI Agent? LLM, Memory, and Tool Calling Explained
The AI landscape is full of terms — LLMs, context windows, memory, retrieval-augmented generation, tool calling, agents — but they all belong to a single engineering chain. This article walks through each layer: a large language model is fundamentally a very large parameter file that an inference service loads into memory to serve HTTP requests; because inference services are stateless, a model's apparent memory really comes from re-injecting conversation history into the context on every call; short-term and long-term memory decide what enters that context, RAG injects external knowledge, and tool calling lets the model act rather than only talk; and an AI agent is simply the orchestration of these pieces inside a perceive-think-act-observe loop. By the end, readers can map any new term they encounter in the stack to its place on the technical map.
1. Why These Concepts Are So Easy to Confuse
Over the past two years, the vocabulary around large language models has exploded: LLMs, context, memory, retrieval-augmented generation, tool calling, agents… Many developers use AI coding assistants every day and still get tangled up in these names. The root cause is that these concepts were introduced by different teams, in different situations, with no unified view that connects them.
The goal of this article is to build exactly that view: start from the essence of the model at the very bottom, layer by layer upward, and explain the most mystifying concept of all — the “agent” — thoroughly.
2. What a Large Language Model Actually Is: A Very Large File on Disk
Whether it’s a chat-style AI or any other generative application, the core is a large language model. Strip away the mystique and its physical form is actually quite plain: a very large file sitting on disk.
What that file holds are the vast number of parameters the model learned during training (typically hundreds of millions to hundreds of billions of floating-point weights). Left alone, it simply “lies” on disk — it doesn’t move on its own and doesn’t answer anything.
To make it work, you need a program that loads it into memory and exposes an interface (usually HTTP) that receives requests, runs inference, and returns results. That whole package is called an inference service.
Model file on disk ──load──▶ Inference service in memory (HTTP) ──▶ Generated output
Wrap a web chat interface around it, and you get the chat-style AI we all know.
3. Key Prerequisite: Inference Services Are Stateless
To understand everything that follows, you first need to remember one critical fact: inference services are stateless.
This has two implications:
- Each request is processed and then done. The service itself keeps no record of “what we talked about last time”.
- To handle high concurrency, multiple inference service instances are usually deployed behind load balancing. Your first request may land on machine A and your second on machine B — two completely independent processes.
In other words, a model is born with amnesia. So why does it clearly feel like it “remembers” the earlier conversation in a chat box? The secret isn’t in the model; it’s in the input the model receives.
4. Context: What the Model’s “Memory” Really Is
The answer is simple: on every request, the system stitches the previous conversation history back together and sends it to the model along with the new question.
[System prompt] You are a helpful assistant[User] My name is Li[Model] Hello, Li[User] What's my name? <-- the actual question this turn
Seeing this whole stitched-together block, the model naturally picks up the thread. That entire block of content sent to the model is collectively called the context.
A large language model has no memory of its own; its “memory” is entirely reflected in the context. How long the context is and what it contains determine how much the model can “recall” this time.
5. Short-Term and Long-Term Memory: Managing the Context
But a new problem appears right away: if you stuff all conversation history into the context, the length will quickly exceed the model’s context window limit. You can’t process it, and the cost climbs sharply.
So in engineering practice, “memory” is split into two categories to manage:
- Short-term memory: the complete recent turns of the current session, kept as-is to guarantee continuity.
- Long-term memory: information that spans sessions and needs to be retained long-term (user preferences, key facts), filtered and summarized, then recalled on demand rather than injected in full.
def build_context(short_term, long_term, new_query):# Short-term memory: recent turns, concatenated as-isrecent = short_term[-N:] # keep only the last N turns# Long-term memory: recalled by relevance, not injected in fullrecalled = retrieve_relevant(long_term, new_query)# Assemble the final contextreturn SYSTEM_PROMPT + recent + recalled + new_query
This mechanism for managing the context — deciding what to send, what to keep, and what to forget — is called memory. It isn’t an intrinsic capability of the model, but a set of engineering strategies wrapped around it.
6. Retrieval-Augmented Generation (RAG): Letting the Model Read External Knowledge
Besides conversation history, what else can go into the context? This leads to retrieval-augmented generation (RAG).
A model’s parameters are knowledge “frozen” at training time. It cannot know your private data or the latest information in real time. The idea behind RAG is this: before sending the question to the model, first retrieve the most relevant chunks from an external knowledge base (usually a vector store) and stitch them into the context.
User question ──▶ Vectorize ──▶ Query knowledge base ──▶ Insert matched chunks into context ──▶ Model generates answer
This way, the model can “answer while looking at the reference material” without retraining, which both reduces hallucination and supports Q&A over private data. Essentially, RAG solves one problem: what external information belongs in the context.
7. Tool Calling: Letting the Model Do Things Instead of Just Talking
A model that only reads context and generates text is limited in what it can do. Tool calling (also commonly referred to loosely as skills) lets a model trigger external actions: querying databases, calling APIs, performing computations, reading and writing files.
The core mechanism isn’t mysterious: you put a set of descriptions of “available tools” (name, purpose, parameter format) into the context. When the model decides it needs one, it outputs a structured “call request”. An external program actually executes it, then writes the result back into the context so the model can continue reasoning based on that result.
// Example of a tool call request output by the model{"tool": "get_weather","arguments": { "city": "Beijing" }}
Model ──emits call request──▶ External program executes ──writes result back into context──▶ Model answers based on the result
8. Standardized Connection Protocols: Unifying What to Connect and How
As tools and data sources multiply, if every application defines its own integration scheme, you quickly fall into the trap of reinventing the wheel. That’s why the industry has produced standardized model context / tool connection protocols. The goal is to decouple the “model side” from the “tools and data side”: tool providers expose their capabilities according to a common specification, and model application developers consume them the same way, so neither side needs a bespoke integration for every pairing.
The core problem these protocols address is still the familiar one: how to package external capabilities and external data into the context in a way the model can use, reliably.
9. AI Agents: Tying It All Together
At this point, the final piece of the puzzle falls into place. An AI agent is not some new model. It’s an orchestration of the capabilities described above:
- Use an inference service to carry the large language model (the underlying engine);
- Use short-term plus long-term memory to manage the context (memory);
- Use retrieval augmentation to inject external knowledge (RAG);
- Use tool calling and standard connection protocols to link external systems (hands and feet);
- Then wrap a “perceive → think → act → observe” loop around it all, so it can autonomously break down goals and execute in multiple steps.
Goal│┌─────▼─────┐│ Perceive/ │◀──── Observation (results returned by tools/retrieval)│ Plan │└─────┬─────┘│┌─────▼─────┐ calls ┌──────────┐│ Reasoning │─────────▶│ Tools / ││ model │ │ Retrieval │└─────┬─────┘ └──────────┘│ context read/write┌─────▼─────┐│ Memory │└───────────┘
10. Summary: The “Mystery” Is All Just Engineering
Walk the whole chain and one thing becomes clear: those terms that sound profound are actually different stages of the same pipeline.
- Large language model: a parameter file on disk, turned into a usable HTTP capability by an inference service;
- Inference services are stateless, so the model’s “memory” is really the input re-stitched into the context on every call;
- Memory is a context management strategy, RAG solves “which external knowledge to inject”, tool calling solves “what it can do”, and connection protocols solve “how to connect in a standard way”;
- An agent is the orchestration that assembles these pieces into a system capable of an autonomous loop.
Once you grasp this main thread, you can quickly locate any new term on the overall technical map — and that’s the most practical payoff of demystifying the technology.
