ChatGPT answers your questions. An AI Agent gets things done."
š Table of Contents
The Problem with Regular AI
What is an AI Agent?
How Does it Work?
Real-World Examples
Build Your First Agent
Should You Be Worried?
The Problem with Regular AI
You've probably used ChatGPT or a similar AI tool. You ask it something, it answers. Done.
But what if you need it to:
Search the web for you š
Send an email on your behalf š§
Book a meeting automatically š
Write code AND run it AND fix the bugs š»
A regular AI can't do that. It just talks. It doesn't act.
That's where AI Agents come in.
What is an AI Agent?
An AI Agent is an AI system that can perceive its environment, make decisions, and take actions to achieve a goal ā without needing you to guide every step.
Think of it like this:
Regular AI (ChatGPT)
AI Agent
š£ļø You ask
"Write me an email"
"Handle my inbox today"
š§ It thinks
Once
Repeatedly, in a loop
š¬ It acts
Just responds with text
Reads emails, writes replies, sends them
š It loops
No
Yes ā until the goal is done
Simple analogy: ChatGPT is like a very smart advisor. An AI Agent is like a very smart employee.
How Does it Work?
Every AI Agent follows a simple loop called Observe ā Think ā Act:
š OBSERVE ā
ā (Read the environment) ā
ā ā ā
ā š§ THINK ā
ā (Decide what to do next) ā
ā ā ā
ā š¬ ACT ā
ā (Use a tool or take a step) ā
ā ā ā
ā š REPEAT until goal is done ā
ā ā
āāāāāāāāāāāāāāāāāāāāāāāāā
The 3 Key Ingredients of an AI Agent
- š§ A Brain (LLM) The core thinking engine ā usually GPT-4, Claude, or Gemini. It decides what to do.
- š ļø Tools Things the agent can use to interact with the world: Web search Code execution Sending emails Reading files Calling APIs
- š¾ Memory The agent remembers what it has done so far, so it doesn't repeat itself or lose track of the goal. Real-World Examples š Example 1: Shopping Agent You say: "Find me the cheapest laptop under $800 with good reviews." The agent: Searches Amazon, Best Buy, Newegg Compares prices and ratings Returns the top 3 options with a summary You didn't tell it how to search. It figured it out. š» Example 2: Coding Agent You say: "Build me a to-do app in React." The agent: Writes the code Runs it Sees the error Fixes the error Runs it again Delivers working code ā This is exactly what tools like Cursor and GitHub Copilot Workspace do today. š§ Example 3: Email Agent You say: "Reply to all unread emails that are asking about pricing." The agent: Reads your inbox Finds relevant emails Drafts personalized replies Sends them (or asks for your approval first) Build Your First Agent Let's build a tiny AI Agent in JavaScript using the Anthropic API. This agent will think step by step and use a tool (a calculator). const Anthropic = require("@anthropic-ai/sdk");
const client = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
// š ļø Define the tools our agent can use
const tools = [
{
name: "calculate",
description: "Perform a math calculation",
input_schema: {
type: "object",
properties: {
expression: {
type: "string",
description: "The math expression to evaluate. e.g. '2 + 2'",
},
},
required: ["expression"],
},
},
];
// š¬ The tool execution function
function executeTool(name, input) {
if (name === "calculate") {
try {
const result = eval(input.expression); // Simple eval for demo
return String(result);
} catch {
return "Error: Invalid expression";
}
}
}
// š The Agent Loop
async function runAgent(userMessage) {
console.log(\nš¤ User: ${userMessage}\n);
const messages = [{ role: "user", content: userMessage }];
while (true) {
const response = await client.messages.create({
model: "claude-opus-4-5",
max_tokens: 1024,
tools: tools,
messages: messages,
});
// š§ Agent is thinking and responding
for (const block of response.content) {
if (block.type === "text") {
console.log(`š¤ Agent: ${block.text}`);
}
// š ļø Agent wants to use a tool
if (block.type === "tool_use") {
console.log(`š§ Using tool: ${block.name}`);
console.log(` Input: ${JSON.stringify(block.input)}`);
const toolResult = executeTool(block.name, block.input);
console.log(` Result: ${toolResult}`);
// Add the tool result back to the conversation
messages.push({ role: "assistant", content: response.content });
messages.push({
role: "user",
content: [
{
type: "tool_result",
tool_use_id: block.id,
content: toolResult,
},
],
});
}
}
// ā
Agent is done
if (response.stop_reason === "end_turn") {
break;
}
// š Agent needs to keep going (used a tool)
if (response.stop_reason !== "tool_use") {
break;
}
}
}
// š Run it!
runAgent("What is (123 * 456) + (789 / 3)?");
Output
š¤ User: What is (123 * 456) + (789 / 3)?
š§ Using tool: calculate
Input: {"expression": "123 * 456"}
Result: 56088
š§ Using tool: calculate
Input: {"expression": "789 / 3"}
Result: 263
š§ Using tool: calculate
Input: {"expression": "56088 + 263"}
Result: 56351
š¤ Agent: The result is 56,351.
Notice how the agent broke the problem into steps and used the tool multiple times ā all by itself. That's the loop in action.
Should You Be Worried?
AI Agents are powerful, but they come with real concerns:
ā
The Good
ā ļø The Risk
Automate boring tasks
Can make mistakes autonomously
Work 24/7 without breaks
Needs careful permission control
Handle complex workflows
Can be expensive if loops go wrong
Free you to do creative work
Still needs human oversight
The golden rule: Always add a human-in-the-loop for important decisions. Don't let your agent send 500 emails without your review first. š
Summary
Regular AI = Talks. AI Agent = Acts.
Every agent follows: Observe ā Think ā Act ā Repeat
An agent needs: a brain (LLM) + tools + memory
They're already being used in coding, email, shopping, and more
Powerful but needs human oversight
šÆ Quick Challenge
Looking at the code above ā can you add a second tool called "reverse_string" that reverses any text the agent passes to it?
Drop your solution in the comments! š
Follow for Part 2: Building a Full AI Agent that browses the web š
Top comments (0)