
AttributeError: ‘AgentExecutor’ object has no attribute ‘ask_for_human_input’ with default experimental executor
快速结论:此报错发生在 CrewAI 1.14.5+ 版本中,当 Task 设置 human_input=True 时触发。优先排查是否使用了新默认的实验性 AgentExecutor(experimental executor),该 executor 未直接暴露 ask_for_human_input 属性,导致 HumanInputProvider 访问失败。
问题场景
用户在 CrewAI(1.14.5 或 1.14.6)中创建 Agent 和 Task,并将 Task 的 human_input 参数设置为 True,然后通过 Crew.kickoff() 运行工作流。运行过程中,当需要触发人工反馈时,代码崩溃并抛出 AttributeError。此问题在 Windows 11、Python 3.12、crewai 1.14.6、crewai-tools 1.14.6 环境中被复现。
报错原文
An unknown error occurred. Please check the details below.
Error details: 'AgentExecutor' object has no attribute 'ask_for_human_input'
原因分析
根本原因在于新默认的实验性 AgentExecutor(位于 crewai/experimental/agent_executor.py)与 ExecutorContext 协议不兼容。
ExecutorContext协议(定义在crewai/core/providers/human_input.py:26)要求 executor 对象直接具备ask_for_human_input: bool属性。SyncHumanInputProvider._handle_regular_feedback会直接读取并写入context.ask_for_human_input(如while context.ask_for_human_input:和context.ask_for_human_input = False)。- 旧的
CrewAgentExecutor(位于crewai/agents/crew_agent_executor.py:129)将ask_for_human_input定义为顶层 Pydantic 字段(ask_for_human_input: bool = Field(default=False)),因此满足协议。 - 新的默认实验性
AgentExecutor(位于crewai/experimental/agent_executor.py)的处理方式不同:ask_for_human_input定义在AgentExecutorState(Flow 状态类,第 132 行)上,而非 executor 本身。executor 的invoke()方法虽然正确地通过self.state.ask_for_human_input使用,但随后将self转换为ExecutorContext传递给_handle_human_feedback(第 3025 行),此时直接的属性访问self.ask_for_human_input因为不存在而失败。
额外问题:在 CrewAI 1.14.4 中,human_input=True 也存在退化——结果被隐藏(除非开启 verbose),导致用户被要求审查从未显示的“Final Result above”。这说明该功能从 1.14.4 开始就已退化,在 1.14.5+ 进一步恶化至完全崩溃。
环境排查
- Python 版本:3.12
- CrewAI 版本:1.14.5 或 1.14.6(问题在 1.14.4 也可能以不同形式出现)
- CrewAI Tools 版本:1.14.6
- 虚拟环境:Venv
- 触发条件:任何设置了
human_input=True的 Task
解决步骤
注意:以下解决方案基于 Issue 中提出的修复方案。由于该 Issue 尚未合并到主分支,建议优先尝试前两种修复方式。
- 方案一:为 AgentExecutor 添加属性委托(可优先尝试)
在
crewai/experimental/agent_executor.py中的AgentExecutor类中添加属性委托,将ask_for_human_input的读写委托给self.state,使其满足ExecutorContext协议:@property def ask_for_human_input(self) -> bool: return self.state.ask_for_human_input @ask_for_human_input.setter def ask_for_human_input(self, value: bool) -> None: self.state.ask_for_human_input = value - 方案二:切换回旧的 CrewAgentExecutor(临时绕过)
如果无法修改源代码,可尝试通过配置强制使用旧的
CrewAgentExecutor。具体方法取决于你的 CrewAI 版本和配置方式,请查阅相关文档。注意:此方式仅为临时绕过,可能影响其他功能。 - 方案三:等待官方修复
监控 CrewAI 的版本更新,确认包含此修复的版本发布后升级。
- 额外修复(针对 1.14.4 版本隐藏结果的问题):
当
human_input激活时,确保AgentFinish输出会无条件显示(而非仅当verbose=True时才显示),以便用户能看到需要审查的结果。这可能需要修改crew_agent_executor.py::_show_logs或相关渲染逻辑。
验证方法
使用以下最小复现代码(无需 API 密钥)测试:
from crewai import Agent, Crew, Task, Process
from crewai.llms.base_llm import BaseLLM
class StubLLM(BaseLLM):
def call(self, messages, tools=None, callbacks=None, available_functions=None,
from_task=None, from_agent=None, response_model=None):
return "Thought: I know it.\nFinal Answer: The sky is blue."
def supports_function_calling(self) -> bool:
return False
agent = Agent(role="Tester", goal="Answer", backstory="bg",
llm=StubLLM(model="stub"), verbose=False)
task = Task(description="Sky colour?", expected_output="a colour",
agent=agent, human_input=True)
Crew(agents=[agent], tasks=[task], process=Process.sequential, verbose=False).kickoff()
运行后,预期行为应为:Agent 完成任务后,暂停执行并显示带最终结果的反馈面板供用户输入。如果不再出现 AttributeError,并且结果可见(无需 verbose=True),则问题已解决。



