Skip to course content
Free CrewAI course

CrewAI for Multi-Agent Automation

Unit 01.02: How a task differs from an instruction

A task is not a sentence telling an agent what to do. It is a description plus a contract for what counts as finished.

expected_output is the contract

The description says what to work on. expected_output says what a finished result looks like, in enough detail that someone else could check it.

The code builds a vague task and a specific one from the same agent.

from crewai import Agent, Task

writer = Agent(role="Support writer", goal="Write clear customer replies",
               backstory="You write plainly.", allow_delegation=False)

vague = Task(description="Help the customer", expected_output="A good reply",
             agent=writer)
specific = Task(
    description=("Write a reply to ACC-1187 explaining that their June refund "
                 "was declined because the request came 9 days after purchase, "
                 "and the window is 7 days."),
    expected_output=("A reply of 3-5 sentences that states the reason, cites "
                     "the 7-day policy, and offers one next step. No apology "
                     "for the policy itself."),
    agent=writer,
)

for label, task in [("vague", vague), ("specific", specific)]:
    checkable = len(task.expected_output.split()) > 8
    print(f"{label:9} expected_output checkable: {checkable}")
    print(f"          {task.expected_output}\n")

# `expected_output` is the contract, and "A good reply" is not one. If you
# cannot write a check against it, neither the agent nor a reviewer knows when
# the task is finished.

"A good reply" is four words and specifies nothing. The specific version names a length, three things the reply must contain, and one thing it must not do - and every one of those is checkable by a person or a script.

That last clause, "no apology for the policy itself", is worth noticing. Negative constraints belong in the contract too, and they are the ones that are hardest to add later, because by then you have output you are used to.

The mistake this prevents

The mistake is writing expected_output as a restatement of the description. "A reply to the customer" adds nothing to "write a reply to the customer" - the contract has to say something the description does not, or it is not a contract.

Takeaway

Write expected_output so that a reviewer could reject a submission against it. If you cannot imagine the rejection, the contract is too vague to guide the agent either.