ai - crewai 的使用 agent
访问量: 6
refer to: https://github.com/crewaiinc/crewai
安装
uv
uv venv
.\.venv\Scripts\activate
uv pip install 'crewai[tools]' -i https://mirrors.aliyun.com/pypi/simple/
uv add -i https://mirrors.aliyun.com/pypi/simple/ 'crewai[litellm]' (用来支持deepseek)
经验:
每个agent对应一个task
想要执行新的task, 那就创建一个新的agent
可以指定某个agent来运行。(kickoff) 当然了,需要创建对应的 editor_only_crew()方法:
crew.py:
def editor_only_crew(self) -> Crew:
return Crew(
agents=[self.editor_agent()],
tasks=[self.editor_agent_task()],
process=Process.sequential,
verbose=True,
)
main.py 中:result = MyAiVideoCrews().editor_only_crew().kickoff(inputs=inputs)
input中的内容,可以直接在tasks.yml 中直接使用该变量,例如:
inputs = {
"topic": novel_name,
"origin_file_content": origin_file_content,
"comment_file_content": comment_file_content,
"base_file_name": base_file_name,
"script_file_name": os.path.join(output_dir, base_file_name + "_script.txt"),
"output_dir": output_dir
}
对应了:
editor_agent_task:
description: >
请根据小说原文的片段 和 初步的剧本注释,生成script文件,使之适合生成AI插图。
小说原文如下:
```
{origin_file_content}
```
初步的剧本注释如下:
```
{comment_file_content}
```
每次启动时,都要访问:https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json
这个可以先用翻墙工具下载到本地,然后再修改本地源代码,直接读取。
(如果首次启动成功后,会有缓存在本地,后续就算连不上也没事,只会有一个WARNING)