Week 8 · Capstone
Agentic AI
LLMs that can reason, use tools, and act. The capstone that ties everything together.
Pause & reflect
Before you read on, answer this in your head — or on paper:
Imagine an LLM that can search the web, run code, and read files. It decides what to do, does it, then decides again.
What could go wrong? What must you design for? Think about failure modes — infinite loops, wrong tool choice, bad tool output, cost.
An agent is an LLM plus a loop: plan → act → observe → repeat. It can call tools (APIs, code execution, search, file ops), interpret results, and decide the next step. It stops when the task is done or a limit is reached. Cursor and Claude Code are examples. The LLM Engineer's Handbook builds an LLM Twin — an AI that learns to write like a specific person — as its end-to-end project; agents are the culmination of that pipeline.
The agent loop
Plan
LLM decides: which tool to call, with what arguments. Or: generate final answer.
Act
Execute the tool. Call API, run code, query DB, search the web.
Observe
Add tool output to the conversation. LLM sees the result.
Repeat or halt
If task done → return answer. Else → plan again. Max steps to avoid infinite loops.
What goes into Week 8
Everything you've learned
Prompting — System prompt defines the agent's role and tool-use behaviour. APIs — Call LLMs. RAG — Retrieve context for tools. Fine-tuning — Optional custom model. All feed into one autonomous system.
Tools in practice
Typical tools: web search, code execution, file read/write, database queries, external APIs. The agent chooses which to call based on the user's goal. Frameworks like LangChain, CrewAI, or raw OpenAI function-calling implement the loop.
Tool definition (OpenAI-style)
{
"name": "search_web",
"description": "Search the web for current information",
"parameters": {
"type": "object",
"properties": {
"query": { "type": "string", "description": "Search query" }
},
"required": ["query"]
}
}The LLM receives tool definitions and can request a call with arguments. Your code runs the tool and returns the result to the model.
Tool design tips
- Clear descriptions — the LLM chooses tools by reading them.
- Small, focused tools — one tool, one job. Easier for the model to use correctly.
- Structured outputs — return JSON so the agent can parse and act.
- Error handling — tools can fail; tell the agent what went wrong.
Test your understanding
Don't reveal yet. Think for ~30 seconds first — what would you try?
The agent keeps calling the same failing tool in a loop. What could you add to fix this?
Check your understanding
What distinguishes an agent from a simple LLM chat?
Why does the course put Agentic AI in Week 8?
Why do agents need max-step limits?