AI Agents in Production · Lesson 2 of 14 · 2 min read · 6 min video
Agent architecture: loop, tools, memory, planner
The four parts inside every agent, and how a request flows through them.
📄 Download slides (PDF)Every agent, whatever framework you use, has the same four parts. Learn them once and every framework becomes easy to read.
The four parts
- The loop: call the model, run any tool it asks for, feed the result back, and repeat until it gives a final answer
- Tools: functions the model can call: search orders, send an email, query a database
- Memory: what the agent knows: the conversation so far, plus facts saved from earlier sessions
- Planner: how it decides the next step. Often it's just the model thinking step by step; sometimes it writes an explicit plan first
The loop in code
def run_agent(task, tools, max_steps=10):
messages = [{"role": "user", "content": task}]
for step in range(max_steps):
reply = call_llm(messages, tools=tools)
if reply.tool_call is None:
return reply.text # final answer
result = tools[reply.tool_call.name](**reply.tool_call.args)
messages.append(reply.as_message())
messages.append(tool_result(reply.tool_call.id, result))
raise StepLimitReached(task)That's the whole engine. Notice max_steps: without it, a confused agent can loop forever and burn your budget.
Following one request
A customer asks a Vizag bakery's agent: "Where's my cake order?"
- The model sees the question and the tool list, and calls find_order(phone)
- Your code runs it, and the tool returns "out for delivery, ETA 6 pm"
- The model reads that and writes the answer
- The loop ends because there's no tool call
Workflow or agent?
If the steps are always the same, don't use an agent. Write a fixed workflow and use the LLM only where judgement is needed. Use an agent when the path really depends on what it finds. Fixed workflows are cheaper, faster and easier to test.
In one line
An agent is a loop: the model picks a tool, your code runs it, the result goes back, and a step limit keeps it from running forever.
Share with a friend