AI知识库

53AI知识库

学习大模型的前沿技术与行业应用场景


人工智能中的多智能体实践综合指南
发布日期:2024-08-19 05:43:17 浏览次数: 1651


定义并建立一个智能体团队,以完善您的求职简历和求职信。

AI智能体是2024年AI社区中最热门的主题之一,这是有充分理由的。基础模型在 推理 和 计划。有了这些功能,我们就可以利用LLM将给定的任务分成较小的部分,逐步执行它们并反思其结果,从而从根本上创造 AI代理商

如果您对AI充满热情,或者喜欢玩语言模型,或者正在从事机器学习, 如果您想跟上最新的AI成就,则必须全面了解AI代理及其作用方式。

如果您像我一样在求职过程中,,您知道,为您申请的每份工作写求职信或调整简历以查明工作要求是乏味的一步。为了实施AI代理,我将建立一个AI代理团队 协作以:

  • 提取 职位描述中的关键信息

  • 修改 您的简历和求职信以解决工作

  • 评估 从招聘人员的角度来看最终结果,并给您0到100的分数




在本文中,我们将探讨什么是协作AI智能体,是什么使智能体与LLM不同,,并通过实际实现来展示如何创建AI智能体可能比您预期的要简单得多。

AI智能体变得简单

AI智能体是一种面向目标的工具,旨在完成一组特定的任务。创建AI语言模型以生成针对特定提示的响应时,AI智能体通过决策和任务执行来解决复杂的问题,从而在更广泛的范围内运行。他们根据任务进行推理,并使用其可用工具执行较小的议程以完成任务。

AI聊天机器人说话,AI智能体行动。

无论是在客户服务,财务还是软件开发中,AI智能体都是出于一件事: 自动化。希望人工智能智能体能够帮助个人和组织进行平凡的例行工作,从而以更低的成本解决创意性较差的议程。


LLM支持的AI代理


即使AI智能体与大型语言模型有很大不同, LLM是我们AI智能体的大脑。代理商需要LLM明智地做任何事情,推理并计划下一步。这意味着您使用的LLM会完全改变代理的行为。这就是为什么Gen-AI激增使AI智能体主题兴起的原因。

Nte: 我们今天听到的AI代理与传统文学和教科书的含义有所不同。如果您只是在搜索AI代理,并且对他们的含义有不同的定义,这可能会令人困惑。我们今天使用的AI代理是AI社区的热门话题,是我们在本文中讨论的基于LLM的代理。





自主AI智能体的核心是三个组成部分:

  1. 规划: 智能体的这种核心功能使其可以将目标分解为较小的步骤并逐个处理。他们计划的另一个方面是 自我反思采取行动并向他们学习。智能体实现自我反思的方式在很大程度上取决于实现,但是可以考虑总体轮廓,如图4所示。

  2. 内存: 要从过去的错误中学习,您必须记住它们。内存是智能体存储和以后检索信息以完善其操作的组成部分。

  3. 工具用途: 简单的LLM和AI智能体之间的关键区别因素是它们使用工具的能力。使用工具就像调用API一样简单,或者使用Python函数读取或写入某些文件一样简单。



多智能体协作

有什么比单个智能体更好? 多智能体!

拥有一个AI智能体是一回事,但是拥有多个相互协作以完成任务并对其采取行动的AI智能体是另一回事。

但是为什么我们 需要 多个智能体?

当将目标分解为较小的部分时,您最终会获得需要不同技能的子目标。那是您需要多个智能体的地方。一个由智能体组成的团队,每个智能体都有特定的角色和技能,可确保每个子目标都由其自己的智能体解决。

您甚至可能需要为每个智能体提供不同的LLM,该LLM对于该智能体分配的任务更为复杂。为编程功能创建的智能体可能需要与应该写文章的智能体完全不同的LLM。


什么才是智能体

如何定义智能体很大程度上取决于您使用的实现或库。通常,智能体归结为三个主要元素:


  1. 目标: 智能体商旨在实现的特定目标。这塑造了其决策框架。例如,“编写易于理解的面向对象的Python代码。”

  2. 角色: 智能体的功能。是谁呀? 调试器,数据科学家,销售营销人员等。

  3. 背景故事: 智能体的上下文。解释目标,角色以及代理人的擅长之处。背景故事的一个例子是“您是高级Python程序员,擅长编写优化的,有据可查的代码及其测试用例。”

