Skip to content

Fixing context of tasks when running pipeline#1411

Closed
Shahar-Y wants to merge 2 commits into
crewAIInc:mainfrom
Shahar-Y:fix/context-fix
Closed

Fixing context of tasks when running pipeline#1411
Shahar-Y wants to merge 2 commits into
crewAIInc:mainfrom
Shahar-Y:fix/context-fix

Conversation

@Shahar-Y
Copy link
Copy Markdown
Contributor

@Shahar-Y Shahar-Y commented Oct 9, 2024

Fixes #1410

I noticed the agents ignore the context tasks given to them in the context field.
After thorough debugging I fund that the problem lays in the deep copy in crew.py (def copy(self) function) .
The problem was that when running the pipeline, it first copies the crews and then runs the copied crews.
When deep-copying the crew, the tasks are being copied, but they create another instance of the task in the context. That instance's output is not updated when the real task completes and therefore the tasks in the context always have an empty output field.

To solve it, I compared the keys of the original copied tasks with the tasks in the context of each task, and if they were the same, I replaced the context task with the original one. That way the context points to the task that is being run. It works perfectly now.

Proof it works:

Now the example in #1410 gives the correct answer:
image

@Shahar-Y Shahar-Y changed the title deep copy works with fixed context Fixing context of tasks when running pipeline Oct 9, 2024
@joaomdmoura joaomdmoura requested a review from bhancockio October 9, 2024 08:27
@bhancockio
Copy link
Copy Markdown
Contributor

Thank you so much @Shahar-Y for identifying the issue and submitting a solution. Your work was really helpful in pinpointing the problem and validating the fix!

I noticed a few additional linting issues and made some tweaks to the fix to align it with our coding standards. I’ll be closing out this PR in favor of this new PR #1416 , which incorporates your solution but with a slightly different approach.

Thanks again for your contribution, and I’ve credited you in the final PR! 🙌

@bhancockio bhancockio closed this Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Context does not work except in following tasts

2 participants