Agents, tasks and a crew
A crew needs three things: an agent that does the work, a task that says what the work is, and the Crew that runs one with the other. kickoff starts it.
ShopLLM answers messages. An agent wraps it with a job description, in three parts CrewAI requires: a role, a goal and a backstory.
from crewai import Agent
from shop_llm import ShopLLM
agent = Agent(
role="Support agent",
goal="Answer customers of a small online shop",
backstory="You have worked the shop's support desk for years.",
llm=ShopLLM(model="shop"),
)
print(agent.role)Nothing ran yet. The agent is a description of a worker; it needs a task.
A task and a crew
from crewai import Crew, Task
task = Task(
description="Answer the customer: Where is my order A17?",
expected_output="One short, friendly sentence.",
agent=agent,
)
crew = Crew(agents=[agent], tasks=[task])
result = crew.kickoff()
print(result.raw)A task has a description of the work and an expected_output saying what finished looks like, and names the agent that does it. The crew takes lists of agents and tasks. kickoff runs the tasks and returns a CrewOutput, whose raw is the last task's answer as text.
result = crew.kickoff()
for output in result.tasks_output:
print(output.agent, "|", output.raw)tasks_output keeps one result per task, each tagged with the role of the agent that produced it. With one task there is one entry; a crew of two agents has two.
Pick one to watch it run, step by step.
The crew holds the lists; the task says what to do and who does it; the agent turns that into messages for the model. A run this small has four moving parts, and you wrote one of them.
An agent with no model
from crewai import Agent
agent = Agent(
role="Support agent",
goal="Answer customers of a small online shop",
backstory="You have worked the shop's support desk for years.",
)
print(agent.llm.model)Leave out llm and CrewAI picks OpenAI's gpt-4.1-mini. The Agents page of the documentation still says the default is GPT-4; the installed version is what runs. Creating the agent works. Running it is where the key is needed:
from crewai import Agent, Crew, Task
import shop_llm
agent = Agent(role="Support agent", goal="Answer customers", backstory="You work the desk.")
task = Task(description="Where is my order A17?", expected_output="One sentence.", agent=agent)
Crew(agents=[agent], tasks=[task]).kickoff()CrewAI tried the call three times before giving up, and printed a warning line for each failed call. import shop_llm is there only for its three settings, so the failed run sends nothing. Every agent below passes llm= explicitly.
- Change the task's description to ask about C40 and run the crew again.
- Delete
expected_outputfrom the task and read the error. - Print
result.tasks_output[0].description.
This is what real progress feels like.