1 Introducing CrewAI
Large language models excel at generating text, but agentic AI closes the gap between writing and doing by enabling systems that pursue goals, invoke tools, gather information, and decide when they are finished. Function calling lets models propose tool invocations that developers execute and loop back into the model, forming the basis of the agent’s reasoning loop. The chapter distinguishes autonomous AI agents—LLM-directed loops with dynamic tool use and self-termination—from agentic workflows, which follow developer-defined, often conditionally routed graphs that trade flexibility for predictability; multiple agents can also collaborate as a crew to accomplish complex tasks.
CrewAI is introduced as an open-source framework that turns a single prompt into a coordinated team via a small set of composable primitives: agents, tasks, tools, crews, processes, and flows. It emphasizes the Role-Goal-Backstory pattern to create focused, effective agents and highlights practical guidance: smaller, specialized agents with fewer tools outperform monoliths, and well-crafted tasks matter most (the “80/20” rule prioritizes task design over agent tuning). Designed for both beginners and enterprise needs, CrewAI combines ease of use, strong defaults, and deep configurability, plus guardrails and backward compatibility.
The building blocks are summarized as follows: agents are autonomous, configurable personas with tools and memory; tasks are precise work units that specify the objective, assignee, success criteria, resources, constraints, and even structured outputs (for example, JSON or Pydantic). Tools transform reasoning into action across search, files, databases, automation, and AI services, with simple paths to custom tooling. Crews orchestrate multi-agent collaboration, managing execution, information flow, retries, and results via hierarchical or sequential processes. Flows provide deterministic orchestration—conditional logic, parallelism, error recovery, and integration—while seamlessly embedding agents or entire crews; together, crews and flows combine autonomy with control to deliver end-to-end, reliable AI systems.
At the heart of each AI agent is the agent loop, in which the LLM reasons, calls tools at will, and decides when to stop.
In an agentic workflow, the system follows code paths that were pre-defined by the developer. Those steps can include arbitrary logic expressed in code, LLM calls, as well as dynamic routing based on the results of a previous step.
Each agent is initialized with a role, goal, and a compelling backstory.
The documentation writer agent has a well-defined role, a clearly laid out goal, and a compelling backstory. It has access to three tools: one to search the web for a specific query, one to summarize a snippet of text, and one to format any given text as markdown to create a nice document.
A crew is like a cross-functional team that works on a given set of tasks until they are completed.
An example flow that generates a book based on a topic that is given as input and returns a link to a generated PDF in the end. It contains two crews that are being executed in two different steps of the workflow, a shared state, parallel execution, and dynamic routing based on the output of a crew.
Summary
- Learned about function calling, agentic AI, and how it’s different from plain LLMs.
- Explored the foundation of CrewAI as a library and its building blocks, including agents, tasks, tools, crews, and flows.
- Examined the differences between AI agents and agentic workflows, their potential for combination, and which one is better suited for specific situations.
FAQ
What is agentic AI, and how is it different from a standard LLM?
Agentic AI refers to systems where an AI agent is self-directed: it can plan, decide, and call tools to accomplish tasks end-to-end. A standard LLM only generates text; an agent uses a reasoning loop to decide when to invoke tools, how to proceed, and when it’s done.
How does tool (function) calling turn an LLM into an agent?
With function calling, developers declare tools (names, descriptions, and input/output schemas). The LLM can propose tool calls; your app executes them and feeds the results back to the model. This loop lets the system gather data, take actions, and produce grounded answers, forming the basis of agentic behavior.
When should I use an autonomous agent vs. an agentic workflow?
Use an agent when tasks are open-ended, adaptive, and benefit from autonomy (the agent decides how to proceed and when to stop). Use an agentic workflow when you need predictable, pre-defined logic with clear control flow, dynamic routing, and reliability. Workflows trade some flexibility for better predictability.
What are CrewAI’s core building blocks?
- Agents: self-guided AI personas with tools and memory
- Tasks: well-scoped units of work with success criteria
- Tools: capabilities that let agents act (search, I/O, APIs, etc.)
- Crews: collaborating teams of agents executing tasks
- Flows: structured, event-driven workflows orchestrating logic
What is the Role–Goal–Backstory framework for agents?
It defines each agent’s identity and behavior:
- Role: professional identity and domain expertise
- Goal: concrete, measurable outcome to deliver
- Backstory: experience, motivations, and communication style that guide decisions
LLMs are strong at role-playing, so clear roles and backstories improve consistency—especially with smaller, cheaper models.
How should I design tasks in CrewAI?
Treat tasks like excellent tickets: specify the description, assigned agent, expected output (format and constraints), and available tools. You can require structured outputs (JSON or Pydantic models). Follow the 80/20 rule: invest most effort in crafting clear, specific tasks to drive reliable results.
How many tools should an agent have?
Prefer small, focused agents with access to a minimal set of tools. Performance degrades as tool count grows (even though some APIs allow many). Teams of specialized agents with fewer tools each typically outperform a single, overloaded agent.
What is a crew, and what process options exist?
A crew is a team of agents working toward shared tasks. CrewAI manages information passing, execution order, errors, and structured outputs. You can choose:
- Hierarchical: a manager oversees, delegates, and reassigns work—great for complex, adaptive problems
- Sequential: fixed order of tasks—ideal for predictable pipelines
What are flows, and how do they relate to agents and crews?
Flows are the orchestration layer for pre-defined logic: conditionals, parallel steps, error handling, and state management. You can call agents or entire crews within a flow, and agents can invoke workflows as tools. This mixes deterministic control with agentic reasoning where it adds value.
Why choose CrewAI for building agentic systems?
CrewAI is open-source, beginner-friendly, and enterprise-proven. It ships quickly, has strong documentation and backward compatibility, and offers rich integrations. You get sensible defaults with the option to override prompts and internals for advanced use cases.
Building Agentic Applications with CrewAI and MCP ebook for free