From c1e9d7bcd79f225248d2fd66fcbde920ea3253ee Mon Sep 17 00:00:00 2001 From: Mahesh Kommareddi Date: Sat, 15 Jun 2024 17:32:58 -0400 Subject: [PATCH] Improvements and understandings --- __pycache__/tasks.cpython-310.pyc | Bin 4940 -> 12017 bytes __pycache__/tools.cpython-310.pyc | Bin 0 -> 2978 bytes tasks.py | 275 +++++++++++++++++++++++++++++- tools.py | 68 ++++++++ 4 files changed, 342 insertions(+), 1 deletion(-) create mode 100644 __pycache__/tools.cpython-310.pyc create mode 100644 tools.py diff --git a/__pycache__/tasks.cpython-310.pyc b/__pycache__/tasks.cpython-310.pyc index 4cf7354e1b8123f0d22dc0c94cf150a4fb662f78..abc561a923b3d3cbe0f36288d3036bc6aa57d4c2 100644 GIT binary patch literal 12017 zcmcIq%X8dDdIvBsa5$tW>TSsuYuMGh(IElZXtTJqACD6c84SEyuX!Rh7@BnB8a zFqDamHmS&`q;%WMX6-8J=xa{NEq_BQx!{zlRI1`!l8Uoi8z=VW_jLo9Aw|XBN`=xi z`rRMCSAYF$1Y=`W4S#;gUp@G?ru`!ohW|_yuHhH{*3dMjG2PQTx~=P!H$0w?RlC|5wMS)L5p^}YCi5k4tTS$p%Y50})0wa*WWM6< z?M&K}GH-hO?0s0r^!D5P<@11jKt2!J2l>JEL--wLBacB1KltPbf8nWaALWy*`bf8r z@nh>R+AndPjj|dWdu-Up**HJ2Zm~U=H8vr0dy$)zxqX*4KEWo~B-_spJTBNTvxDpq zJIs!JX0R97QF^uwcI-35eucfrUSh|QJHagWGJ6HNSNSXa1b>yC_^e?6fR8-V?AQ1x z(${$v=^K0;X`R=fyvbgDO0-h>BtMDr5AyO9pF;VyygbdPQGPuyH+Tc(H}difpFz2v zmuLAb%5PGcon%v=YW68M%^G;lu^Bdt=V^9|&Ea{57ujichMnbgeiCnWj-O)ZAD8X3 zyu>cBi~KCR1P+`-ueaD`c7;#zY1wN|_BxMVZ?miXyzF%Wy{@r&cAcN(4cY6o>~#^n z7T7!dqU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A^KgcwMzpd83acf zriog{_fz5J2;2gfhluS6Mpt*%KBK=x(hDFaQ0DYxy+ObHwTmHwt~S@UM>^wA#?_Ip zj;VS$gS_2KmVke&(81Ml9SoMdnD|^8{V6g`6QrGrm!|~qak$xZ9L!(2_hUgI{vZCi{Pp?7veWyL zZ6_7m?tqI!p0$&zZ9^vT@g`;4Sr#^=63M)6J3$aafCI)7x=OeUUY*2cEHDJ8F-oAz z3baLmhapg+p;(qiHB6QwzduQg=oPI-YQ)m#4C}I0&faP{9kX9Ik}BTV9520LN`d#Z Xv}@A3iFGR@^EuvhB;L@fWLf_Ybkibg literal 0 HcmV?d00001 diff --git a/tasks.py b/tasks.py index 4cb5cdd..928f863 100644 --- a/tasks.py +++ b/tasks.py @@ -1,6 +1,8 @@ from celery import Celery -from crewai import Agent, Task, Crew, tasks +from crewai import Process, Agent, Task, Crew, tasks from crewai_tools import SerperDevTool, ScrapeWebsiteTool, SeleniumScrapingTool +from crewai_tools import BaseTool +from tools import MockTool from langchain_openai import ChatOpenAI from pymongo import MongoClient import langchain_core @@ -30,11 +32,282 @@ llm = ChatOpenAI( temperature=0.1 ) +# Example usage +order_details = { + 'customer_id': 1234, + 'items': [ + {'product_id': 'ABC123', 'quantity': 2}, + {'product_id': 'XYZ456', 'quantity': 1} + ] +} + +customer_inquiry = { + 'customer_id': 5678, + 'issue': 'Order status inquiry' +} + +shipping_details = { + 'order_id': 9876, + 'shipping_address': '123 Main St, Anytown USA' +} + +order = { + 'order_details': order_details, + 'customer_inquiry': customer_inquiry, + 'shipping_details': shipping_details +} + # Load tools search_tool = SerperDevTool() scrape_tool = SeleniumScrapingTool() scrape_tool_bare = ScrapeWebsiteTool() +order_management_tool = MockTool() +order_management_tool.set_name("Order Management") +inventory_tool = MockTool() +inventory_tool.set_name("Inventory") +customer_support_tool = MockTool() +customer_support_tool.set_name("Customer Support") +order_tracking_tool = MockTool() +order_tracking_tool.set_name("Order Tracking") +supplier_management_tool = MockTool() +supplier_management_tool.set_name("Supplier Management") +shipping_tool = MockTool() +shipping_tool.set_name("Shipping") +tracking_tool = MockTool() +tracking_tool.set_name("Tracking") + +# Callback functions +def order_callback(output): + if isinstance(output, langchain_core.agents.AgentFinish): + print("Order Agent finished") + elif output and output[0]: + print(output[0]) + if output[0][0]: + print(output[0][0].log) + +def customer_callback(output): + if isinstance(output, langchain_core.agents.AgentFinish): + print("Customer Agent finished") + elif output and output[0]: + print(output[0]) + if output[0][0]: + print(output[0][0].log) + +def inventory_callback(output): + if isinstance(output, langchain_core.agents.AgentFinish): + print("Inventory Agent finished") + elif output and output[0]: + print(output[0]) + if output[0][0]: + print(output[0][0].log) + +def logistics_callback(output): + if isinstance(output, langchain_core.agents.AgentFinish): + print("Logistics Agent finished") + elif output and output[0]: + print(output[0]) + if output[0][0]: + print(output[0][0].log) + +# Define the Order Agent +order_agent = Agent( + role='Order Manager', + goal='Manage and process customer orders efficiently', + backstory=( + "You are the Order Manager at an e-commerce company." + "Your responsibilities include receiving and processing customer orders," + "updating inventory levels, and coordinating with the logistics team for shipping." + "You have access to the company's order management system and inventory database." + ), + tools=[order_management_tool, inventory_tool], + max_rpm=100, + step_callback=order_callback +) + +order_task = Task( + description=( + "Process the incoming customer order." + "Update the inventory levels accordingly." + "Coordinate with the logistics team for shipping." + ), + expected_output="Order processed successfully, inventory updated, and shipping coordinated.", + agent=order_agent +) + +# Define the Customer Agent +customer_agent = Agent( + role='Customer Service Representative', + goal='Provide excellent customer support and resolve inquiries', + backstory=( + "You are a Customer Service Representative at an e-commerce company." + "Your role is to assist customers with their questions, concerns, and complaints." + "You have access to customer order history, product information, and company policies." + ), + tools=[customer_support_tool, order_tracking_tool], + max_rpm=100, + step_callback=customer_callback +) + +customer_task = Task( + description=( + "Respond to the customer inquiry or complaint." + "Provide relevant information, track order status, or escalate the issue if necessary." + ), + expected_output="Customer inquiry resolved or escalated appropriately.", + agent=customer_agent +) + +# Define the Inventory Agent +inventory_agent = Agent( + role='Inventory Manager', + goal='Maintain accurate inventory levels and optimize stock', + backstory=( + "You are the Inventory Manager at an e-commerce company." + "Your responsibilities include monitoring inventory levels, reordering products," + "and ensuring efficient stock management." + "You have access to the company's inventory database and supplier information." + ), + tools=[inventory_tool, supplier_management_tool], + max_rpm=100, + step_callback=inventory_callback +) + +inventory_task = Task( + description=( + "Monitor inventory levels and reorder products as needed." + "Coordinate with suppliers for timely restocking." + "Optimize stock levels based on demand and sales data." + ), + expected_output="Inventory levels optimized, and restocking coordinated with suppliers.", + agent=inventory_agent +) + +# Define the Logistics Agent +logistics_agent = Agent( + role='Logistics Coordinator', + goal='Ensure efficient and timely shipping of orders', + backstory=( + "You are the Logistics Coordinator at an e-commerce company." + "Your role is to manage the shipping process, coordinate with carriers," + "and track shipments to ensure timely delivery." + "You have access to the company's order management system and carrier integrations." + ), + tools=[shipping_tool, tracking_tool], + max_rpm=100, + step_callback=logistics_callback +) + +logistics_task = Task( + description=( + "Coordinate the shipping of the processed order." + "Select the appropriate carrier and shipping method." + "Track the shipment and provide updates to the customer." + ), + expected_output="Order shipped successfully, and tracking information provided to the customer.", + agent=logistics_agent +) + +# Update the Company class +class Company: + def __init__(self): + self.order_agent = order_agent + self.customer_agent = customer_agent + self.inventory_agent = inventory_agent + self.logistics_agent = logistics_agent + + self.order_crew = Crew(agents=[order_agent], tasks=[order_task]) + self.customer_crew = Crew(agents=[customer_agent], tasks=[customer_task]) + self.inventory_crew = Crew(agents=[inventory_agent], tasks=[inventory_task]) + self.logistics_crew = Crew(agents=[logistics_agent], tasks=[logistics_task]) + + def process_order(self, order): + # Execute the order crew with the provided order details + order_result = self.order_crew.kickoff(order_task, order) + return order_result + + def handle_customer_inquiry(self, inquiry): + # Execute the customer crew with the provided inquiry details + inquiry_result = self.customer_crew.kickoff(customer_task, inquiry) + return inquiry_result + + def manage_inventory(self): + # Execute the inventory crew + inventory_result = self.inventory_crew.kickoff(inventory_task) + return inventory_result + + def ship_order(self, order): + # Execute the logistics crew with the provided order details + shipping_result = self.logistics_crew.kickoff(logistics_task, order) + return shipping_result + +company = Company() + +class ManagerTool(BaseTool): + name: str | None = "Manager Tool" + description: str | None = "A tool for the Manager Agent to coordinate other agents and handle business processes." + + # name = "Manager Tool" + # description = "A tool for the Manager Agent to coordinate other agents and handle business processes." + + def _run(self, **kwargs) -> str: + # Parse the argument to determine the requested action + if len(kwargs) > 0: + action = kwargs[0] + + if action == "process_order": + order_details = kwargs.get('order_details', order['order_details']) + result = company.process_order(order_details) + elif action == "handle_inquiry": + customer_inquiry = kwargs.get('customer_inquiry', order['customer_inquiry']) + result = company.handle_customer_inquiry(customer_inquiry) + elif action == "manage_inventory": + result = company.manage_inventory() + elif action == "ship_order": + shipping_details = kwargs.get('shipping_details', order['shipping_details']) + result = company.ship_order(shipping_details) + else: + result = f"The orders and status is: {order}" + + return str(result) + return f"I understand. I have done what is necessary." + +# Define the Manager Agent +manager_agent = Agent( + role="Business Operations Manager", + goal="Coordinate and manage business processes efficiently", + backstory=( + "You are the Business Operations Manager at an e-commerce company." + "Your role is to oversee and coordinate various business processes," + "including order processing, customer support, inventory management, and logistics." + "You have access to a tool that allows you to delegate tasks to specialized agents." + "The agents you can delegate to are order_agent, customer_agent, inventory_agent, and logistics_agent" + ), + tools=[ManagerTool()], + max_rpm=100, +) + +manager_task = Task( + description="Manage and coordinate the appropriate business processes based on the given input.", + expected_output="Business processes executed successfully.", + agent=manager_agent, +) + +project_crew = Crew( + agents=[manager_agent, order_agent, customer_agent, inventory_agent, logistics_agent], + tasks=[manager_task, order_task, customer_task, inventory_task, logistics_task], + manager_llm=ChatOpenAI( + model="amazon-embeddings", + base_url="http://chat.the.mk:1337", + temperature=0.1 + ), # Mandatory for hierarchical process + process=Process.hierarchical, # Specifies the hierarchical management approach + # memory=True, # Enable memory usage for enhanced task execution +) + +# Pass the order_details, customer_inquiry, and shipping_details as arguments to the kickoff method +project_crew.kickoff() + # Function to update task status in MongoDB def update_task_status(task_id, status, message): try: diff --git a/tools.py b/tools.py new file mode 100644 index 0000000..d5a85f3 --- /dev/null +++ b/tools.py @@ -0,0 +1,68 @@ +# tools.py +from crewai_tools import BaseTool + +class MockTool(BaseTool): + name: str | None = "mock_tool" + description: str | None = "useful for when you need to mock a tool" + + def set_name(self, set_name): + self.name = set_name + + def _run(self, **kwargs) -> str: + if len(kwargs) > 0: + argument = kwargs[0] + + # Implementation goes here + if self.name == "Order Management": + return self._handle_order_management(argument) + elif self.name == "Customer Support": + return self._handle_customer_support(argument) + elif self.name == "Inventory": + return self._handle_inventory(argument) + elif self.name == "Supplier Management": + return self._handle_supplier_management(argument) + elif self.name == "Shipping": + return self._handle_shipping(argument) + elif self.name == "Tracking": + return self._handle_tracking(argument) + else: + return f"Mock output from {self.name} tool for query: {argument}" + else: + return f"Ran the action successfully" + + + def _handle_order_management(self, argument): + if "get order details" in argument.lower(): + return "Mock order details: [{'product_id': 'ABC123', 'quantity': 2}, {'product_id': 'XYZ456', 'quantity': 1}], Delivery Address: 123 Main St, Anytown USA" + else: + return f"Mock output from Order Management tool for query: {argument}" + + def _handle_customer_support(self, argument): + if "customer inquiry" in argument.lower(): + return "Mock customer inquiry: Order status inquiry" + else: + return f"Mock output from Customer Support tool for query: {argument}" + + def _handle_inventory(self, argument): + if "check stock levels" in argument.lower(): + return "Mock stock levels: Product ABC123 - 100 units, Product XYZ456 - 50 units" + else: + return f"Mock output from Inventory tool for query: {argument}" + + def _handle_supplier_management(self, argument): + if "check recent orders" in argument.lower(): + return "Mock recent orders: Product ABC123 - 500 units ordered from Supplier A, Product XYZ456 - 200 units ordered from Supplier B" + else: + return f"Mock output from Supplier Management tool for query: {argument}" + + def _handle_shipping(self, argument): + if "check shipping options" in argument.lower(): + return "Mock shipping options: Standard (5-7 business days), Express (2-3 business days)" + else: + return f"Mock output from Shipping tool for query: {argument}" + + def _handle_tracking(self, argument): + if "track shipment" in argument.lower(): + return "Mock tracking information: Order ABC123XYZ, Shipped via Express, Estimated Delivery: 2023-06-10" + else: + return f"Mock output from Tracking tool for query: {argument}" \ No newline at end of file