diff --git a/docs/core-concepts/Crews.md b/docs/core-concepts/Crews.md index b1b0339fb..2d9402258 100644 --- a/docs/core-concepts/Crews.md +++ b/docs/core-concepts/Crews.md @@ -155,12 +155,15 @@ for async_result in async_results: print(async_result) ``` +These methods provide flexibility in how you manage and execute tasks within your crew, allowing for both synchronous and asynchronous workflows tailored to your needs + + ### Replaying from specific task: You can now replay from a specific task using our cli command replay. The replay_from_tasks feature in CrewAI allows you to replay from a specific task using the command-line interface (CLI). By running the command `crewai replay -t `, you can specify the `task_id` for the replay process. -Kickoffs will now save the latest task outputs locally for you to be able to replay from. +Kickoffs will now save the latest kickoffs returned task outputs locally for you to be able to replay from. ### Replaying from specific task Using the CLI @@ -181,4 +184,4 @@ crewai log-tasks-outputs crewai replay -t ``` -These methods provide flexibility in how you manage and execute tasks within your crew, allowing for both synchronous and asynchronous workflows tailored to your needs +These commands let you replay from your latest kickoff tasks, still retaining context from previously executed tasks. \ No newline at end of file diff --git a/docs/how-to/Replay-tasks-from-latest-Crew-Kickoff.md b/docs/how-to/Replay-tasks-from-latest-Crew-Kickoff.md new file mode 100644 index 000000000..4843bcb4c --- /dev/null +++ b/docs/how-to/Replay-tasks-from-latest-Crew-Kickoff.md @@ -0,0 +1,49 @@ +--- +title: Replay Tasks from Latest Crew Kickoff +description: Replay tasks from the latest crew.kickoff(...) +--- + +## 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. + +## Note: +You must run `crew.kickoff()` before you can replay a task. Currently, only the latest kickoff is supported, so if you use `kickoff_for_each`, it will only allow you to replay from the most recent crew run. + +Here's an example of how to replay from a task: + +### Replaying from specific task Using the CLI +To use the replay feature, follow these steps: + +1. Open your terminal or command prompt. +2. Navigate to the directory where your CrewAI project is located. +3. Run the following command: + +To view latest kickoff task_ids use: +```shell +crewai log-tasks-outputs +``` + +Once you have your task_id to replay from use: +```shell +crewai replay -t +``` + + +### Replaying from a task Programmatically +To replay from a task programmatically, use the following steps: + +1. Specify the task_id and input parameters for the replay process. +2. Execute the replay command within a try-except block to handle potential errors. + +```python + def replay_from_task(): + """ + Replay the crew execution from a specific task. + """ + task_id = '' + inputs = {"topic": "CrewAI Training"} # this is optional, you can pass in the inputs you want to replay otherwise uses the previous kickoffs inputs + try: + YourCrewName_Crew().crew().replay_from_task(task_id=task_id, inputs=inputs) + + except Exception as e: + raise Exception(f"An error occurred while replaying the crew: {e}") \ No newline at end of file diff --git a/docs/index.md b/docs/index.md index 66b4a7a37..061ee9027 100644 --- a/docs/index.md +++ b/docs/index.md @@ -113,6 +113,11 @@ Cutting-edge framework for orchestrating role-playing, autonomous AI agents. By Kickoff a Crew for a List +
  • + + Replay from a Task + +
  • Agent Monitoring with AgentOps diff --git a/mkdocs.yml b/mkdocs.yml index d609c2547..e17bc0281 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -145,6 +145,7 @@ nav: - Human Input on Execution: 'how-to/Human-Input-on-Execution.md' - Kickoff a Crew Asynchronously: 'how-to/Kickoff-async.md' - Kickoff a Crew for a List: 'how-to/Kickoff-for-each.md' + - Replay from a specific task from a kickoff: 'how-to/Replay-tasks-from-latest-Crew-Kickoff.md' - Agent Monitoring with AgentOps: 'how-to/AgentOps-Observability.md' - Agent Monitoring with LangTrace: 'how-to/Langtrace-Observability.md' - Tools Docs: diff --git a/src/crewai/cli/cli.py b/src/crewai/cli/cli.py index aef0da963..6b8038248 100644 --- a/src/crewai/cli/cli.py +++ b/src/crewai/cli/cli.py @@ -78,14 +78,16 @@ def replay(task_id: str) -> None: @crewai.command() def log_tasks_outputs() -> None: """ - Log your previously ran kickoff task outputs. + Retrieve your latest crew.kickoff() task outputs. """ try: storage = KickoffTaskOutputsSQLiteStorage() tasks = storage.load() if not tasks: - click.echo("No task outputs found.") + click.echo( + "No task outputs found. Only crew kickoff task outputs are logged." + ) return for index, task in enumerate(tasks, 1): diff --git a/src/crewai/crew.py b/src/crewai/crew.py index 018097f3b..0132c6941 100644 --- a/src/crewai/crew.py +++ b/src/crewai/crew.py @@ -464,6 +464,7 @@ class Crew(BaseModel): results.append(output) self.usage_metrics = total_usage_metrics + self._task_output_handler.reset() return results async def kickoff_async(self, inputs: Optional[Dict[str, Any]] = {}) -> CrewOutput: @@ -512,7 +513,7 @@ class Crew(BaseModel): total_usage_metrics[key] += crew.usage_metrics.get(key, 0) self.usage_metrics = total_usage_metrics - + self._task_output_handler.reset() return results def _store_execution_log(