A beginner-friendly, open-source tutorial. No frameworks. No fluff. Just PHP doing cool AI things.
An AI agent is a program that can perceive a task, think using an AI model like Claude, and act — respond, calculate, search, or call other agents.
Think of it like a smart employee. You assign it work. It figures out how to do it.
| STEP | WHAT HAPPENS |
|---|---|
| 1. Perceive | Receives a task or question from the user |
| 2. Think | Sends the task to Claude API for reasoning |
| 3. Act | Returns an answer, uses a tool, or calls another agent |
Install PHP or use XAMPP / WAMP locally
Free at console.anthropic.com
Comes with PHP by default. Just check php.ini
CMD, Terminal, or any shell will do
Set your API key as an environment variable:
Never hardcode your API key directly in PHP files. Always use environment variables or a .env file that's listed in .gitignore.
The simplest agent: send a question to Claude, get an answer back. This is the foundation of everything.
Challenge: Change the question on the last line. Try: "What is SQL injection in simple terms?"
Real agents use tools. We give this agent a calculator and a date checker. Claude decides on its own which tool to use.
| TOOL | WHAT IT DOES |
|---|---|
| 🔢 calculator | Evaluates a math expression safely |
| 📅 get_current_date | Returns today's date |
Challenge: Add a word_counter($text) tool that returns the number of words in a sentence!
Multiple specialized agents collaborate. A Coordinator reads each task and delegates to the right expert. This is the architecture behind MoltFlask.
| AGENT | SPECIALTY |
|---|---|
| 🎯 Coordinator | Routes tasks to the right specialist |
| 🔐 Security Agent | Cybersecurity questions |
| 📊 Data Agent | Data analysis questions |
| ✍️ Writer Agent | Writing and summaries |
Challenge: Add a teacher_agent() that explains topics like a patient professor. Then add it to the coordinator's routing!
This multi-agent architecture is the foundation of MoltFlask 2 — a cloud-deployed AI agent social network security research platform. Read the paper →
| CONCEPT | SIMPLE MEANING |
|---|---|
| Agent | A program that receives tasks and uses AI to complete them |
| Tool | A PHP function the agent can call to do real-world actions |
| Coordinator | An agent that reads and delegates tasks to specialists |
| Multi-agent system | Multiple agents working together, each with a specialty |
| Agent loop | The cycle: receive → think → act → respond |
| cURL | PHP's built-in tool for making HTTP requests (how we call Claude) |