中文版: AI 学习路线图 08 · 智能体开发
08 · AI Agents
The AI Learning Roadmap · Stage 8 of 9
Why This Stage Matters
Everything so far has been conversational: you send a request, the model answers. An agent is the step beyond: a system that pursues a goal — planning steps, calling tools, checking results, remembering state, and looping until the task is done. Instead of "write me a summary," an agent can "research this topic, draft a report, save it to my drive, and email me when it's ready."
This is where the field is headed — every major lab frames its frontier products in agentic terms — and it is the highest-leverage skill in applied AI right now. The good news: you already have every ingredient. From Stage 7 you have function calling, orchestration, and evaluation. This stage assembles them into the loop and teaches you the two things that separate working agents from demos: memory and reliability.
Core Concepts
1. The agent paradigm
An agent is an LLM inside a loop:
┌────────────────────────────────────────────┐
│ ▼
Goal ──► Reason: what should I do next? ──► Act: call a tool / write
▲ │
│ ▼
└──── Observe: what did the result tell me? ◄── (result returns)
The difference from a chatbot:
- Stateful — the agent maintains context across many steps (conversation history, intermediate results, todo list).
- Multi-step — a single request triggers many model calls and tool calls, chained.
- Goal-directed — the loop continues until the goal is achieved or a stopping condition fires.
- Fallible and recoverable — a failed tool call is an observation, not the end.
2. Planning — how agents decide
- ReAct (Reason + Act) — the foundational pattern: interleave thought ("I need the current price, so I'll call the price tool"), action (tool call), and observation (result), feeding each back. Reasoning and acting reinforce each other. Almost every modern agent is ReAct with better packaging.
- Task decomposition — break a big goal into subtasks (a research task → outline → search queries → per-section drafting → assembly). Explicit plans (a todo list the model maintains and updates) beat implicit ones.
- Reflection — after producing something, the agent critiques its own output and improves it ("is this report complete? what's missing?"). Cheap and surprisingly effective — often the single biggest quality lever.
- Plan-and-execute vs. interleaved — write the whole plan upfront, then execute (efficient but brittle: plans drift); or plan one step at a time (flexible, more calls). Modern practice: start with a light plan, re-plan as observations arrive.
- The failure mode to know: agents drift — they start aligned with the goal and slowly wander. Mitigations: keep the original goal visible in context, checkpoints, and explicit "am I still on task?" reflection.
3. Tools — the agent's hands
Tools are function calling (Stage 7) at loop scale. The design rules compound here:
- Narrow, well-described tools — the description is how the model decides; ambiguous tools → wrong choices.
- Failure as data — a tool that returns an error should return a structured message the model can act on ("rate limited, retry in 60s"), not crash the loop.
- Permission boundaries — destructive tools (send, delete, pay) need confirmation or dry-run modes. The agent can propose; a human approves the irreversible.
- Tool sprawl is real — each added tool degrades selection accuracy; 5–10 excellent tools beat 50 mediocre ones.
4. Memory — short-term and long-term
Chatbots forget; agents must remember.
- Short-term memory — the conversation/context window. It is the agent's working memory and its constraint: finite, and expensive. Context management is a core engineering skill: trim old turns, summarize what's done, keep the goal pinned, drop what's no longer needed.
- Long-term memory — survives across sessions: a vector store of past facts and documents (retrieve relevant memory when needed — this is RAG applied to the agent's own history), plus structured stores (profiles, todo state, notes).
- Memory management patterns — summarization (compress history when the window fills), retrieval (pull relevant memory on demand), and structured state (keep critical facts in a schema the agent can query, not buried in prose).
5. Multi-agent systems
Two or more specialized agents collaborating. The patterns:
- Supervisor/worker — one agent plans and delegates; workers execute subtasks and report back. The most common and most controllable.
- Handoffs — pass the conversation to whoever is best suited (a triage agent → a billing agent). Common in customer support.
- Debate/critique — two agents argue or review each other's work; raises quality on reasoning tasks at the cost of tokens.
- When multi-agent helps: tasks with genuinely distinct roles and skills, where specialization beats one generalist. When it hurts: it multiplies cost, latency, and failure modes — most "multi-agent" demos are a single well-prompted loop wearing a trench coat. Start single; split only with evidence.
6. Frameworks — and why to build one by hand once
The options, at a glance:
- LangGraph — explicit graph/state-machine semantics; the industry default for serious agents; good testing and checkpointing.
- OpenAI Agents SDK / Claude Agent SDK — provider-native, minimal, fast to start.
- AutoGen / CrewAI — multi-agent oriented.
- Your own loop — 100–200 lines: LLM call → tool dispatch → state update → repeat.
The recommendation: build a minimal agent from scratch once (one weekend) to own the mental model, then use LangGraph (or the SDK) for real work. The framework is the plumbing; the loop is the idea, and you must know the idea cold.
7. Reliability & guardrails — the engineering core
Agents fail differently from chatbots — they act, so failures cost more. The guardrail checklist:
- Loop prevention — max iterations, timeouts, cycle detection (the same tool call with the same result twice in a row = stop and re-plan).
- Error containment — every tool wrapped; the loop survives individual failures.
- Cost control — token budgets per step and per run; a runaway agent is a burning credit card. Kill switches.
- Human-in-the-loop — checkpoints before irreversible actions; escalation when confidence is low.
- Safety — tool permissions are the new security boundary: least privilege, sandboxed execution (run code in containers), input validation (agents are a bigger prompt-injection surface — a malicious web page your agent reads can try to steer it), and output filtering.
- Determinism where it matters — for critical paths, structure the agent's output (JSON schemas), validate, and fall back to a deterministic branch when validation fails.
8. Evaluating agents
Evaluation is harder than for chatbots, because there is a trajectory, not just a final answer:
- Outcome metrics — did the task succeed? (task success rate on a task suite, quality of the final artifact).
- Trajectory metrics — efficiency (steps taken vs. optimal), tool-use correctness (right tool, right args), loop discipline (no useless repeats). Trajectory evals catch problems outcome evals miss.
- The practice: build a task suite (10–30 representative tasks with checkable success criteria), run it on every change, and track both success rate and cost per task. This is the agent equivalent of the golden set from Stage 7 — non-negotiable for anything that ships.
Tools & Skills
- LangGraph (recommended framework) or your chosen SDK — plus a hand-built minimal loop.
- A tooling layer — search, file access, a sandboxed code runner, maybe a browser tool.
- A vector store (from Stage 7) for long-term memory.
- Observability + evals — traces of every step, and a scripted task suite.
Hands-On Tasks
- Build a minimal agent by hand (week 1). One LLM, a tool registry (2–3 tools), a loop with max-iteration guard. No framework. Get it to complete a two-step task (search → summarize). You now own the mental model.
- The research agent (weeks 2–3). On LangGraph, build an agent that researches a topic: decomposes the task, searches (or queries a mock/search API), reads sources, drafts, reflects, and delivers a structured report. Add long-term memory: a vector store that remembers past research it can reuse.
- The workflow agent (week 3–4). Build a second agent with a different shape — e.g., email triage or data pipeline: read items, classify, take actions, escalate. Compare its design with the research agent; notice what generalizes.
- Guardrails (week 4). Deliberately try to break your agent: loop it (a task it can't complete), give it a destructive tool without confirmation (it should stop), inject instructions via retrieved content (it should ignore). Fix each. This is the most valuable debugging you will do in this whole roadmap.
- Eval suite (week 5). Write 10–15 tasks with checkable outcomes; run your agent; measure success rate and cost/task. Make one improvement (better tools, reflection, memory) and re-measure — the numbers should move.
Milestone Checkpoint
You are ready for Stage 9 when:
- Your agent completes a real multi-step task end to end (not a canned demo).
- You can draw the agent loop from memory and name what each arrow means.
- You built it once by hand and once with a framework, and can explain why the framework exists.
- Your agent has: max-iteration guard, error containment, token budget, and at least one human-in-the-loop checkpoint.
- You have a task suite with measured success rate and cost per task — and you improved both at least once.
Curated Resources
- Anthropic — "Building effective agents" — re-read; the clearest essay on agent architecture and when agents are even the right answer.
- LangGraph tutorials — the fastest route from pattern to code, including memory and multi-agent.
- ReAct paper (Yao et al., 2022) — the foundational pattern; short and readable.
- "The Rise and Potential of Large Language Model Based Agents" (survey) — the definitive map of agent architectures, memory taxonomies, and open problems.
- OpenAI / Claude agent docs — provider-native patterns and tool schemas in production.
Time Estimate & Pace
- Total: ~6 weeks at 10–15 h/week (roughly 75 hours).
- Suggested split: week 1 → hand-built loop (task 1); weeks 2–3 → research agent + memory (task 2); week 4 → workflow agent + guardrails (tasks 3–4); weeks 5–6 → eval suite, iteration, milestone.
Bridge to the Next Stage
You have reached the top of the map: from zero to a working agent. Stage 9 is the final article, and it does something different — it looks outward and forward: multimodal models, production operations, the frontier research shaping the next five years, and how to turn everything you've built into a portfolio and a career. The road is nearly yours.
No comments yet.