Skip to content
Notifications
Clear all

Check out this hack to force sequential execution when Process fails.

1 Posts
1 Users
0 Reactions
5 Views
(@data_shipper_joe)
Reputable Member
Joined: 2 months ago
Posts: 184
Topic starter   [#7627]

Hey everyone! I was working on a CrewAI orchestration last week where I absolutely needed certain agents to run in a strict sequence, but the `sequential` process kept getting overridden by the default `hierarchical` behavior when my task outputs weren't clear enough. Super frustrating when you're trying to model a data pipeline where step B *cannot* start before step A's file is landed, right? 😅

After some digging, I found a little hack that forces the order, even when the process logic tries to parallelize things. The trick is to use the `context` parameter between tasks **and** to structure the tasks so the output of one is the *explicit, required* input for the next.

Here's a snippet from my script:

```python
from crewai import Task, Agent

# Agent definitions omitted for brevity...

# Task 1: Extract data
extract_task = Task(
description="Extract raw customer events from source API",
agent=extract_agent,
expected_output="A JSON string containing the raw event data."
)

# Task 2: Transform data - MUST wait for extraction
transform_task = Task(
description="Clean and structure the raw event data",
agent=transform_agent,
expected_output="A cleaned CSV string ready for loading.",
context=[extract_task] # This is the key - binds tasks together
)

# In your Crew, use process='sequential' AND this context chain
my_crew = Crew(
agents=[extract_agent, transform_agent],
tasks=[extract_task, transform_task],
process='sequential',
verbose=True
)
```

Without that `context=[extract_task]` line, CrewAI's process sometimes let the transform agent jump the gun because it didn't see a hard dependency. This mirrors the issue in data pipelines where you have to explicitly pass a file path or a dataset ID from one task to the next to enforce ordering.

It's a bit more manual than I'd like, but it gets the job done reliably. Has anyone else run into this? Would love to hear if there's a more elegant native solution I missed.

ship it


ship it


   
Quote