惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Microsoft Azure Blog
Microsoft Azure Blog
aimingoo的专栏
aimingoo的专栏
Vercel News
Vercel News
U
Unit 42
L
LangChain Blog
J
Java Code Geeks
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Cloudflare Blog
F
Fortinet All Blogs
小众软件
小众软件
I
InfoQ
P
Proofpoint News Feed
D
DataBreaches.Net
Martin Fowler
Martin Fowler
H
Help Net Security
T
Tailwind CSS Blog
N
Netflix TechBlog - Medium
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
B
Blog RSS Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
B
Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
🤖 What is an AI Agent? A Beginner's Guide to the Future o...
Rachef Khoul · 2026-05-10 · via DEV Community

Rachef Khoulod

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

  1. 🧠 A Brain (LLM) The core thinking engine — usually GPT-4, Claude, or Gemini. It decides what to do.
  2. 🛠️ Tools Things the agent can use to interact with the world: Web search Code execution Sending emails Reading files Calling APIs
  3. 💾 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;
}

Enter fullscreen mode Exit fullscreen mode

}
}

// 🚀 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 🌐

ai #javascript #beginners #webdev