跟着我的步骤,轻松打造出 AI 智能体

简介: 跟着我的步骤,轻松打造出 AI 智能体

crewAI 是一个开源框架,可以编排角色扮演的 AI 智能体,通过促进协作使这些 AI 智能体无缝衔接,处理复杂问题。了解详情,可点击此链接。

本文采用的 crewAI 版本为 v0.22.5,废话不多说,直接盘它。

安装

pip install crewai

如果原来已经安装过,可以使用如下命令进行更新:

pip install --upgrade crewai

创建项目

v0.22.5 版本已经支持使用命令 crewai create 项目名称 创建项目。

例如,我们的本地工作目录为 PythonProjects,要创建的项目为 crewai_labs,就可以这样进行安装:

cd PythonProjects
crewai create crewai_labs

执行成功,结果如下所示:

Creating folder crewai_labs...
  - Created crewai_labs/.gitignore
  - Created crewai_labs/pyproject.toml
  - Created crewai_labs/README.md
  - Created crewai_labs/src/crewai_labs/__init__.py
  - Created crewai_labs/src/crewai_labs/main.py
  - Created crewai_labs/src/crewai_labs/crew.py
  - Created crewai_labs/src/crewai_labs/tools/custom_tool.py
  - Created crewai_labs/src/crewai_labs/tools/__init__.py
  - Created crewai_labs/src/crewai_labs/config/agents.yaml
  - Created crewai_labs/src/crewai_labs/config/tasks.yaml
Crew crewai_labs created successfully!

安装项目依赖

根据生成文件 crewai_labs/README.md 中说明安装即可。

5eb58f4b8077cefa868e254b8a82ad7e.png

  1. 确保系统上安装了 Python 版本在 3.10 到 3.13 之间;
  2. 项目使用 Poetry 进行依赖管理;
pip install poetry
  1. poetry.lock 文件
cd crewai_labs
poetry lock
  1. 安装依赖
cd crewai_labs
poetry install
  1. 新增 .env 文件
// 框架默认使用的是 GPT-4,后面会讲解如何自定义配置 LLM
OPENAI_API_KEY=xxx

项目运行

cd crewai_labs
poetry run crewai_labs

输出信息:

// 信息太多,我就不贴了,如果出现了错误,能一眼就能看出发生了错误。

官方示例在未修改的情况下,运行完毕后会在项目根目录创建一个名为 report.md 的文件,内容是关于大型语言模型(LLMs)研究的输出结果。

我本地运行成功后生成的 report.md 内容如下:

# AI Large Language Models (LLMs): A Comprehensive Report 
## Introduction
AI LLMs are machine learning models that use large volumes of data to understand and generate human language. They are increasingly being used across a wide range of industries, transforming how we translate languages, create content, analyze data, and more. Recent developments, like OpenAI's GPT-3, have resulted in models capable of generating contextually relevant texts and performing tasks such as translating languages, writing essays, answering trivia questions, and even writing poetry.
## Specific Use Cases
AI LLMs are being deployed across various sectors, each with unique applications. In healthcare, they are used for predicting patient outcomes, diagnosing diseases, and personalizing treatment plans. Finance sees its utilization for fraud detection, credit scoring, and algorithmic trading. Meanwhile, the retail sector leverages AI LLMs for demand forecasting, customer segmentation, and personalized marketing. Notably, in the automotive industry, they are integral to the development of autonomous vehicles.
## Ethical Concerns
Despite the advantages, AI LLMs present a range of ethical challenges and bias concerns. AI systems may perpetuate existing biases if trained on biased data, leading to unfair outcomes in applications like hiring or lending. Privacy concerns also exist, as AI systems often require access to large amounts of data, potentially including sensitive personal information. Accountability issues arise as well, as it can be challenging to determine responsibility when an AI system causes harm.
## Future Trends
The future of AI LLMs technology is promising. Current trends point towards more transparent AI systems that can explain their decisions, a concept known as explainable AI. There is also a growing interest in federally learning, allowing AI models to learn from decentralized data sources while preserving privacy. Research is also underway to improve the efficiency of AI models, enabling them to provide more accurate predictions with less data and computational resources.
## Market Analysis
The AI LLMs market is competitive, with key players like IBM, Google, Amazon, and Microsoft at the forefront. These companies compete based on the accuracy of their AI models, diversity of applications, and user-friendly interfaces. Partnerships are also a common strategy to enhance offerings, such as IBM's collaboration with Apple to develop healthcare applications.
## Notable Achievements
There have been many groundbreaking achievements in AI LLMs. Google's AI model, AlphaGo, defeated the world champion in the game of Go, signifying a significant milestone in AI development. OpenAI's GPT-3 has showcased impressive capabilities in natural language understanding and generation. In the medical field, several models have demonstrated performance on par with or superior to human experts for medical diagnoses.

核心文件

  • src/crewai_labs/config/agents.yaml,在这里定义 Agents。
  • src/crewai_labs/config/tasks.yaml,在这里定义 Tasks。
  • src/crewai_labs/crew.py,在这里定义自己的逻辑、工具和参配。
  • src/crewai_labs/main.py,在这里定义自己的输入信息。

每个文件的内容,都比较简单,大家可以看一下 ~

