Sequential process and task context

CrewAI · Essentials · 10 min

Getting the right information to each task is what turns separate agents into a working pipeline.

In the sequential process (process=Process.sequential, the default), tasks run in list order. Each task automatically receives the output of the task right before it as context: extra text added to its prompt.

Often that is not enough. A final report task may need the results of tasks one and two. Set context explicitly:

report = Task(..., context=[research_task, numbers_task])

Now the report agent sees both outputs. context takes a list of task objects, not names.

Two consequences to keep in mind:

  • Context is text added to the prompt, so long outputs make later prompts long. Ask earlier tasks for concise results.
  • The order of the task list still matters: a task can only use the output of tasks that run before it.

Independent tasks in parallel. If two tasks don't depend on each other, mark them async_execution=True. They start without waiting, and a later task that lists them in context waits for both to finish. This saves time when tasks call slow tools like web search.

A crew must not end with two or more async tasks in a row. Add a normal task that gathers their results.

The other process type, hierarchical, lets a manager agent decide who does what. It is covered in an advanced lesson. Start with sequential: it is cheaper, easier to debug and enough for most pipelines.

Example

from crewai import Agent, Crew, Process, Task

analyst = Agent(role="Analyst", goal="Research {company}", backstory="Careful and concise.")
writer = Agent(role="Writer", goal="Write a brief on {company}", backstory="Clear writer.")

news = Task(description="List 3 recent news items about {company}.",
            expected_output="3 bullets with dates.", agent=analyst, async_execution=True)
competitors = Task(description="Name {company}'s 3 main competitors.",
                   expected_output="3 bullets.", agent=analyst, async_execution=True)
brief = Task(description="Write a one-paragraph brief using the research.",
             expected_output="One paragraph, under 120 words.", agent=writer,
             context=[news, competitors])   # waits for both async tasks

crew = Crew(agents=[analyst, writer], tasks=[news, competitors, brief],
            process=Process.sequential)
print(crew.kickoff(inputs={"company": "Spotify"}).raw)

Remember

  • Sequential crews pass the previous task's output forward automatically
  • context=[task_a, task_b] gives a task several earlier outputs
  • async_execution=True runs independent tasks in parallel

Watch out for

  • Ending a crew with several async tasks and no final task to collect them, which is rejected.

Check yourself

  1. Task C must use the outputs of tasks A and B (A runs first, then B, then C). What should you set?

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

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