Tasks and expected output

CrewAI · Essentials · 10 min

Clear tasks with a concrete expected output are what make agent results predictable.

A Task is one piece of work. Its two required fields are:

  • description: what to do, written like instructions to a colleague. Include the inputs, steps and constraints.
  • expected_output: what "done" looks like, for example "A markdown list of 5 bullet points, each with a source URL". Agents use this to decide when to stop and how to format the answer, so make it specific.

Usually you also set agent, the agent responsible for the task. (In the hierarchical process, covered later, a manager assigns agents instead.)

Like agents, tasks can contain {placeholders} that are filled from the crew's inputs when it starts.

Other common options:

  • output_file="output/report.md" saves the result to a file; missing folders are created.
  • markdown=True asks the agent to format its answer as Markdown.
  • tools=[...] gives tools for this task only, overriding the agent's tools.
  • name gives the task a readable name for logs.

When the task finishes, CrewAI stores a TaskOutput. Its raw field is the answer as text; later lessons add structured versions.

A good habit: one task, one clear deliverable. If a description contains "and then" several times, it is probably several tasks. Smaller tasks are easier to check, retry and reuse.

Example

from crewai import Agent, Task

analyst = Agent(
    role="Product analyst",
    goal="Turn raw notes into clear findings",
    backstory="You write concise, evidence-based summaries.",
)

summarize = Task(
    name="summarize_feedback",
    description=(
        "Read these customer comments about {product}:\n{comments}\n"
        "Group them into themes and count how often each theme appears."
    ),
    expected_output="A markdown table with columns Theme | Count | Example quote, "
                    "sorted by Count, at most 6 rows.",
    agent=analyst,
    markdown=True,
    output_file="output/feedback.md",   # written when the task completes
)

Remember

  • Every task needs a description and a concrete expected_output
  • Assign an agent; use {placeholders} for run-time inputs
  • One task, one deliverable; split long multi-step descriptions

Watch out for

  • Leaving expected_output vague ("a good report"), which gives inconsistent length and format between runs.

Check yourself

  1. Why does a precise expected_output improve results?

Sign in to answer, see the explanations, and get this lesson back as a quick review later.

Official docs: docs.crewai.com/en/concepts/tasks