跳转到主要内容

文档索引

获取完整文档索引: https://docs.crewai.com.cn/llms.txt

在深入了解之前,请使用此文件来浏览所有可用页面。

简介

在 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

结果返回

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