In this tutorial, you will build a fully local multi-agent system with IBM® Granite® by using BeeAI in Python. These agents will collaborate to negotiate a contractual agreement for landscaping services between two companies by taking into account market trends and internal budget constraints. The workflow will be composed of a budget advisor agent, contract synthesizer agent, web search agent and procurement advisor agent. Given the contract, budget data, service industry and company names provided by the user, the agents collaborate to produce an email to negotiate the terms of the contract in favor of the client.
BeeAI, released by IBM Research® and now donated to the Linux® Foundation, is an open-source agentic AI platform that provides developers with the ability to build AI agents from any framework.1
An artificial intelligence (AI) agent refers to a system or program built by using a large language model (LLM) to autonomously perform tasks on behalf of a user or another system by designing its workflow and by using utilizing available tools. AI agents are more advanced than traditional LLM chatbots as they can access predefined tools, plan future actions and require little to no human intervention to solve and automate complex problems.
The predecessor of BeeAI is the Bee Agent Framework, an open source framework specific to building single LLM agents. Conversely, BeeAI provides a more advanced ecosystem to build and orchestrate multi-agent workflows.
BeeAI is:
This step-by-step guide can be found on our GitHub repository in the form of a Jupyter Notebook.
We first need to set up our environment by fulfilling some prerequisites.
1. In this tutorial, we will not be using an application programming interface (API) like the ones available through IBM® watsonx.ai® and OpenAI. Instead, we can install the latest version of Ollama to run the model locally.
The simplest way to install Ollama for macOS, Linux and Windows is through their webpage: https://ollama.com/download. This step will install a menu bar app to run the Ollama server in the background and keep you up to date with the latest releases.
As an alternative, you can install Ollama with Homebrew in your terminal:
If installing from brew, or building from source, you need to boot the central server:
2. There are several LLMs that support tool calling such as Meta’s latest Llama models and Mistral AI’s Mistral models. For this tutorial, we will use IBM’s open source Granite 3.3 model. This model features enhanced reasoning and instruction-following capabilities.3 Pull the latest Granite 3.3 model by running the following command in your terminal.
3. To avoid package dependency conflicts, let's set up a virtual environment. To create a virtual environement with Python version 3.11.9, run the following command in your terminal.
Then, to activate the environment, run:
4. Your
To install these packages, run the following command in your terminal.
5. Create a new Python file entitled
At the top of the fresh Python file, include the import statements for the necessary libraries and modules.
In an asynchronous main method using
For a visual of the agentic workflow, refer to the following diagram.
We will assemble each component of this workflow in the following steps.
Our workflow relies on user input. The initial inputs required are the names of both the client and contractor companies. The user will be prompted with the following text upon execution of the workflow in a later step. Add the following code to the main method.
We will also need the names of the files containing the client company's budget report,
In the following code, we also verify the file extensions to help ensure that they align with our anticipated format. If either file is the incorrect file type, the user will be prompted to try again.
The last user input required is the industry of the service described in the contract. This input can be finance, construction or others.
The first tool that we can build in our multi-agent system is for the budget advisor agent. This agent is responsible for reading the client's budget data. The function provided to the agent is
Now, let's set up the driving force of the agent, the
To help ensure the appropriate usage of this tool, let's use LangChain's
Using BeeAI's LangChain adapter, LangChainTool, we can finalize the initialization of our first tool.
The next tool that we can build is for the contract synthesizer agent. This agent is responsible for reading the contract between the client and contractor. The function provided to the agent is
In this step, we can add the various agents to our workflow. Let's provide the budget advisor and contract synthesizer agents with their corresponding custom tools. We can also set the agent name, role, instructions, list of tools and LLM.
To search the web for market trends in the relevant industry, we can create an agent with access to the prebuilt LangChain
The fourth and final agent in our multi-agent system is the procurement advisor. This agent is responsible for using the information retrieved and synthesized by the other agents to formulate a convincing email to the contractor company in favor of the client. The email should consider market trends and the client's internal budget constraints to negotiate the terms of the contract. This agent does not require any external tools but rather, is driven by its instructions.
We can now finalize our main method with all of our code so far. At the tail end of the main method, we can include the agentic workflow execution. Given the
For a sample contract and budget data as well as the final script, check out our GitHub repository. To run the project, we can run the following command in our terminal.
Use this sample user input:
The following text depicts example output that we received from running this multi-agent workflow.
Output:
-> Step 'Budget Advisor' has been completed with the following outcome.
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. -> Step 'Contract Synthesizer' has been completed with the following outcome.
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.
-> Step 'Web Search' has been completed with the following outcome.
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.
Best regards,
[Your Name]
Company A
-> Step 'Procurement Advisor' has been completed with the following outcome.
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.
Evidently, the agents correctly invoked their available tools to read and synthesize the contract and budget data to then formulate an effective email in which the terms of the contract are negotiated in favor of the client. We can see the output of each agent within the workflow and the importance of each agent's role. Key details such as the scope of landscaping work, payment terms and the contract timeline are highlighted in the email. We can also see that the negotiation utilizes market trends in landscaping to the client's benefit as well. Finally, the revised total payment of USD 4,800 proposed in the email falls within the client's landscaping budget of USD 5,200. This looks great!
With this tutorial, you built several BeeAI agents, each with custom tools. Each agent played a critical role in the contract management system use case. Some next steps can include exploring the various GitHub repositories available in the i-am-bee GitHub organization and building more custom tools. In the repositories, you will also find starter Python notebooks to better understand the core components of BeeAI such as
Easily design scalable AI assistants and agents, automate repetitive tasks and simplify complex processes with IBM® watsonx Orchestrate™.
Create breakthrough productivity with one of the industry's most comprehensive set of capabilities for helping businesses build, customize and manage AI agents and assistants.
Achieve over 90% cost savings with Granite's smaller and open models, designed for developer efficiency. These enterprise-ready models deliver exceptional performance against safety benchmarks and across a wide range of enterprise tasks from cybersecurity to RAG.