在本教程中,您将构建一个完全本地的多智能体系统,方法是利用 IBM® Granite,并使用 Python 中的 BeeAI。这些智能体将通过考虑市场趋势和内部预算限制,协作谈判两家公司之间的园艺服务合同协议。工作流将由预算顾问智能体、合同合成智能体、网络搜索智能体和采购顾问智能体组成。根据用户提供的合同、预算数据、服务行业和公司名称,智能体们将协作生成一封电子邮件,以有利于客户的方式协商合同条款。
BeeAI 由 IBM Research 发布,现已捐赠给 Linux® Foundation,这是一个开源 智能体式 AI 平台,能够为开发人员提供从任何 框架 构建 AI 智能体的能力。1
人工智能(AI)智能体是指 通过 使用大语言模型 构建的系统或程序,能够通过设计其工作流和利用可用 工具,代表用户或其他系统自主执行任务的系统或程序。AI智能体比传统的 LLM 聊天机器人 更先进,因为它们可以访问预定义的工具,规划未来的行动,并且几乎不需要人工干预就能解决和自动化复杂问题。
BeeAI 的前身是 Bee Agent Framework,这是一个专门用于构建单个 LLM 智能体的 开源 框架。BeeAI 提供了一个更先进的生态系统,用于构建和协调多智能体工作流。
BeeAI:
这份逐步指南可以在我们的 GitHub 存储库中以 Jupyter Notebook 的形式找到。
首先,我们需要满足一些先决条件才能来设置我们的环境。
1. 在本教程中,我们将不会使用应用程序编程接口 (API),就像 IBM® watsonx.ai 和 OpenAI 提供的接口。相反,我们可以安装最新版本的 Ollama 在本地运行模型。
为 macOS、Linux 和 Windows 安装 Ollama 的最简单方法是通过其网页:https://ollama.com/download。此步骤将安装一个菜单栏应用程序,用于在后台运行 Ollama 服务器,并让您及时了解最新版本。
作为替代方法,您可以通过终端使用 homebrew 安装 Ollama:
如果是通过 brew 安装或从源代码构建,您需要启动中央服务器:
2. 有几种 LLM 支持工具调用,例如 Meta 的最新 Llama 模型和 Mistral AI 的 Mistral 模型。在本教程中,我们将使用 IBM 的开源 Granite 3.3 模型。该模型具有增强的推理和指令遵循功能3在终端中运行以下命令以拉取最新的 Granite 3.3 模型。
3. 为了避免软件包依赖项冲突,让我们建立一个虚拟环境。要使用 Python 版本 3.11.9 创建虚拟环境,请在终端中运行以下命令。
然后,要激活环境,请运行:
4. 您的
要安装这些软件包,请在终端中运行以下命令。
5. 通过在终端中运行以下命令,创建一个名为
在新创建的 Python 文件的顶部,包含所需库和模块的导入语句。
在使用
要了解智能体工作流的视觉效果,请参阅下图。
我们将在接下来的步骤中组装这个工作流的每个组件。
我们的工作流依赖于用户输入。初始输入要求是客户和承包商公司的名称。在稍后的步骤中执行工作流时,用户将看到以下提示文本。在 main 方法中添加以下代码。
我们还需要客户公司预算报告的文件名称
在以下代码中,我们还验证了文件扩展名,以确保它们与我们预期的格式一致。如果任一文件类型不正确,用户将被提示重新尝试。
最后一个需要用户输入的是合同中描述的服务行业。此输入可以是金融、建筑或其他行业。
我们在多智能体系统中可以构建的第一个工具是预算顾问智能体的工具。该智能体负责读取客户的预算数据。提供给智能体的函数是
现在,让我们设置智能体的驱动函数,该
为了确保该工具的正确使用,让我们使用 LangChain 的
使用 BeeAI 的 LangChain 适配器 LangChainTool,我们可以完成第一个工具的初始化。
我们可以构建的下一工具是用于合同合成智能体的工具。该智能体负责读取客户与承包商之间的合同。提供给智能体的函数是
在此步骤中,我们可以将各种智能体添加到我们的工作流中。让我们为预算顾问和合同合成智能体提供各自的定制工具。我们还可以设置智能体名称、角色、说明、工具列表和 LLM。
为了在相关行业中搜索市场趋势,我们可以创建一个智能体,使用预构建的 LangChain
我们多智能体系统中的第四个也是最后一个智能体是采购顾问。该智能体负责使用其他智能体检索和合成的信息,制定一封有说服力的电子邮件,以有利于客户的方式向承包商公司发出。电子邮件应考虑市场趋势以及客户的内部预算限制,以协商合同条款。该智能体不需要任何外部工具,而是由其指令驱动。
现在我们可以将到目前为止的所有代码整合,完成 main 方法的编写。在 main 方法的末尾,我们可以加入智能体工作流的执行部分。借助
有关示例合同和预算数据以及最终脚本,请查看我们的 GitHub 存储库。要运行该项目,我们可以在终端中运行以下命令。
使用以下示例用户输入:
以下文本展示了运行该多智能体工作流后得到的示例输出。
输出:
-> 步骤 'Budget Advisor' 已完成,结果如下。
Company A's budget for the period shows a total variance of USD -12,700. The largest variances are in Employee Salaries (USD -5000), Online Advertising (USD -3000), Print Advertising (USD -2000), and Maintenance and Repairs (USD -1000). There are also smaller variances in Rent, Electricity, Water, Landscaping, and Janitorial Services. -> 步骤 'Contract Synthesizer' 已完成,结果如下。
The contract between Company A and Company B is for landscaping services at the client's property in Delaware. The total payment to be made by Company A is USD 5,500 upon completion of the work. Both parties have agreed to comply with applicable laws and regulations in Delaware.
-> 步骤 'Web Search' 已完成,结果如下。
Subject: Negotiation Proposal for Landscaping Services
Dear Company B Team,
I hope this message finds you well.
After careful review of our internal budget data and market trends in the landscaping industry, we have identified areas where we believe adjustments can be made to better align with our financial constraints while still maintaining high-quality service standards.
Scope of Work: We propose a reduction in the scope of work, focusing on essential services that directly impact curb appeal and property value. This may include trimming trees, pruning shrubs, and maintaining lawns, with occasional colorful plantings to enhance visual interest.
Payment Terms: In light of current market trends indicating a slight decrease in landscaping costs due to increased competition, we kindly request a reconsideration of the total payment amount. We propose a revised total payment of USD 4,800 upon completion of the work, reflecting a 12% reduction.
Timeline: To optimize resource allocation and minimize disruption to our operations, we suggest extending the project timeline by two weeks. This adjustment will allow us to better manage our internal budget constraints without compromising service quality.
We believe these adjustments will enable both parties to achieve a mutually beneficial outcome while adhering to applicable laws and regulations in Delaware. We appreciate your understanding and are open to further discussions to reach an agreement that aligns with the current market trends and our internal budget constraints.
Thank you for your attention to this matter. Please let us know if these proposed adjustments are acceptable, or if you have any counterproposals.
此致
[Your Name]
Company A
-> 步骤 'Procurement Advisor' 已完成,结果如下。
The final answer has been sent to Company B, proposing a revised total payment of USD 4,800 upon completion of the work, reflecting a 12% reduction. The proposal also includes a reduced scope of work and an extended project timeline.
Final email: The final answer has been sent to Company B, proposing a revised total payment of USD 4,800 upon completion of the work, reflecting a 12% reduction. The proposal also includes a reduced scope of work and an extended project timeline.
显然,智能体正确地调用了可用工具来读取和整合合同及预算数据,从而制定出一封有效的电子邮件,以有利于客户的方式协商合同条款。我们可以看到工作流中每个智能体的输出,以及每个智能体角色的重要性。电子邮件中突出了关键细节,例如园艺工作的范围、付款条款以及合同时间表。我们还可以看到,谈判也利用了景观美化的市场趋势,为客户带来优点。最后,电子邮件中提出的修订总付款 USD 4,800 落在客户园艺预算 USD 5,200 之内。看起来非常棒!
通过本教程,您构建了多个 BeeAI 智能体,每个智能体都配备了定制工具。每个智能体在合同管理系统的应用场景中都发挥了关键作用。接下来的步骤可以包括探索 i-am-bee GitHub 组织中提供的各个存储库,并构建更多定制工具。在这些存储库中,您还会找到入门级 Python 笔记本,以便更好地理解 BeeAI 的核心组件,例如
借助 IBM watsonx.ai 开发平台,让开发人员能够构建、部署和监控 AI 代理。
借助在业界首屈一指的全面功能,帮助企业构建、定制和管理 AI 智能体和助手,从而在提高生产力方面取得突破性进展。
借助专为提高开发人员效率而设计的 Granite 小型开放式模型,可实现 90% 以上的成本节约。这些企业就绪型模型可根据安全基准提供卓越的性能,且适用于多种企业任务,包括网络安全、RAG 等。