介绍

在CrewAI中,你可以强制将工具的输出作为代理任务的结果。 当你想要确保工具的输出被捕获并作为任务结果返回时,这个功能非常有用,可以避免在任务执行过程中代理进行任何修改。

强制工具输出作为结果

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

以下是如何强制将工具输出作为代理任务结果的示例:

Code
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

结果返回

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

这个页面有帮助吗?