07. Frameworks & Libraries
Building Multi-Agent Apps with CrewAI
Building multi-agent apps with CrewAI means wrapping crews in a real product: validated inputs, role allowlists, sequential or hierarchical processes, post-kickoff validators, budgets, traces, and optional human gates. CrewAI runs the team; your app owns safety and shipping quality.
What you will learn
- Sketch a layered CrewAI application architecture
- Design a research β write β review product crew
- Choose sequential vs hierarchical for a feature
- List production controls around kickoff
- Answer interview questions with short, solid answers
Definition
A CrewAI application is a product feature that builds Agents and Tasks, assembles a Crew with a Process, and calls kickoff (or async kickoff) behind an API β with your orchestration for auth, inputs, cost caps, logging, validation, and human approval.
Fundamentals covered the four pillars. This lesson focuses on shipping: architecture, a concrete pipeline, process choice, and the production checklist that demos often skip.
Introduction
This lesson (#6 in Frameworks & Libraries) follows CrewAI Fundamentals. Next: Microsoft AutoGen Fundamentals β another multi-agent style.
Start with a small sequential crew and crisp expected_output contracts. Add hierarchy only when dynamic delegation is required.
App layers
Keep CrewAI inside a boundary so you can swap models, add HITL, or migrate hard workflows to LangGraph later without rewriting the product edge.
- Edge - auth, rate limits, request schema validation
- Orchestration - budgets, feature flags, HITL hooks, job ids
- CrewAI - agents, tasks, process, kickoff
- Backends - LLMs, tools/APIs, files, vector/ticket stores
- Obs - per-task and per-tool traces + cost metrics
Example: research brief product
A common shipping shape: sequential research β write β review, then app-level validate and optional human publish.
- Research task - claims[] + sources[] expected_output
- Write task - brief draft constrained by research context
- Review task - pass/fail + must_fix[] against a rubric
- App - schema-validate each hop; reject malformed crew output
- Publish - human approve if customer-facing
Process choice in products
- Sequential - fixed pipelines (briefs, ETL-style AI, codegen+review)
- Hierarchical - open-ended goals needing a manager to assign work
- Hybrid apps - router API selects which crew (or process) to run
- Measure - quality, p95 latency, $/kickoff before adding agents
Tools and memory in apps
- Attach tools per agent allowlist (search β send_email)
- Put authz inside tool handlers β never trust the model alone
- Pass only needed context between tasks; avoid dumping full chat
- Store run artifacts by job_id for audit and retries
Production checklist
kickoff() is not a deploy plan. Wrap it with the same rigor as any workflow engine.
- Inputs - JSON schema before crew construction
- Outputs - parse/validate expected_output artifacts
- Budgets - max time, tokens, and tool calls per kickoff
- Traces - job_id, agent, task, tool, latency, errors
- Evals - golden briefs; regress on prompt/model change
- HITL - approve before irreversible side effects
Failure modes
- Notebook kickoff in prod - secrets and no session isolation
- Fuzzy expected_output - cannot validate or chain reliably
- Tool sprawl - every agent gets every integration
- No timeout - hung tools block workers
- Silent model upgrades - quality cliffs without pins
Program / implementation notes
Structure as api/ + crews/ (agent/task defs) + tools/ + evals/. Build the crew per request from validated inputs; do not share mutable crew state across tenants.
- Prefer sequential + validators first; add hierarchical when metrics demand it
- For durable HITL mid-graph, consider LangGraph alongside or instead
- Next: Microsoft AutoGen Fundamentals
Advantages and limitations
- Advantage: fast path from crew design to product feature
- Advantage: clear role/task contracts for teams
- Advantage: hierarchical process for dynamic delegation
- Limitation: less fine-grained durable control than LangGraph
- Limitation: easy to over-crew simple features
- Limitation: app still must own auth, evals, and ops
Key points
- Apps wrap CrewAI with auth, budgets, validation, and obs.
- Design crews as product workflows with crisp expected_output.
- Sequential first; hierarchical when managers must assign dynamically.
- Validate artifacts after kickoff; HITL before side effects.
- Trace per task/tool and pin models/packages.
- Use LangGraph when you need durable mid-run interrupts.
FAQs
Should every feature be a multi-agent crew?
No. Many features are one agent or a chain. Use a crew when roles, isolation, or review quality clearly pay off.
Where do I put API keys for tools?
Server-side secrets. Tool handlers inject credentials; never put keys in agent backstories or prompts.
How do I stop expensive kickoffs?
Enforce wall-clock and token budgets in orchestration, limit tools/iterations, and fail closed when caps hit.
CrewAI app or LangGraph app?
CrewAI for crew/task-centric teams shipping quickly. LangGraph when you need explicit durable graphs and HITL checkpoints mid-flow.
Interview questions
- How do you structure a CrewAI application?
Answer Edge auth/API, orchestration (budgets/HITL/logs), CrewAI crew kickoff, and backends (LLMs/tools/stores) with per-task observability.
- Give a concrete multi-agent CrewAI product flow.
Answer Sequential research β write β review with expected_output contracts, app-side validation, then optional human approve before publish.
- When choose hierarchical process in an app?
Answer When the goal is open-ended and a manager must dynamically assign worker tasks β not for fixed three-step pipelines.
- What production controls wrap kickoff?
Answer Input/output validation, token/time budgets, tracing, evals, HITL for side effects, and pinned model/package versions.
- Name a common CrewAI app failure.
Answer Vague expected_output and no validators β crews return prose that downstream systems cannot trust.
- How does this relate to Module 06 patterns?
Answer Apps implement specialized agents, pipelines, and supervisorβworker via CrewAI agents/tasks/processes under product orchestration.
Related topics
Practice task
Complete each numbered practice step in a notebook or doc before opening the next lesson.
- Draw app layers for a βweekly competitor briefβ CrewAI feature; name one component per layer.
- Write expected_output one-liners for research, write, and review tasks.
- List tool allowlists per agent (max 4 tools each).
- Define budget + HITL rules (when a human must approve publish).
- Answer interview questions 1, 2, and 4 in two sentences each.