CrewAI – 在运行Crew时遇到KeyError: ‘key_name’

我在按照CrewAI的入门指南操作时,执行项目根目录下的crewai run命令时遇到了KeyError: 'key_name'错误。

(ai-crew) userk@mycelium:~/development/git/vanto_ai_agents_cornerstone/crewai/latest_ai_development$ crewai runRunning the Crewwarning: `VIRTUAL_ENV=/home/userk/development/venv/ai-crew` does not match the project environment path `.venv` and will be ignoredTraceback (most recent call last):  File "/home/userk/development/git/vanto_ai_agents_cornerstone/crewai/latest_ai_development/.venv/bin/run_crew", line 8, in <module>    sys.exit(run())             ^^^^^  File "/home/userk/development/git/vanto_ai_agents_cornerstone/crewai/latest_ai_development/src/latest_ai_development/main.py", line 13, in run    LatestAiDevelopmentCrew().crew().kickoff(inputs=inputs)    ^^^^^^^^^^^^^^^^^^^^^^^^^  File "/home/userk/development/git/vanto_ai_agents_cornerstone/crewai/latest_ai_development/.venv/lib/python3.12/site-packages/crewai/project/crew_base.py", line 35, in __init__    self.map_all_task_variables()  File "/home/userk/development/git/vanto_ai_agents_cornerstone/crewai/latest_ai_development/.venv/lib/python3.12/site-packages/crewai/project/crew_base.py", line 145, in map_all_task_variables    self._map_task_variables(  File "/home/userk/development/git/vanto_ai_agents_cornerstone/crewai/latest_ai_development/.venv/lib/python3.12/site-packages/crewai/project/crew_base.py", line 178, in _map_task_variables    self.tasks_config[task_name]["agent"] = agents[agent_name]()                                            ^^^^^^^^^^^^^^^^^^^^  File "/home/userk/development/git/vanto_ai_agents_cornerstone/crewai/latest_ai_development/.venv/lib/python3.12/site-packages/crewai/project/utils.py", line 7, in memoized_func    cache[key] = func(*args, **kwargs)                 ^^^^^^^^^^^^^^^^^^^^^  File "/home/userk/development/git/vanto_ai_agents_cornerstone/crewai/latest_ai_development/src/latest_ai_development/crew.py", line 12, in researcher    return Agent(           ^^^^^^  File "/home/userk/development/git/vanto_ai_agents_cornerstone/crewai/latest_ai_development/.venv/lib/python3.12/site-packages/pydantic/main.py", line 212, in __init__    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  File "/home/userk/development/git/vanto_ai_agents_cornerstone/crewai/latest_ai_development/.venv/lib/python3.12/site-packages/crewai/agent.py", line 160, in post_init_setup    if env_var["key_name"] in unnacepted_attributes:       ~~~~~~~^^^^^^^^^^^^KeyError: 'key_name'An error occurred while running the crew: Command '['uv', 'run', 'run_crew']' returned non-zero exit status 1.

这是我的设置:

(ai-crew) userk@mycelium:~/development/git/vanto_ai_agents_cornerstone/crewai/latest_ai_development$ python --versionPython 3.12.3(ai-crew) userk@mycelium:~/development/git/vanto_ai_agents_cornerstone/crewai/latest_ai_development$ pip freeze --local | grep crewaicrewai==0.80.0crewai-tools==0.14.0(ai-crew) userk@mycelium:~/development/git/vanto_ai_agents_cornerstone/crewai/latest_ai_development$ pip -Vpip 24.0 from /home/userk/development/venv/ai-crew/lib/python3.12/site-packages/pip (python 3.12)

我还尝试使用项目目录中创建的虚拟环境,但没有成功。

如何解决这个错误?


回答:

好的,我在agent.py中添加了一个条件检查,只有在key_name存在时才处理它。这样可以防止错误发生,并确保在不需要key_name的设置中保持兼容性。

建议的修复方法:可以在agent.py中添加一个条件检查,只有在key_name存在且有效时才处理它:

if "key_name" in env_var and env_var["key_name"] in unnacepted_attributes:continue

这样可以确保在key_name不存在但对任务不必要时不会发生错误。

我已经创建了一个拉取请求,在这里

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注