ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

CrewAI 任务如何开启 human_input 在执行中向用户索取补充信息

CrewAI 任务如何开启 human_input 在执行中向用户索取补充信息 CrewAI 任务如何开启 human_input 在执行中向用户索取补充信息【免费下载链接】crewAIFramework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.项目地址: https://gitcode.com/GitHub_Trending/cr/crewAI在 CrewAI 中运行多步任务时Agent 可能会在信息不足、存在歧义或产出需要人工确认的情况下直接给出最终答案。human_input是Task的一个布尔属性开启后Agent 在交付最终答案之前会先向用户索取输入——用于补充上下文、澄清歧义或验证 Agent 的产出。本文说明如何在任务上开启这个开关、如何运行并确认它生效以及该功能的行为边界。适用前提CrewAI 要求Python 3.10 and 3.14可用以下命令确认python3 --versionhuman_input 的行为与适用条件根据 Human Input on Execution开启方式就是在任务定义中设置human_input标志。启用后Agent 会在给出最终答案前提示用户输入这份输入可以补充额外上下文、澄清歧义或验证 Agent 的输出。在 Task 属性表中该字段的定义是AttributeParametersTypeDescriptionHuman Input(optional)human_inputOptional[bool]Whether the task should have a human review the final answer of the agent. Defaults to False.要点默认值为False即不设置时任务执行过程不会向用户索取输入它是任务级属性对每个任务单独生效哪个任务开启哪个任务暂停等待由于运行中会暂停等待人工输入任务必须运行在可交互的环境里。文档在描述训练流程其中任务同样设置human_input true时明确提示在非交互式环境中运行会阻塞在等待用户输入这一步见 Training 文档。准备环境安装 CrewAI来自 human-input 官方示例的依赖安装方式pip install crewai运行官方示例还需要两个 API key通过环境变量提供SERPER_API_KEYserper.dev 的搜索 API key示例中的SerperDevTool依赖它OPENAI_API_KEY模型服务的 API key。如果更倾向于用 CLI 管理安装Installation 文档给出的是uv tool install crewai并用uv tool list验证安装文档示例输出为crewai v0.102.0 - crewai。两种方式任选其一即可本文主路径跟随官方 human-input 示例使用pip。在任务上开启 human_input下面的完整脚本来自 官方 human-input 示例是一个研究员 撰稿人的 Crew两个任务都开启了human_inputTrue。代码中Your Key两处是文档占位符运行前必须替换为你自己的 serper.dev 和 OpenAI API keyimport os from crewai import Agent, Task, Crew from crewai_tools import SerperDevTool os.environ[SERPER_API_KEY] Your Key # serper.dev API key os.environ[OPENAI_API_KEY] Your Key # Loading Tools search_tool SerperDevTool() # Define your agents with roles, goals, tools, and additional attributes researcher Agent( roleSenior Research Analyst, goalUncover cutting-edge developments in AI and data science, backstory( You are a Senior Research Analyst at a leading tech think tank. Your expertise lies in identifying emerging trends and technologies in AI and data science. You have a knack for dissecting complex data and presenting actionable insights. ), verboseTrue, allow_delegationFalse, tools[search_tool] ) writer Agent( roleTech Content Strategist, goalCraft compelling content on tech advancements, backstory( You are a renowned Tech Content Strategist, known for your insightful and engaging articles on technology and innovation. With a deep understanding of the tech industry, you transform complex concepts into compelling narratives. ), verboseTrue, allow_delegationTrue, tools[search_tool], cacheFalse, # Disable cache for this agent ) # Create tasks for your agents task1 Task( description( Conduct a comprehensive analysis of the latest advancements in AI in 2025. Identify key trends, breakthrough technologies, and potential industry impacts. Compile your findings in a detailed report. Make sure to check with a human if the draft is good before finalizing your answer. ), expected_outputA comprehensive full report on the latest AI advancements in 2025, leave nothing out, agentresearcher, human_inputTrue ) task2 Task( description( Using the insights from the researcher\s report, develop an engaging blog post that highlights the most significant AI advancements. Your post should be informative yet accessible, catering to a tech-savvy audience. Aim for a narrative that captures the essence of these breakthroughs and their implications for the future. ), expected_outputA compelling 3 paragraphs blog post formatted as markdown about the latest AI advancements in 2025, agentwriter, human_inputTrue ) # Instantiate your crew with a sequential process crew Crew( agents[researcher, writer], tasks[task1, task2], verboseTrue, memoryTrue, planningTrue # Enable planning feature for the crew ) # Get your crew to work! result crew.kickoff() print(######################) print(result)脚本里两个值得注意的细节human_inputTrue直接写在Task(...)的参数中与agent、expected_output并列task1的description里还额外写了一句 Make sure to check with a human if the draft is good before finalizing your answer.——这是官方示例的做法即在任务描述中说明定稿前找人工确认与human_inputTrue配合使用。JSONC 项目中的开启方式如果你的项目是用crewai create crew name生成的 JSON-first 项目任务定义在crew.jsonc中不需要改 Python 代码。Tasks 文档说明crew.jsonc中每个任务条目支持所有公开的Task字段明确列出的常用字段就包括human_input。在对应任务里加上该字段即可例如{ name: reporting_task, description: Review the research and expand it into a detailed report., expected_output: A polished markdown report without fenced code blocks., agent: reporting_analyst, context: [research_task], human_input: true, markdown: true, output_file: report.md }以上片段基于 Tasks 文档给出的crew.jsonc双任务示例仅演示human_input字段的写法。运行与确认生效直接执行脚本在可交互的终端中python your_script.py判断human_input是否生效依据文档描述的行为开启该标志的任务在执行到最终答案之前会暂停并向用户提示输入。即运行到task1和task2的交付阶段时终端会等待你输入你提供的补充信息会被用于修正或确认该任务的最终答案之后 Crew 继续执行最后通过print(result)输出整趟运行的结果。需要区分两种情况交互式终端符合预期输入后继续运行非交互式环境文档指出此类任务设置human_input true后运行会阻塞在用户输入这一步因此不要期望无人值守地跑完含human_inputTrue任务的 Crew。限制与边界human_input默认False且是任务级开关不影响 Crew 其他任务它的作用点是在最终答案交付前向用户索取输入文档没有提供在任务执行中途任意位置插入人工确认的机制描述人工输入用于补充上下文、澄清歧义或验证输出见 human-input 文档文档未对该功能给出其他扩展配置项。相关文档入口Human Input on Execution、Tasks、Installation、Training。【免费下载链接】crewAIFramework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.项目地址: https://gitcode.com/GitHub_Trending/cr/crewAI创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表