็ฆป็บฟ่ตๆ ยท 01-ai-agent-handbook/en/chapters/01-fundamentals.html
In this chapter, you'll understand what an AI Agent is, why it matters, and how it fundamentally works.
Traditional LLM call:
User question โ LLM processes โ Return answer
AI Agent:
User goal โ [Perceive โ Decide โ Act โ Observe] loop โ Goal achieved
โ
Call tools / Query memory / Collaborate with other Agents
A complete Agent = LLM + Persona + Tools + Memory + Decision Logic
| Component | Role | Analogy |
|---|---|---|
| LLM (Brain) | Understand, reason, generate | Human brain |
| Persona | Defines domain expertise and behavior | Professional identity |
| Tools | External capabilities (search, compute, databases) | Hands and tools |
| Memory | Short-term conversation + long-term knowledge | Memory system |
| Decision Logic | Rules that determine the next action | Decision center |
At its core, an Agent is a while loop that repeatedly executes these steps:
def agent_loop(user_goal: str, tools: dict, max_steps: int = 10):
messages = [{"role": "system", "content": build_system_prompt(tools)}]
messages.append({"role": "user", "content": user_goal})
for step in range(max_steps):
# 1. Perceive: call the LLM to get a response
response = call_llm(messages)
messages.append({"role": "assistant", "content": response})
# 2. Parse: check whether a tool needs to be called
action = parse_action(response)
if action is None:
# No tool call, return the final answer
return response["content"]
# 3. Act: execute the tool call
tool_result = execute_tool(action.name, action.parameters)
messages.append({
"role": "tool",
"tool_call_id": action.id,
"content": tool_result
})
# 4. Observe: the LLM continues reasoning based on tool results
return "Task timeout, please simplify your request"
ReAct = Reasoning + Acting
Thought: I need to check the weather first, then calculate the travel budget
Action: get_weather(city="Beijing")
Observation: Beijing is sunny today, 25ยฐC
Thought: The weather is great, I can continue planning the itinerary...
Action: calculate_budget(days=3, location="Beijing")
...
Final Answer: A 3-day Beijing trip budget is approximately 5000 RMB
| Problem | Example |
|---|---|
| Knowledge cutoff | LLM training data has a cutoff date |
| Factual accuracy | Prone to hallucination |
| Complex tasks | Tasks requiring multi-step reasoning and tool calls |
| Personalization | Cannot remember user preferences and history |
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Traditional LLM โ
โ Q&A โ Generate โ Done โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ AI Agent โ
โ Understand goal โ Plan โ Execute โ Verify โ Adjust
โ โ โ
โ โโโ Loop and optimize until success โโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
User โ [Agent A] โ Result
Pros: Simple, fast, low cost Cons: Struggles with complex tasks, easy to drift off target
โโโโโโโโโโโโโโโโ
โ Supervisor โ
โโโโโโโโฌโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโ
โ โ โ
โโโโโโโผโโโโโโ โโโโโโโผโโโโโโ โโโโโโโผโโโโโโ
โ Research โ โ Writer โ โ Reviewer โ
โ Agent โ โ Agent โ โ Agent โ
โโโโโโโโโโโโโ โโโโโโโโโโโโโ โโโโโโโโโโโโโ
Pros: Specialized division of labor, parallel execution, easier debugging Cons: High coordination complexity, more token consumption
| Term | Definition |
|---|---|
| Agent | An LLM entity with perceive-decide-act capabilities |
| Tool Calling | The Agent's ability to call external tools |
| Function Calling | Interacting with external tools via function call interfaces |
| RAG | Retrieval-Augmented Generation |
| Orchestration | Controlling execution order and data flow of multiple agents |
| Handoff | One agent transfers control to another agent |
| MCP | Model Context Protocol, standardized AI tool protocol |
| A2A | Agent-to-Agent Protocol, inter-agent communication protocol |
| Checkpointer | Saves agent state for resumable execution |
| HITL | Human-in-the-Loop, human review mechanism |
โณ English translation of Chapter 2 is in progress. Read the Chinese original: Chapter 2 ยท Build a ReAct Agent from Scratch, or check the Translation Status.