实现多智能体的条件是什么

多智能体的实现细节需要考虑一些细微差别。想象一下一个朝着同一目标努力的团队,一个餐厅厨房的厨师团队就是一个例子。

您将需要一位主厨来领导团队。团队成员需要相互交流。您需要他们能够将完成的工作发送给其他厨师,以进行下一步的食品准备。这只是制作多个智能体需要多少东西的一个示例 协作以共享任务。

通常,使用多个智能体,您将需要:

  1. 共享信息: 智能体需要将结果相互传递并分享他们的发现。座席的完成工作可能是另一个座席开始其任务的输入。

  2. 合作: 智能体应该能够使用彼此的帮助,并在需要时委派部分工作。在简单的情况下,这可能不是必须的,但是在复杂的过程中,这是非常必要的。

  3. 经理智能体管理员: 控制智能体之间的任务流程,使其保持控制状态。


代码实现:帮助您申请工作的智能体

现在,让我们创建我们的智能体团队。有多个库可让您开发AI智能体,例如 LlamaIndex 或 CrewAI。我会用 CrewAI 易于使用的工作流程和高抽象水平。它是免费使用的,同时可以充分控制您的智能体,从而使您免于简单项目中不必要的复杂性。

我将创建一个智能体团队,以帮助我为给定的职位描述修改简历和求职信,以评估最终结果并查看我将有多少机会 接受采访。为此,我将创建 四个 智能体:

  1. 求职者: 该智能体将接收职位发布的URL,爬取网页并提取有关职位要求,资格等的关键信息。

  2. 简历修改器: 根据Job Crawler提供的有关工作的关键信息,该代理人阅读我的简历并对其进行增强,以更好地适应职位描述。

  3. 求职信修改器: 这与CV修饰符相同,但可以在求职信上使用。

  4. 招聘人员: 担任招聘人员,并分析我修改后的简历和求职信。它会给我反馈,并且得分在[ 0 – 100 ]范围内。

对于LLM,我们将使用 gpt-4-turbo 。但是,使用Ollama可以运行LLM 100%本地 和 免费。我不会在本文中详细介绍,而是默认读者知道如何运行 Qwen, LLama-3Mistral, Phi-3。


接下来,我将加载 OPENAI_API_KEY 并初始化我 model。该模型是我们智能体推理的基础:

from dotenv import load_dotenvfrom crewai import Agent, Task, Crew, Processfrom langchain_openai import ChatOpenAIfrom langchain.tools import toolimport re
# Load your OPENAI_API_KEY from your .env fileload_dotenv()
# The model for the agentsmodel = ChatOpenAI(model_name="gpt-4-turbo", temperature=0.8)

我们还需要定义两个 工具 我们的代理商需要使用的。工具是智能体用来执行某些任务的工具。为智能体编写自定义工具就像Python函数一样简单。您需要做的就是用langchain的工具装饰器包裹它。我们为该项目所需的工具是一种用于通过给定URL获取页面内容的工具,另一种用于读取页面内容的工具 CV.pdf 和 Cover Letter.pdf 内容。

from langchain_community.document_loaders import PyMuPDFLoaderimport requests
# Tool for loading and reading a PDF locally@tooldef fetch_pdf_content(pdf_path: str): """ Reads a local PDF and returns the content """ loader = PyMuPDFLoader(pdf_path) data = loader.load()[0] return data.page_content
# Tool for loading a webpage@tooldef get_webpage_contents(url: str): """ Reads the webpage with a given URL and returns the page content """ try: response = requests.get(url) response.raise_for_status() # Check for HTTP errors return response.text except requests.exceptions.RequestException as e: return str(e)

准备好我的模型和所需的工具,接下来就是定义我的智能体。CrewAI中的智能体需要三个主要属性,即 角色目标, 和 背景故事。对于每个智能体,我们将指定一组所需的工具。智能体也可以选择将其部分任务委托给其他智能体,但是由于该项目并不那么复杂,因此我们设置 allow_delegation 对我们所有的智能体都是错误的。

