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

9 — Workflows & AgentsTrung cấp20 phút

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

Bạn sẽ học được
  • Phân biệt workflow và agent
  • So sánh ưu/nhược điểm mỗi approach
  • Decision framework: workflow hay agent?
  • Hiểu "always workflow first, agent only when required"

Workflow

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

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

Example

Video creation workflow:

Sequence fixed. Each step focused.

  • Topic research (Claude)
  • Write script (Claude)
  • Generate voice (TTS API)
  • Generate visuals (image API)
  • Combine with FFmpeg (code)
  • Upload to platform (API)
User task → Step 1 (Claude) → Step 2 (Claude) → Step 3 (code) → ... → Output

Agent

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

Claude decides dynamically.

Example

Claude Code — agent for coding tasks:

Never same sequence twice. Claude adapts.

  • Tools: Read, Edit, Bash, Grep, WebFetch, ...
  • User: "Fix this bug"
  • Claude: reads relevant files, analyzes, edits, runs tests, iterates until fixed
User task → Claude plans → Call tool A → See result → Plan next → Call tool B → ... → Output

Trade-offs

Workflow benefits

Workflow downsides

Agent benefits

Agent downsides

  • 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
  • Inflexible: Only solve pre-defined task
  • Design effort: Need plan sequence upfront
  • Constrained UX: User must match pattern
  • Flexible: Handle novel tasks
  • Powerful UX: Natural conversation
  • Creative: Combine tools unexpectedly
  • Adaptive: Ask user when stuck
  • 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

Specific cues

Workflow when:

Agent 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
  • Open-ended tasks ("help me debug this")
  • User conversations (assistant)
  • Creative problem solving
  • Tool set genuinely varied
  • Can accept 80% success rate
┌─────────────────────────────────────────────┐
│                                             │
│   Can I draw flowchart of task?             │
│                                             │
│           ┌─────────────┐                   │
│           │    YES      │                   │
│           │  → Workflow │                   │
│           └─────────────┘                   │
│                                             │
│           ┌─────────────┐                   │
│           │     NO      │                   │
│           │  → Agent    │                   │
│           └─────────────┘                   │
│                                             │
└─────────────────────────────────────────────┘

Hybrid pattern

Production apps thường hybrid:

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

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

Real-world examples

Pure workflow

Pure agent

Hybrid

  • Invoice generator: data → format → send. Same sequence always.
  • Content moderation: ingest → classify → route. Predictable.
  • Report generation: template + data → fill → export.
  • Claude Code: coding tasks unpredictable
  • Computer Use: navigate UI flexibly
  • Research assistant: questions vary widely
  • 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

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:

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.

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

Tóm tắt

🎯 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.

Nội dung này có hữu ích không?