Lộ trình học›Claude API›Building with the Claude API Mở bản đồ

6.70 · Workflows vs Agents — Pattern nào khi nào?

Bài viếtTrung cấp → Nâng20 phút đọc

Có 2 kiến trúc chính khi build app với Claude + tools:

Sau bài này, bạn sẽ
  1. Phân biệt workflow và agent
  2. So sánh ưu/nhược điểm mỗi approach
  3. Decision framework: workflow hay agent?
  4. Hiểu "always workflow first, agent only when required"

Mở đầu: 2 cách build AI apps

Workflow
Bạn pre-define sequence of steps. Claude thực thi từng bước.
Agent
Bạn give Claude goals + tools. Claude tự plan sequence.

Trông giống, behavior khác biệt. Chọn sai → app unreliable hoặc over-engineered.

Workflow

Definition: Pre-defined series of Claude calls designed to solve known problems.

User task → Step 1 (Claude) → Step 2 (Claude) → Step 3 (code) → ... → Output

Mỗi step có specific job. Bạn biết exact sequence.

Example

Video creation workflow:

  1. Topic research (Claude)
  2. Write script (Claude)
  3. Generate voice (TTS API)
  4. Generate visuals (image API)
  5. Combine with FFmpeg (code)
  6. Upload to platform (API)

Sequence fixed. Each step focused.

Agent

Definition: Give Claude tools + goal. Claude figure out steps.

User task → Claude plans → Call tool A → See result → Plan next → Call tool B → ... → Output

Claude decides dynamically.

Example

Claude Code — agent for coding tasks:

  • Tools: Read, Edit, Bash, Grep, WebFetch, ...
  • User: "Fix this bug"
  • Claude: reads relevant files, analyzes, edits, runs tests, iterates until fixed

Never same sequence twice. Claude adapts.

Trade-offs

Workflow benefits

  • Higher accuracy: Claude focus 1 subtask at time
  • Easier eval: Know exact steps, test mỗi
  • Predictable: Same input → similar output
  • Lower cost: Smaller prompts per step

Workflow downsides

  • Inflexible: Only solve pre-defined task
  • Design effort: Need plan sequence upfront
  • Constrained UX: User must match pattern

Agent benefits

  • Flexible: Handle novel tasks
  • Powerful UX: Natural conversation
  • Creative: Combine tools unexpectedly
  • Adaptive: Ask user when stuck

Agent downsides

  • Lower success rate: Creative planning sometimes wrong
  • Hard to test: Non-deterministic behavior
  • Expensive: More turns = more tokens
  • Hard to debug: Each run different

Decision framework

┌─────────────────────────────────────────────┐
│                                             │
│   Can I draw flowchart of task?             │
│                                             │
│           ┌─────────────┐                   │
│           │    YES      │                   │
│           │  → Workflow │                   │
│           └─────────────┘                   │
│                                             │
│           ┌─────────────┐                   │
│           │     NO      │                   │
│           │  → Agent    │                   │
│           └─────────────┘                   │
│                                             │
└─────────────────────────────────────────────┘

Specific cues

Workflow when:

  • Task well-defined (e.g., "generate invoice from data")
  • Clear input/output contracts
  • Compliance/audit needs (show exact steps)
  • High reliability required
  • High volume same type task

Agent when:

  • Open-ended tasks ("help me debug this")
  • User conversations (assistant)
  • Creative problem solving
  • Tool set genuinely varied
  • Can accept 80% success rate

Hybrid pattern

Production apps thường hybrid:

User input
    │
    ▼
Agent (high-level) — decide approach
    │
    ├─ Task A → Workflow 1
    ├─ Task B → Workflow 2
    └─ Task C → Sub-agent với specialized tools

Agent as router → dispatch to workflows for well-known tasks.

Real-world examples

Pure workflow

  • Invoice generator: data → format → send. Same sequence always.
  • Content moderation: ingest → classify → route. Predictable.
  • Report generation: template + data → fill → export.

Pure agent

  • Claude Code: coding tasks unpredictable
  • Computer Use: navigate UI flexibly
  • Research assistant: questions vary widely

Hybrid

  • Customer support bot: agent chat → if refund request, invoke refund workflow
  • Sales assistant: agent for lead qualification → workflow for CRM update
  • Legal review: agent chat → workflow for specific contract analysis

Quote từ Anthropic research

We recommend workflows whenever possible. They're more reliable, easier to eval, and cheaper. Use agents only when flexibility is genuinely required.

Anthropic Building Agents team. Priority: reliability > flexibility cho user-facing apps.

Common mistakes

Agent for simple task

"Classify support ticket" → no need agent. Simple prompt enough.

Fix: Workflow / single call.

Workflow for open-ended

"Help me with this project" → too varied for workflow.

Fix: Agent với right tools.

No eval for agent

Ship agent without measuring behavior → silent failures in production.

Fix: Log tool calls, success rates, user feedback.

Over-tooled agent

50 tools cho agent → Claude overwhelmed, slow, expensive.

Fix: Minimal tools. Add only when user hit gap.

Áp dụng ngay

Bài tập 1: Classify your app (10 phút)

For each feature of your app:

  • Is task shape predictable? → Workflow
  • Does it vary widely? → Agent

Document in my-goals.md.

Bài tập 2: Convert agent → workflow (20 phút)

Pick 1 currently agent-based feature. Can it be workflow?

If yes → draft workflow steps. Usually simpler + more reliable.

Tóm tắt bài học

Những điều cốt lõi
  • Workflow: pre-defined steps, high reliability, easy eval.
  • Agent: Claude plans with tools, flexible, handle novel tasks.
  • Workflow first, agent only when flexibility required.
  • Hybrid common: agent routes to workflows for known tasks.
  • Trade-off: reliability vs flexibility. Start reliable.
Kiểm tra nhanh3 câu hỏi · chọn đáp án để xem giải thích
    Bạn đã hoàn thành bài này chưa?Tiến độ lưu trên trình duyệt của bạn.