job_crawler = Agent(    role='Job Description Crawler',    goal='Extract the relevant job description, requirements and qualificiations',    backstory='Specialized in parsing HTML and retrieving important information from it',    verbose=True,    tools=[get_webpage_contents],    allow_delegation=False,    llm=model)
cv_modifier = Agent( role='CV/Resume Writer', goal='Write a top-notch CV that increases the chance of landing an interview', backstory='Expert in writing CV that is best recieved by the recruiting team and HR', verbose=True, tools=[fetch_pdf_content], allow_delegation=False, llm=model)
cover_letter_modifier = Agent( role='Cover Letter Writer', goal='Write an intriguing cover letter that boosts the chance of landing an interview', backstory='Expert in writing Cover Letter that is best recieved by the recruiting team and HR', verbose=True, tools=[fetch_pdf_content], allow_delegation=False, llm=model)
recruiter = Agent( role='Hiring Manager', goal='Analyze how well a candidate is suited for a job description, given their CV and Cover Letter', backstory='Experienced hiring manager with an especialization of giving feedback to job seekers', verbose=True, allow_delegation=False, llm=model)

现在我们需要列出我们的任务。任务是您希望特定智能体执行的特定工作。我将为每个智能体分配一个任务。我将解释我的任务的描述,以及我希望任务输出的具体方式。

def extract_job_information(page_url):    return Task(        description=f"Given this url: {page_url}, extract the job description, and relative information about the job",        agent=job_crawler,        expected_output="Key points of the job description, requirements, and qualifications needed for the job",    )
def cv_modifying(cv_path): return Task( description=f"Read the CV at this local path: {cv_path}, then\ modify the keypoints and the order of the skills, to make it emphasize what is needded by the job.\ Do NOT add any extra skill or new information, keep it honest.", agent=cv_modifier, expected_output="A modified version of CV, tailor-made for the job description", )
def cover_letter_modifying(cv_path): return Task( description=f"Read the cover letter at this local path: {cv_path},\ then baseed on the provided job description by 'job_crawler' agent, \ modify it to make it target the provided job description. Fill in the empty brackets with the company name.\ Do NOT add any extra skill or new information, keep it honest.", agent=cover_letter_modifier, expected_output="A modified version of cover letter, tailor-made for the job description", )
evaluate = Task( description=f"Provided the modified CV and Cover Letter, and the key points of the job description,\ give a score to the candidate from 0-100, based on how well suited they are for this job", agent=recruiter, expected_output="Score in the range [0-100]", )

请注意,其中一些任务取决于另一个任务的输出。例如,我需要修改后的简历和求职信来评估它们。而且我也无法修改简历和求职信,除非 求职者 智能体已成功从网页中提取了作业信息。

不过,您必须意识到,最终您将从外部网站内容中提取关键工作信息。在将此类工具用于个人或商业用途时,最好牢记网站的权利/版权。

CrewAI通过确保代理彼此共享所需信息来自动解决此问题。

剩下的就是创建我的特工团队,然后开始他们!

# USER INPUTScover_letter_path = r'Cover Letter.pdf'cv_path = r'CV.pdf'job_url = [www.job.com]
extract_job_information_task = extract_job_information(job_url)cv_modifying_task = cv_modifying(cv_path)cover_letter_modifying_task = cover_letter_modifying(cover_letter_path)
# make the crewcrew = Crew( agents=[job_crawler, cv_modifier, cover_letter_modifier, recruiter], tasks=[ extract_job_information_task, cv_modifying_task, cover_letter_modifying_task, evaluate ], verbose=2)
# Let's start!result = crew.kickoff()

此代码块使用户输入所需文件和网页的路径。然后,我将使用我之前定义的代理和任务来创建我的工作人员,然后将他们踢开!

结果是我们智能体的所有思维过程和结果的长输出。为了简短起见,我将对我的思考过程进行抽样 Cover Letter Modifier 智能体:


> Entering new CrewAgentExecutor chain...I need to read the content of the cover letter from the provided PDF file to understand its structure and content. This will help modify it according to the job description.
Action: fetch_pdf_contentAction Input: {"pdf_path": "Cover Letter.pdf"}
Dear Hiring Manager, [Original cover letter, excluded for brevity]Sincerely,