主要做了一件什么事?输入一个{主题}(框架中默认主题为:AI LLMs),然后输出一份报告。

框架定义了两个 Agent:

研究人员

  • 角色:{主题} 高级数据研究员
  • 目标:揭示{主题}领域的前沿发展
  • 背景:您是一位经验丰富的研究员,擅长发掘{主题}领域的最新进展。您以能够找到最相关的信息并以清晰、简洁的方式呈现而闻名。
  • 任务:对{主题}进行全面研究 确保在2024年当前的情况下,找到任何有趣且相关的信息。
  • 预期输出:一个包含关于{主题}最相关信息的10个要点的列表。

报告分析师

  • 角色:{主题} 报告分析师
  • 目标:根据{主题}数据分析和研究发现创建详细报告
  • 背景:您是一位注重细节的分析师,对细节有敏锐的洞察力。您以将复杂数据转化为清晰、简洁的报告而闻名,使他人能够轻松理解和根据您提供的信息采取行动。
  • 任务:审查你所获得的背景信息,并将每个主题扩展成一个报告的完整部分。确保报告详细且包含所有相关信息。
  • 预期输出:一份完整的报告,包含主要主题,每个主题都有一个完整的信息部分。以markdown格式呈现,不使用 '```' 符号。

这的核心是提示词!在 .yaml 文件中,按照规范定义提示词即可。

小结

看到这,估计大家都有了自己的想法,知道 crewAI 框架到底是干什么的了。它可以使 AI 代理能够承担角色,可以共享目标,就像一个精密运作的团队一样,共同为一个目标而努力。

个人认为,多智能体协作平台做出的东西可以颠覆目前很多的单智能体应用,好好进行任务编排,大有可为。

目录
相关文章
|
3天前
|
机器学习/深度学习 人工智能 弹性计算
基于OpenAPI和AI coding的上云智能体构建实践
本文探讨了基于LLM和AI编程技术构建上云智能体的实践,提出通过人在回路中设计整体流程、LLM自主决策与执行的方式,有效减少幻觉并提升任务正确率。方案在多轮迭代中逐步生成代码,解决了API参数依赖等问题,并验证了三大核心设计理念的可行性。
基于OpenAPI和AI coding的上云智能体构建实践
|
19天前
|
人工智能 Java 程序员
搭建AI智能体的Java神器:Google ADK深度解析
想用Java构建复杂的AI智能体?Google开源的ADK工具包来了!代码优先、模块化设计,让你像搭积木一样轻松组合智能体。从单体到多智能体系统,从简单工具到复杂编排,这篇文章带你玩转Java AI开发的全新境界。
88 1
|
4天前
|
人工智能 IDE API
还在配置规则文件和智能体?Roo Commander:预置90+领域专家,开箱即用的AI编程新体验
Roo指挥官是一款创新AI编程助手,通过智能调度90多位虚拟技术专家,实现对复杂项目的自主规划与高效执行。用户无需手动选择专家或反复调整提示,只需提交需求,系统即可自动分析、拆解任务并协调最合适的技术角色完成开发。文中以构建3D互动简历为例,展示了其从需求分析到项目落地的全流程自动化能力,显著提升开发效率,开启AI驱动的智能化编程新体验。
26 0
|
16天前
|
人工智能 持续交付 开发工具
AI大模型运维开发探索第五篇:GitOps 智能体
本文探讨了如何结合 Manus 的智能体设计理念与 GitOps 持续集成技术,构建低成本、高扩展性的智能体系统。通过借鉴 Manus 的沙箱机制与操作系统交互思路,利用 Git 作为智能体的记忆存储与任务调度核心,实现了推理过程可视化、自进化能力强的智能体架构。文章还分享了具体落地实践与优化经验,展示了其与 Manus 相当的功能表现,并提供了开源代码供进一步探索。
169 21
|
22天前
|
人工智能 自然语言处理 搜索推荐
蚂蚁百宝箱体验:如何快速创建“旅游小助手”AI智能体
蚂蚁百宝箱作为站式智能体应用开发平台,致力于为AI开发者提供**简单、高效、快捷**的智能体创作体验。作为业内领先的AI应用开发平台,开发者可以根据自身的个性化需求,基于各式各样的大模型来创建一个属于自己的智能体应用。
118 40
|
4天前
|
存储 人工智能 自然语言处理
AI智能体从请求到响应,这系统过程中究竟藏着什么?
三桥君带你深入解析AI智能体从用户请求到生成响应的全流程,涵盖接入服务、智能体应用、知识检索、模型重排、LLM调用与工具执行等关键技术环节,揭开AI背后的运作原理。
42 2
|
5天前
|
数据采集 数据可视化 定位技术
阿里云百炼智能体与工作流深度联动,打造更灵活的AI+流程开发体验
阿里云百炼平台推出智能体与工作流相互调用功能,支持四种灵活嵌套模式,提升复杂业务流程的复用与自动化能力。通过组件化封装,用户可在智能体中调用工作流,或在工作流中嵌套智能体,显著提高开发效率与系统灵活性,适用于不同技术水平的开发者。
70 0
阿里云百炼智能体与工作流深度联动,打造更灵活的AI+流程开发体验