Skip to content
CrewAI 文档版本 跟随上游 源快照 5fccb703 更新于 2026-10-18

强制将工具输出作为结果

了解如何在 CrewAI 中强制将工具输出作为智能体任务的结果。

引言

在 CrewAI 中,你可以强制将工具的输出作为智能体任务的结果。 当你希望确保工具输出被捕获并作为任务结果返回,避免智能体在执行任务期间进行任何修改时,此功能非常有用。

强制将工具输出作为结果

要将工具输出强制作为智能体任务的结果,你需要在向智能体添加工具时将 result_as_answer 参数设置为 True。 此参数确保工具输出被捕获并作为任务结果返回,而不会经过智能体的任何修改。

以下示例展示如何强制将工具输出作为智能体任务的结果:

python
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)

工作流实战

Task Execution

智能体使用提供的工具执行任务。

Tool Output

工具生成输出,该输出会被捕获为任务结果。

Agent Interaction

智能体可能会进行反思并从工具中学习,但输出不会被修改。

Result Return

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

BytesRouter 是社区翻译站点,所有译文仅供参考,一切以官方英文原文为准。