Thought:Now I have the content of the original cover letter. I need to tailor this cover letter to specifically address the job opening at Huawei's AI4Sec Research Team. I will adjust the content to highlight relevant experiences and skills that align with the job description provided.
Final Answer:Dear Hiring Manager,[Modified cover letter, excluded for brevity]Sincerely,

您可以自己查看智能体的原因,确定需要做什么并使用手头的工具执行。

我们每个智能体完成任务后,我们都可以看到他们的输出以及他们的表现。

您可以看到,求职信修改器智能体已成功完善了我的求职信以适合职位描述,甚至添加了职位描述中强调的一些要点。但是,简历修改器智能体的输出有些令人难以置信,需要对其智能体和任务定义进行一些调整。

招聘人员智能体还浏览了我修改后的简历和求职信,并分配了 92/100:

Based on the detailed review of Hesam Sheikh Hassani’s CV and 
Cover Letter in relation to the key points of the job description
for the AI Researcher position at [Excluded Intentionally], I would score the candidate
a 92 out of 100. Hesam exhibits a strong academic and professional
background in Artificial Intelligence, particularly in machine learning
and deep learning, which aligns well with the requirements of the
[Excluded Intentionally] Research Team at [Excluded Intentionally].

His experience with Large Language Models (LLMs) and his ability to
communicate complex AI concepts effectively, as demonstrated through
his engagement on social media and articles, are particularly impressive
and directly relevant to the position. His technical proficiency with tools
critical for the role, such as Git, Linux, Python, and advanced
machine learning algorithms, further strengthens his candidacy.

Hesam's previous roles and projects, such as the Agricultural Sorting Machine
at PFK and his work on AI-on-Demand platforms, showcase his leadership skills
and his capability to manage and execute AI projects, which is essential for
the role at [Excluded Intentionally]. His expressed eagerness to contribute to and learn from
[Excluded Intentionally]’s research initiatives, along with his alignment with [Excluded Intentionally]’s core
values of continuous improvement, AI integrity, and inclusiveness, make
him a strong fit culturally and professionally for the position.

His immediate availability and willingness to relocate also add to his
suitability for the role, ensuring a smooth transition and immediate
contribution to the team. Thus, given Hesam Sheikh Hassani’s strong
alignment with both the technical and cultural aspects of the AI
Researcher position at [Excluded Intentionally],
he is highly recommended for this role with a score of 92.

AI智能体修改简历和求职信的示例用例只是强调我们如何使用AI自动化重复性任务并作为教育示例的范围。如果您想在实践中使用此类工具,最好记住一些限制:

  • AI生成的简历或求职信可能被视为 红色标志 由招聘人员。招聘经理可能会使用AI检测工具来消除此类候选应用程序。

  • 诸如ChatGPT之类的AI工具仍然陷入 简历语言。简历中AI的某些书写风格和单词选择很容易检测。诸如“ delve ”或“ spearhead ”之类的词可能会发出AI生成的文本。这种书写风格可能会使您的简历听起来不真实且不相关。

  • AI聊天机器人和LLM遭受 幻觉。在此示例中,幻觉可能意味着将经验和技能放入您实际上并不拥有但受职位描述启发的求职信和简历中。仔细检查您的简历/求职信是否有任何不切实际的修改。

牢牢把握LLM可以做的事情,会使公司和专家处于优越的地位。AI智能体就是其中一种令人着迷的功能。在本文中,我们探讨了AI智能体是什么,它与LLM有何不同, 以及我们如何通过几行代码实现它们以自动化我们的重复任务。


参考:https://hesamsheikh.substack.com/p/a-comprehensive-guide-to-collaborative?publication_id=2366930&post_id=146261089&isFreemail=true&r=1g4rup&triedRedirect=true


53AI,企业落地应用大模型首选服务商

产品:大模型应用平台+智能体定制开发+落地咨询服务

承诺:先做场景POC验证,看到效果再签署服务协议。零风险落地应用大模型,已交付160+中大型企业

联系我们

售前咨询
186 6662 7370
预约演示
185 8882 0121

微信扫码

与创始人交个朋友

回到顶部

 
扫码咨询