跳转到内容

从最近一次 Crew Kickoff 回放任务

CrewAI 提供了从最近一次 crew kickoff 中指定任务进行回放的能力。这个功能在你已经完成一次 kickoff,并且想重试某些任务,或者无需重新抓取数据时特别有用,因为你的智能体已经在 kickoff 执行中保存了上下文,所以你只需要回放想要的任务。

下面是如何从任务回放的示例:

要使用回放功能,请按以下步骤操作:

  1. 打开终端或命令提示符。
  2. 切换到你的 CrewAI 项目所在目录。
  3. 运行以下命令:

    查看最近一次 kickoff 的 task_id:

    Terminal window
    crewai log-tasks-outputs

    拿到要回放的 task_id 后,执行:

    Terminal window
    crewai replay -t <task_id>

要通过代码回放任务,请按以下步骤:

  1. 指定 `task_id` 和回放所需的输入参数。

    指定 task_id 和输入参数。

  2. 在 try-except 结构中执行回放命令,以处理潜在错误。

    在 try-except 结构中执行回放命令,以处理潜在错误。

    Code
    def 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}")

借助以上增强和详细功能,CrewAI 中对特定任务的回放已经变得更高效、更稳健。请严格遵循这些命令和步骤,以充分利用这些功能。