The Four Components of an AI Agent, in One Small TypeScript File
Most explanations of AI agents stop at “a model with tools”. That is true, but it doesn't help when your agent forgets a preference, calls the wrong function or loops forever. To debug any of those, you need to know which part is misbehaving. This post continues my series on building agents. The previous one covered LLMs versus agents . The four components of an AI agent An AI agent has four…
The four components of an AI agent are the brain, memory, tools, and action loop. The brain is the language model that decides the next step, while memory holds the conversation history and stored facts. Tools allow the agent to interact with the outside world, and the action loop runs the model, executes tools, and returns results.
The brain is the only model in an AI agent. It receives the system prompt, conversation, tool list, and tool results, and returns text or a request to call a tool. Memory consists of two layers: short-term memory, which is the message history sent with every call, and long-term memory, which is anything written to storage and read back in a later run.
Tools are ordinary functions with a description, name, when to use them, and a JSON Schema for inputs. The model never sees the code, only the description, so it should be written like API documentation for a reader who can't ask questions. The action loop sends memory to the brain, and a tool request runs the tool, appends the result to memory, and repeats the loop. Exits include a final answer, a step cap, unrecoverable failures, and human approval.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.