You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决CrewAI层级处理报错:输入需为有效字典或BaseAgent实例

问题:CrewAI层级流程(Process.hierarchical)启动报错

使用CrewAI搭建1个管理Agent与2个工作Agent,采用顺序流程(Process.sequential)时运行正常,但切换至层级流程(Process.hierarchical)时出现如下报错:

manager_agent
  Input should be a valid dictionary or instance of BaseAgent [type=model_type, input_value=<bound method memoize.<lo... object at 0x10bd9e390>>, input_type=method]
    For further information visit https://errors.pydantic.dev/2.8/v/model_type

问题原因

初始化Crew时,manager_agent=self.manager传递的是方法对象,而非方法执行后返回的Agent实例。层级流程要求manager_agent必须是BaseAgent的实例,因此触发了Pydantic的类型校验错误。

修复方法

将manager_agent=self.manager修改为manager_agent=self.manager(),调用被@agent装饰的方法以获取实际的Agent实例。

修改后的crew方法代码如下:

@crew
def crew(self) -> Crew:
    """Creates the Sample crew"""
    return Crew(
        agents=self.agents, # Automatically created by the @agent decorator
        tasks=self.tasks, # Automatically created by the @task decorator
        # process=Process.sequential,
        verbose=2,
        manager_agent=self.manager(),  # 调用方法获取Agent实例
        memory=True,
        # manager_llm=azure_llm,
        process=Process.hierarchical,
    )

内容的提问来源于stack exchange,提问作者Diablo3093

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 09:11:07