Replay Tasks from Latest Crew Kickoff
Introduction
Section titled “Introduction”CrewAI provides the ability to replay from a task specified from the latest crew kickoff. This feature is particularly useful when you’ve finished a kickoff and may want to retry certain tasks or don’t need to refetch data over and your agents already have the context saved from the kickoff execution so you just need to replay the tasks you want to.
Here’s an example of how to replay from a task:
Replaying from Specific Task Using the CLI
Section titled “Replaying from Specific Task Using the CLI”To use the replay feature, follow these steps:
- Open your terminal or command prompt.
- Navigate to the directory where your CrewAI project is located.
- Run the following commands:
To view the latest kickoff task_ids use:
Terminal window crewai log-tasks-outputsOnce you have your
task_idto replay, use:Terminal window crewai replay -t <task_id>
Replaying from a Task Programmatically
Section titled “Replaying from a Task Programmatically”To replay from a task programmatically, use the following steps:
- Specify the `task_id` and input parameters for the replay process.
Specify the
task_idand input parameters for the replay process. - Execute the replay command within a try-except block to handle potential errors.
Execute the replay command within a try-except block to handle potential errors.
Codedef replay():"""Replay the crew execution from a specific task."""task_id = '<task_id>'inputs = {"topic": "CrewAI Training"} # This is optional; you can pass in the inputs you want to replay; otherwise, it uses the previous kickoff's inputs.try:YourCrewName_Crew().crew().replay(task_id=task_id, inputs=inputs)except subprocess.CalledProcessError as e:raise Exception(f"An error occurred while replaying the crew: {e}")except Exception as e:raise Exception(f"An unexpected error occurred: {e}")
Conclusion
Section titled “Conclusion”With the above enhancements and detailed functionality, replaying specific tasks in CrewAI has been made more efficient and robust. Ensure you follow the commands and steps precisely to make the most of these features.