跳转到主要内容

简介

在 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

结果返回

工具输出作为任务结果返回,不做任何修改。