跳转到内容

强制将工具输出作为结果

在 CrewAI 中,你可以将某个工具的输出强制作为代理任务的结果。这个功能适用于你希望确保工具输出被捕获并作为任务结果返回,同时避免在任务执行过程中被代理修改的场景。

要将工具输出强制作为代理任务的结果,你需要在向代理添加工具时将 result_as_answer 参数设置为 True。这个参数可确保工具输出被捕获并作为任务结果返回,不会被代理做任何修改。

下面是一个将工具输出强制作为代理任务结果的示例:

from crewai.agent import Agent
from my_tool import MyCustomTool
# Create a coding agent with the custom tool
coding_agent = Agent(
role="Data Scientist",
goal="Produce amazing reports on AI",
backstory="You work with data and AI",
tools=[MyCustomTool(result_as_answer=True)],
)
# Assuming the tool's execution and result population occurs within the system
task_result = coding_agent.execute_task(task)
  1. 任务执行

    代理使用提供的工具执行任务。

  2. 工具输出

    工具生成输出,并将其捕获为任务结果。

  3. 代理交互

    代理可能会基于该工具进行反思并吸收信息,但输出不会被修改。

  4. 结果返回

    工具输出会在不做任何修改的情况下作为任务结果返回。