Building a Supply Chain Agent with CrewAI: Simplifying RFQ Creation and Carrier Comparison Without Writing Much Code
2025 is shaping up to be the year of AI agents, and CrewAI offers an excellent platform for diving into this exciting field. Whether you're a seasoned developer or just starting out, CrewAI provides a user-friendly environment where you can explore and prototype your agent ideas with minimal coding. Key Features of CrewAI Built for: Agent Teamwork Key Concept: Role-Based Collaboration CrewAI allows you to define various "roles," such as Developer, Analyst, and Editor, each equipped with its own specialized skills and personality. These agents can communicate and collaborate to accomplish complex tasks. Project Overview: Building a Supply Chain Agent For this project, we will build a 2-agent system designed to handle key aspects of supply chain management. Specifically, these agents will create Request for Quotes (RFQs) and compare different carriers to make the best choice. This setup can significantly streamline the decision-making process and improve efficiency. Part 1: Setting Up the Environment Step 1: Install Python and Uv Package Manager First, ensure that Python is installed on your system. CrewAI is a Python framework, so having Python set up is essential. Next, install the Uv package manager. This tool helps manage dependencies and installations for CrewAI. sh $ pip install uv Step 2: Install CrewAI Once Uv is installed, use it to install CrewAI. sh $ uv install CrewAI Step-by-Step Guide 1. Define the Roles In CrewAI, roles are central to agent collaboration. For our supply chain project, we will define two roles: Developer: Responsible for generating RFQs. Analyst: Responsible for comparing carrier quotes and making the best selection. 2. Set Up the Agents Create agent configurations for the Developer and Analyst roles. These configurations will specify the tasks each agent will perform and how they will interact. ```python from crewai import Agent, Role Define the Developer role developer_role = Role(name="Developer", description="Responsible for creating RFQs") Define the Analyst role analyst_role = Role(name="Analyst", description="Responsible for comparing carrier quotes and making the best choice") Instantiate the agents developer_agent = Agent(role=developer_role) analyst_agent = Agent(role=analyst_role) ``` 3. Task Definition Define the specific tasks for each agent. The Developer will generate RFQs, and the Analyst will compare the responses. ```python Task for Developer: Generate RFQ rfq_task = Task( name="Generate RFQ", description="Create a comprehensive Request for Quote document for shipping.", inputs=["product_details", "shipping_requirements"], outputs=["rfq_document"] ) Task for Analyst: Compare Carrier Quotes comparison_task = Task( name="Compare Carrier Quotes", description="Evaluate quotes from different carriers and select the most cost-effective one.", inputs=["carrier_quotes"], outputs=["best_choice"] ) ``` 4. Interaction Between Agents Set up the interaction between the Developer and Analyst agents. The Developer will generate the RFQ, and the Analyst will receive the quotes to compare. ```python Developer generates the RFQ rfq_document = developer_agent.run_task(rfq_task, product_details="example_product", shipping_requirements="example_shipping") Analyst receives carrier quotes and makes the best choice carrier_quotes = ["carrier1_quote", "carrier2_quote", "carrier3_quote"] # Example quotes best_choice = analyst_agent.run_task(comparison_task, carrier_quotes=carrier_quotes) ``` Testing the System To ensure everything is working as expected, you can test the system with sample data. This will help you validate the interactions and fine-tune the agents' behaviors. ```python Sample product details and shipping requirements product_details = { "product_name": "Widget", "quantity": 100, "dimensions": "10x10x10 inches", "weight": "5 lbs" } shipping_requirements = { "delivery_location": "New York, NY", "delivery_date": "2025-06-15", "preferred_carriers": ["FedEx", "UPS", "DHL"] } Run the Developer agent rfq_document = developer_agent.run_task(rfq_task, product_details=product_details, shipping_requirements=shipping_requirements) print("Generated RFQ Document:", rfq_document) Sample carrier quotes carrier_quotes = [ {"carrier": "FedEx", "price": "$150", "delivery_time": "5 days"}, {"carrier": "UPS", "price": "$140", "delivery_time": "7 days"}, {"carrier": "DHL", "price": "$160", "delivery_time": "4 days"} ] Run the Analyst agent best_choice = analyst_agent.run_task(comparison_task, carrier_quotes=carrier_quotes) print("Best Choice:", best_choice) ``` Conclusion By using CrewAI, you can quickly build and test a 2-agent system for supply chain management. The Developer and Analyst agents work together to generate RFQs and select the best carrier, demonstrating the power of role-based collaboration in AI. This project serves as a solid foundation for further exploration and development in the realm of AI agents.