Notebooks
M
MongoDB
Agentic System Enhanced Contract And Supply Chain Management For International Shipping

Agentic System Enhanced Contract And Supply Chain Management For International Shipping

agentsgravity9artificial-intelligencellmspartnersmongodb-genai-showcasegenerative-airag

Use Case: Enhanced Contract and Supply Chain Management for International Shipping

Open In Colab

Watch the Webinar

Objective: Streamline operations, improve customer service, and optimize supply chain management for a shipping company through an AI-driven agent that uses Retrieval-Augmented Generation (RAG) architecture, MongoDB Atlas, and Large Language Models (LLMs).

Solution Overview

In international shipping, contracts are highly detailed, covering clauses for tariffs, insurance, timelines, and penalties. Supply chain operations add another layer of complexity, with inventory management, route optimization, and partner collaboration essential to efficient delivery. Departments across the company—operations, customer service, legal, and supply chain—need quick access to accurate information.

TODO: Place image of solution here

AI Agent Solution

Leveraging RAG architecture, MongoDB Atlas, and LLMs, the proposed AI agent enables users to query both contract and supply chain data in natural language. This agent would:

  1. Retrieve Relevant Contract and Supply Chain Data: MongoDB Atlas stores complex contract documents, shipment details, inventory levels, routing data, and supplier agreements. The RAG architecture allows the agent to retrieve relevant information based on user queries, even across multiple databases if needed.

  2. Generate Natural Language Responses: The LLM synthesizes and presents the retrieved information in a clear, user-friendly way, so non-technical employees can get precise answers quickly.

Use Case Examples

  • Operational Efficiency: An operations manager could ask, "What penalties apply if shipment delays impact our Asia-Europe supply route?" The agent retrieves contract clauses and relevant shipping timelines to provide a direct answer.

  • Customer Service: A representative could inquire, "What are the customs requirements for electronics shipped to Canada?" The agent quickly identifies key contract clauses to ensure accurate, compliant responses.

  • Supply Chain Optimization: A supply chain manager could ask, "What inventory do we have in transit to Europe, and are there any delays?" The agent accesses real-time shipment and inventory data to provide a summary of items en route and any expected disruptions.

  • Supplier Collaboration: If a manager asks, "What are the penalties if our supplier delays the shipment?" the agent pulls clauses from the supplier contracts and any penalties that may affect downstream partners or delivery timelines.

  • Shipment Status Update: An operations coordinator could instruct, "Update the status of Shipment SHP-2024-001 to 'Delayed' and notify relevant stakeholders." The agent records the status change in the database, notifies impacted teams, and logs the delay along with any penalties or updated timelines, ensuring that all parties have real-time visibility of the shipment status and potential impacts.

Benefits for Supply Chain Operations

Efficency and Productivity Gains

This solution minimizes the time and effort involved in searching through contracts, shipment records, and inventory databases. With natural language querying, supply chain managers, operations staff, and other departments can access critical information quickly, leading to faster decision-making, optimized routes, timely inventory management, and improved overall service quality.

image.png

Part 1: Semantic Search and RAG Implementation

image.png

Install Libaries and Set Environment Variables

[3]
[2]

Step 1: Data Loading (L)

[4]

Step 2: Embedding Generation (L)

[5]
Enter your VoyageAI API key: ··········
[6]
[7]
[8]
[9]
100%|██████████| 200/200 [00:54<00:00,  3.68it/s]
[10]
[11]

Step 3: MongoDB (Operational and Vector Database) (R)

MongoDB acts as both an operational and a vector database for the RAG system. MongoDB Atlas specifically provides a database solution that efficiently stores, queries and retrieves vector embeddings.

Creating a database and collection within MongoDB is made simple with MongoDB Atlas.

  1. First, register for a MongoDB Atlas account. For existing users, sign into MongoDB Atlas.
  2. Follow the instructions. Select Atlas UI as the procedure to deploy your first cluster.

Follow MongoDB’s steps to get the connection string from the Atlas UI. After setting up the database and obtaining the Atlas cluster connection URI, securely store the URI within your development environment.

[12]
Enter your MONGO URI: ··········
[13]
[14]
Connection to MongoDB successful
[15]
DeleteResult({'n': 0, 'electionId': ObjectId('7fffffff0000000000000038'), 'opTime': {'ts': Timestamp(1731599723, 1), 't': 56}, 'ok': 1.0, '$clusterTime': {'clusterTime': Timestamp(1731599723, 1), 'signature': {'hash': b',\x9czar\x84\xaf\xb5fL\xa74\xa7\xbb\xa9r9j>\xc4', 'keyId': 7390008424139849730}}, 'operationTime': Timestamp(1731599723, 1)}, acknowledged=True)

Step 4: Data Ingestion (R)

[16]
Data ingestion into MongoDB completed

Step 5: Vector Index Creation (R)

[17]
[18]
[19]
[20]
[21]
Creating index 'vector_index'...
Waiting for 30 seconds to allow index 'vector_index' to be created...
30-second wait completed for index 'vector_index'.
'vector_index'

Step 6: Vector Search Function (R)

[22]

Step 7: Semantic Search (R)

[23]

Step 8: Retrieval Augmented Generation(RAG) (L)

[24]
Enter your Anthropic API key: ··········
[25]
[26]
[27]
[28]
Based on the shipping contract details provided, the shipment that is relevant to the question about customs requirements for toys shipped to Canada is:

Contract Number: SHP-2024-0196
Origin: Port of Santos, Brazil
Destination: Port of Vancouver, Canada 
Goods Description: Toys
Customs and Compliance: Shipper responsible for US customs; receiver for destination customs

For this shipment to Canada, the key customs requirement is that the receiver (Aguilar, Hunt and Villanueva) is responsible for handling the customs clearance and any applicable duties and taxes when the toys arrive in Canada. 

Some general requirements for toy imports into Canada include:
- Toys must meet Canadian safety standards and labeling requirements
- Toys require a commercial invoice, cargo control document, and certificate of origin
- Duties and taxes like GST apply based on the toy's tariff classification and value
- Certain toy materials like wood or textiles may require additional permits or certificates
- Using a licensed customs broker is recommended to ensure compliance

However, the specific customs procedures and paperwork would need to be confirmed with Canada Border Services Agency and the receiver's customs broker, as requirements can vary based on the exact type of toy, materials, country of origin, and shipment value. The shipper should work closely with the receiver to provide all required information.

Part 2: Making Things Agentic (L)

image.png

What you are building

image.png

[29]

Enabling LangSmith for tracing (Optional)

[30]
Enter Langsmith API Key··········
[31]

MongoDB LangGraph Checkpointer (R)

[32]

Step 1: Create Tools (R)

Let's remind ourselves of the use cases and scenarios

  1. Operational Efficiency: An operations manager could ask, "What penalties apply if shipment delays impact our Asia-Europe supply route?" The agent retrieves contract clauses and relevant shipping timelines to provide a direct answer.

  2. Customer Service: A representative could inquire, "What are the customs requirements for electronics shipped to Canada?" The agent quickly identifies key contract clauses to ensure accurate, compliant responses.

  3. Supply Chain Optimization: A supply chain manager could ask, "What inventory do we have in transit to Europe, and are there any delays?" The agent accesses real-time shipment and inventory data to provide a summary of items en route and any expected disruptions.

  4. Supplier Collaboration: If a manager asks, "What are the penalties if our supplier delays the shipment?" the agent pulls clauses from the supplier contracts and any penalties that may affect downstream partners or delivery timelines.

  5. Shipment Status Update: An operations coordinator could instruct, "Update the status of Shipment SHP-2024-001 to 'Delayed' and notify relevant stakeholders." The agent records the status change in the database, notifies impacted teams, and logs the delay along with any penalties or updated timelines, ensuring that all parties have real-time visibility of the shipment status and potential impacts.

Scenario 1, 2, 3 and 4 can be achieved with a tool that searched the collection using hybird search

Scenario 5 can be achieved with a tool that updates the status field within a document in the collection

Create Collection Search Tool

[33]
[34]
[35]
Search index 'text_search_index' created successfully
'text_search_index'
[36]
[37]
<ipython-input-37-4a0fd1527de9>:3: LangChainDeprecationWarning: The method `BaseRetriever.get_relevant_documents` was deprecated in langchain-core 0.1.46 and will be removed in 1.0. Use :meth:`~invoke` instead.
  hybrid_search_result = hybrid_search.get_relevant_documents(query)
[Document(metadata={'_id': '67361d6f96963026f329b2fc', 'Contract Number': 'SHP-2024-0022', 'Effective Date': '2024-12-01', 'Shipper': 'Walker-Dillon', 'Receiver': 'Henry, Scott and Brown', 'Goods Description': 'Toys', 'Quantity': '421 units', 'Total Weight': '2564 kg', 'Value': '$860070 USD', 'Shipping Method': 'Air Freight', 'Origin': 'Port of Dubai, UAE', 'Destination': 'Port of Tokyo, Japan', 'Estimated Delivery Date': '2024-09-28', 'Total Shipping Cost': '$98622 USD', 'Payment Schedule': '60% upfront, 40% after 30 days of delivery', 'Insurance Coverage': 'Yes', 'Insurance Value': '$924834 USD', 'Liability': 'Loss during transit only', 'Penalty for Late Delivery': '$6336 per week of delay', 'Grace Period': '7 days', 'Customs and Compliance': 'Shipper responsible for US customs; receiver for destination customs', 'Termination Notice': '15 days with mutual consent', 'Jurisdiction': 'Germany', 'Arbitration Location': 'Dubai, UAE', 'Inventory Status': 'In Transit', 'Current Transit Status': 'Delayed', 'vector_score': 0.01639344262295082, 'rank': 0, 'fulltext_score': 0, 'score': 0.01639344262295082}, page_content='delicate machinery'),
 Document(metadata={'_id': '67361d6f96963026f329b379', 'Contract Number': 'SHP-2024-0147', 'Effective Date': '2024-07-14', 'Shipper': 'Morrow-Wilson', 'Receiver': 'Thomas-Duncan', 'Goods Description': 'Toys', 'Quantity': '2906 units', 'Total Weight': '1913 kg', 'Value': '$862579 USD', 'Shipping Method': 'Air Freight', 'Origin': 'Port of Tokyo, Japan', 'Destination': 'Port of Singapore, Singapore', 'Estimated Delivery Date': '2024-09-06', 'Total Shipping Cost': '$35698 USD', 'Payment Schedule': '60% upfront, 40% after 30 days of delivery', 'Insurance Coverage': 'Yes', 'Insurance Value': '$159451 USD', 'Liability': 'Full liability up to maximum contract value', 'Penalty for Late Delivery': '$2457 per week of delay', 'Grace Period': '7 days', 'Customs and Compliance': 'Third-party customs broker required', 'Termination Notice': 'Immediate for breach', 'Jurisdiction': 'India', 'Arbitration Location': 'Sao Paulo, Brazil', 'Inventory Status': 'Awaiting Customs Clearance', 'Current Transit Status': 'Delayed', 'vector_score': 0.016129032258064516, 'rank': 1, 'fulltext_score': 0, 'score': 0.016129032258064516}, page_content='fragile goods'),
 Document(metadata={'_id': '67361d6f96963026f329b38f', 'Contract Number': 'SHP-2024-0169', 'Effective Date': '2024-07-11', 'Shipper': 'Mcintosh-Carpenter', 'Receiver': 'Garcia Group', 'Goods Description': 'Toys', 'Quantity': '2262 units', 'Total Weight': '7635 kg', 'Value': '$806060 USD', 'Shipping Method': 'Road Freight', 'Origin': 'Port of Melbourne, Australia', 'Destination': 'Port of Le Havre, France', 'Estimated Delivery Date': '2024-07-14', 'Total Shipping Cost': '$54969 USD', 'Payment Schedule': '60% upfront, 40% after 30 days of delivery', 'Insurance Coverage': 'Yes', 'Insurance Value': '$530148 USD', 'Liability': 'Loss during transit only', 'Penalty for Late Delivery': '$1164 per week of delay', 'Grace Period': '7 days', 'Customs and Compliance': 'Third-party customs broker required', 'Termination Notice': '90 days for strategic contracts', 'Jurisdiction': 'Australia', 'Arbitration Location': 'London, UK', 'Inventory Status': 'Awaiting Customs Clearance', 'Current Transit Status': 'On Schedule', 'vector_score': 0.015873015873015872, 'rank': 2, 'fulltext_score': 0, 'score': 0.015873015873015872}, page_content='delicate machinery'),
 Document(metadata={'_id': '67361d6f96963026f329b3aa', 'Contract Number': 'SHP-2024-0196', 'Effective Date': '2024-06-02', 'Shipper': 'Smith-Monroe', 'Receiver': 'Aguilar, Hunt and Villanueva', 'Goods Description': 'Toys', 'Quantity': '1499 units', 'Total Weight': '1375 kg', 'Value': '$32231 USD', 'Shipping Method': 'Rail Freight', 'Origin': 'Port of Santos, Brazil', 'Destination': 'Port of Vancouver, Canada', 'Estimated Delivery Date': '2024-06-26', 'Total Shipping Cost': '$21845 USD', 'Payment Schedule': '30% upfront, 70% on delivery', 'Insurance Coverage': 'Yes', 'Insurance Value': '$590538 USD', 'Liability': 'Damage liability only, no theft coverage', 'Penalty for Late Delivery': '$6267 per week of delay', 'Grace Period': '7 days', 'Customs and Compliance': 'Shipper responsible for US customs; receiver for destination customs', 'Termination Notice': '90 days for strategic contracts', 'Jurisdiction': 'China', 'Arbitration Location': 'Sydney, Australia', 'Inventory Status': 'Awaiting Customs Clearance', 'Current Transit Status': 'On Schedule', 'vector_score': 0.015625, 'rank': 3, 'fulltext_score': 0, 'score': 0.015625}, page_content='high value electronics'),
 Document(metadata={'_id': '67361d6f96963026f329b387', 'Contract Number': 'SHP-2024-0161', 'Effective Date': '2024-06-20', 'Shipper': 'Bennett, Reynolds and Gibson', 'Receiver': 'Barrera-Martin', 'Goods Description': 'Toys', 'Quantity': '1039 units', 'Total Weight': '4839 kg', 'Value': '$152943 USD', 'Shipping Method': 'Air Freight', 'Origin': 'Port of Santos, Brazil', 'Destination': 'Port of Valencia, Spain', 'Estimated Delivery Date': '2024-12-29', 'Total Shipping Cost': '$67659 USD', 'Payment Schedule': '30% upfront, 70% on delivery', 'Insurance Coverage': 'Yes', 'Insurance Value': '$809475 USD', 'Liability': 'Loss or damage up to insured value', 'Penalty for Late Delivery': '$5464 per week of delay', 'Grace Period': '7 days', 'Customs and Compliance': 'Shipper responsible for US customs; receiver for destination customs', 'Termination Notice': '45 days', 'Jurisdiction': 'Japan', 'Arbitration Location': 'New York, NY', 'Inventory Status': 'Pending Dispatch', 'Current Transit Status': 'On Schedule', 'vector_score': 0.015384615384615385, 'rank': 4, 'fulltext_score': 0, 'score': 0.015384615384615385}, page_content='bulk order'),
 Document(metadata={'_id': '67361d6f96963026f329b340', 'Contract Number': 'SHP-2024-0090', 'Effective Date': '2024-10-24', 'Shipper': 'Hudson Inc', 'Receiver': 'Mcdonald, Allen and Hardy', 'Goods Description': 'Toys', 'Quantity': '2424 units', 'Total Weight': '9635 kg', 'Value': '$317790 USD', 'Shipping Method': 'Air Freight', 'Origin': 'Port of Dubai, UAE', 'Destination': 'Port of Singapore, Singapore', 'Estimated Delivery Date': '2024-05-22', 'Total Shipping Cost': '$62033 USD', 'Payment Schedule': 'Full payment on delivery', 'Insurance Coverage': 'Yes', 'Insurance Value': '$739599 USD', 'Liability': 'Loss, damage, or theft up to insured value', 'Penalty for Late Delivery': '$3528 per week of delay', 'Grace Period': '7 days', 'Customs and Compliance': 'Third-party customs broker required', 'Termination Notice': '60 days', 'Jurisdiction': 'India', 'Arbitration Location': 'New York, NY', 'Inventory Status': 'In Transit', 'Current Transit Status': 'Delayed', 'vector_score': 0.015151515151515152, 'rank': 5, 'fulltext_score': 0, 'score': 0.015151515151515152}, page_content='climate-sensitive items'),
 Document(metadata={'_id': '67361d6f96963026f329b35e', 'Contract Number': 'SHP-2024-0120', 'Effective Date': '2024-02-14', 'Shipper': 'Robles, Hunt and James', 'Receiver': 'Serrano, Bradshaw and Garner', 'Goods Description': 'Toys', 'Quantity': '1588 units', 'Total Weight': '783 kg', 'Value': '$703309 USD', 'Shipping Method': 'Ocean Freight', 'Origin': 'Port of Melbourne, Australia', 'Destination': 'Port of Cape Town, South Africa', 'Estimated Delivery Date': '2024-08-01', 'Total Shipping Cost': '$96190 USD', 'Payment Schedule': '30% upfront, 70% on delivery', 'Insurance Coverage': 'Yes', 'Insurance Value': '$931746 USD', 'Liability': 'Loss during transit only', 'Penalty for Late Delivery': '$8656 per week of delay', 'Grace Period': '7 days', 'Customs and Compliance': 'Third-party customs broker required', 'Termination Notice': 'Immediate for breach', 'Jurisdiction': 'Japan', 'Arbitration Location': 'Sydney, Australia', 'Inventory Status': 'Delivered', 'Current Transit Status': 'On Schedule', 'vector_score': 0.014925373134328358, 'rank': 6, 'fulltext_score': 0, 'score': 0.014925373134328358}, page_content='climate-sensitive items'),
 Document(metadata={'_id': '67361d6f96963026f329b37a', 'Contract Number': 'SHP-2024-0148', 'Effective Date': '2024-11-08', 'Shipper': 'Santos, Jones and Shelton', 'Receiver': 'French PLC', 'Goods Description': 'Toys', 'Quantity': '2006 units', 'Total Weight': '2311 kg', 'Value': '$603218 USD', 'Shipping Method': 'Air Freight', 'Origin': 'Port of Tokyo, Japan', 'Destination': 'Port of Vancouver, Canada', 'Estimated Delivery Date': '2024-07-06', 'Total Shipping Cost': '$95084 USD', 'Payment Schedule': 'Full payment on delivery', 'Insurance Coverage': 'Yes', 'Insurance Value': '$749543 USD', 'Liability': 'Loss or damage up to insured value', 'Penalty for Late Delivery': '$9850 per week of delay', 'Grace Period': '7 days', 'Customs and Compliance': 'Handled by receiver', 'Termination Notice': '45 days', 'Jurisdiction': 'United Kingdom', 'Arbitration Location': 'London, UK', 'Inventory Status': 'Awaiting Customs Clearance', 'Current Transit Status': 'On Schedule', 'vector_score': 0.014705882352941176, 'rank': 7, 'fulltext_score': 0, 'score': 0.014705882352941176}, page_content='medical equipment'),
 Document(metadata={'_id': '67361d6f96963026f329b3a3', 'Contract Number': 'SHP-2024-0189', 'Effective Date': '2024-05-04', 'Shipper': 'Lucas-Robles', 'Receiver': 'Fields, Davis and Clark', 'Goods Description': 'Toys', 'Quantity': '3511 units', 'Total Weight': '2309 kg', 'Value': '$41496 USD', 'Shipping Method': 'Air Freight', 'Origin': 'Port of Miami, USA', 'Destination': 'Port of Le Havre, France', 'Estimated Delivery Date': '2024-07-22', 'Total Shipping Cost': '$27273 USD', 'Payment Schedule': '20% upfront, 80% on delivery', 'Insurance Coverage': 'Yes', 'Insurance Value': '$92318 USD', 'Liability': 'Loss or damage up to insured value', 'Penalty for Late Delivery': '$6649 per week of delay', 'Grace Period': '7 days', 'Customs and Compliance': 'Third-party customs broker required', 'Termination Notice': '60 days', 'Jurisdiction': 'Australia', 'Arbitration Location': 'Mumbai, India', 'Inventory Status': 'Pending Dispatch', 'Current Transit Status': 'On Schedule', 'vector_score': 0.014492753623188406, 'rank': 8, 'fulltext_score': 0, 'score': 0.014492753623188406}, page_content='non-hazardous material'),
 Document(metadata={'_id': '67361d6f96963026f329b393', 'Contract Number': 'SHP-2024-0173', 'Effective Date': '2024-02-18', 'Shipper': 'Dean, Huff and Harrell', 'Receiver': 'Leonard, Campbell and Richardson', 'Goods Description': 'Toys', 'Quantity': '3107 units', 'Total Weight': '356 kg', 'Value': '$707196 USD', 'Shipping Method': 'Road Freight', 'Origin': 'Port of Dubai, UAE', 'Destination': 'Port of Tokyo, Japan', 'Estimated Delivery Date': '2024-12-30', 'Total Shipping Cost': '$41294 USD', 'Payment Schedule': '60% upfront, 40% after 30 days of delivery', 'Insurance Coverage': 'Yes', 'Insurance Value': '$680742 USD', 'Liability': 'Damage liability only, no theft coverage', 'Penalty for Late Delivery': '$7963 per week of delay', 'Grace Period': '7 days', 'Customs and Compliance': 'Third-party customs broker required', 'Termination Notice': '60 days', 'Jurisdiction': 'Japan', 'Arbitration Location': 'Mumbai, India', 'Inventory Status': 'Pending Dispatch', 'Current Transit Status': 'On Schedule', 'vector_score': 0.014285714285714285, 'rank': 9, 'fulltext_score': 0, 'score': 0.014285714285714285}, page_content='long-distance transport')]
[79]

Create Field Update Tool

[80]

Create Inventory and Transit Status Tool

  1. Inventory Status:

This represents the current handling or processing state of the shipment within a supply chain or logistics facility. It indicates whether the shipment is physically in storage, undergoing customs checks, waiting for a clearance, or already delivered.

  1. Current Transit Status:

This indicates the current progress or issues regarding the actual movement of the shipment between the origin and the destination.

[81]
[82]

Get Real Time News On Particular Shippment (Optional)

[83]
[44]
Enter your Tavily API Key: ··········
[45]
Enter your Cohere API Key: ··········
[84]
[85]
Get real-time news about Rail Freight disruptions, customs issues at Port of Santos, Brazil, port congestion at Port of New York, USA or Port of Santos, Brazil, and logistics or supply chain issues related to shipping Clothing from Port of New York, USA to Port of Santos, Brazil.
[{'content': 'Brazil Port Congestion: Calls: Santos: Container Ships data is updated weekly, averaging 38.000 Unit from Jan 2022 (Median) to 28 Oct 2024, with 144 observations. | Brazil Port Congestion: Calls: Ilheus: Dry Breakbulk (Unit) | 1.000 13 May 2024 | weekly | 14 Mar 2022 - 13 May 2024 | | Brazil Port Congestion: Calls: Santos: Dry Bulk (Unit) | 20.000 04 Nov 2024 | weekly | 31 Jan 2022 - 04 Nov 2024 | | Brazil Port Congestion: Calls: Vila Do Conde: Other Markets (Unit) | 3.000 04 Nov 2024 | weekly | 07 Mar 2022 - 04 Nov 2024 | | Brazil Port Congestion: Calls: Manaus: Dry Breakbulk (Unit) | 1.000 07 Oct 2024 | weekly | 07 Mar 2022 - 07 Oct 2024 |', 'score': 0.7756048, 'origin': 'local'}, {'content': 'Brazil Port Congestion: Calls: Santos: Container Ships data is updated weekly, averaging 38.000 Unit from Jan 2022 (Median) to 28 Oct 2024, with 144 observations. | Brazil Port Congestion: Calls: Ilheus: Dry Breakbulk (Unit) | 1.000 13 May 2024 | weekly | 14 Mar 2022 - 13 May 2024 | | Brazil Port Congestion: Calls: Santos: Dry Bulk (Unit) | 20.000 04 Nov 2024 | weekly | 31 Jan 2022 - 04 Nov 2024 | | Brazil Port Congestion: Calls: Vila Do Conde: Other Markets (Unit) | 3.000 04 Nov 2024 | weekly | 07 Mar 2022 - 04 Nov 2024 | | Brazil Port Congestion: Calls: Manaus: Dry Breakbulk (Unit) | 1.000 07 Oct 2024 | weekly | 07 Mar 2022 - 07 Oct 2024 |', 'score': 0.7756048, 'origin': 'foreign'}, {'content': "Brazil Port Congestion / Delay Status Data - GoComet Our port congestion report is a data-driven tool that can help you calculate how much of a congestion your shipment will experience based on the specific port in the Brazil where it's due to arrive or depart from. To avoid congestion, businesses can use GoComet's real-time port congestion tool to know live status of port situation in Brazil. Supported by\xa0GoComet platform’s real-time container tracking\xa0data, our machine learning algorithm calculates congestion/delays at ports based on the turnaround times of these containers at a given arrival/departure port. GoComet’s port congestion data gives real-time visibility over port congestion that uses a combination of multiple sources such as AIS data, geofencing around ports and live container events data – collected from over 45000 containers tracked every month.", 'score': 0.7136312, 'origin': 'foreign'}, {'content': 'Santos Port struggles to encourage railway solutions for container transport - DatamarNews HomeNewsSantos Port struggles to encourage railway solutions for container transport Santos Port struggles to encourage railway solutions for container transport It is necessary to bring together concessionaires and independent railway operators with container port operators,” he adds. On the other hand, Ivam Jardim believes that the Port of Santos, which handles high-value-added cargo, cannot primarily focus on railways as the primary option because container transportation requires more agility, making road transport ideal for it. “Moreover, for container operations to be efficient in the railway mode, complex works would be necessary in the Serra do Mar mountain range, which is not financially feasible, precisely due to the low capacity to capture this cargo compared to road transport competition,” he argues.', 'score': 0.5532941, 'origin': 'local'}, {'content': 'long-distance transport', 'score': 0.033336826, 'origin': 'local'}, {'content': 'automotive parts', 'score': 0.021125192, 'origin': 'local'}, {'content': 'automotive parts', 'score': 0.021125192, 'origin': 'local'}]
[86]
[87]
[StructuredTool(name='supply_chain_hybrid_search_tool', description='Perform a hybrid (vector + full-text) search on inventory, contracts, shipping items and goods.\n\nArgs:\n    query (str): The search query string.\n\nReturns:\n    list: Relevant inventory documents from hybrid search.\n\nNote:\n    Uses both supply_chain_hybrid_search_tool and text_search_index.', args_schema=<class 'langchain_core.utils.pydantic.supply_chain_hybrid_search_tool'>, func=<function supply_chain_hybrid_search_tool at 0x7912f4def760>),
 StructuredTool(name='update_transit_status', description="Updates the status of a shipment in transit.\nInput should be in the format: 'shipment_id,new_status'.\nFor example: 'SHP-2024-001,Delayed'", args_schema=<class 'langchain_core.utils.pydantic.update_transit_status'>, func=<function update_transit_status at 0x79131d4d80d0>),
 StructuredTool(name='get_contracts_by_transit_status', description='Retrieves contract information from MongoDB based on the Current Transit Status.\n\nArgs:\n  status: The Current Transit Status to filter by (e.g., "Delayed", "On Schedule").\n\nReturns:\n  A list of contract documents matching the specified status.', args_schema=<class 'langchain_core.utils.pydantic.get_contracts_by_transit_status'>, func=<function get_contracts_by_transit_status at 0x7912f4dec9d0>),
 StructuredTool(name='get_contracts_by_inventory_status', description='Retrieves contract information from MongoDB based on the Inventory Status.\n\n    Args:\n        status: The Inventory Status to filter by (e.g., "Delivered", "Awaiting Customs Clearance", "\nIn Transit", "Pending Dispatch").\n        limit: The maximum number of contracts to retrieve (default is 5).\n\n    Returns:\n        A list of contract documents matching the specified inventory status.', args_schema=<class 'langchain_core.utils.pydantic.get_contracts_by_inventory_status'>, func=<function get_contracts_by_inventory_status at 0x7912f4def010>),
 StructuredTool(name='get_real_time_news_on_shipment_by_contract', description='Retrieves real-time news related to a specific shipment by contract number.\n\nArgs:\n  contract_number (str): The contract number to find the shipment details or information.\n  max_local (int): Maximum number of local results to retrieve.\n  max_foreign (int): Maximum number of foreign results to retrieve.\n\nReturns:\n  list: A list of news results relevant to the shipment.', args_schema=<class 'langchain_core.utils.pydantic.get_real_time_news_on_shipment_by_contract'>, func=<function get_real_time_news_on_shipment_by_contract at 0x7912f4dec700>)]

Step 2: Define LLM (R)

[88]

Step 3: Define State (R)

[65]

Step 4: Define Agent Node (R)

[89]
[90]

Step 5: Define Tool Node (R)

[91]

Step 6: Define Graph (R)

[92]
[70]
<langgraph.graph.state.StateGraph at 0x7912fb8750c0>
[93]

Step 7: Graph Visualization (R)

[94]
Output

Step 8: Graph Execution (L)

[100]
[101]
User: Hi there
Assistant: ----Calling Agent Node-------
Hello! Welcome to our AI-powered Logistics Assistant. I'm here to help you with any questions or tasks related to our international shipping operations, contract details, shipment information, inventory data, and supply chain updates. How may I assist you today? 

Is there a specific area you'd like information on, such as:
1. Checking the status of a shipment
2. Inquiring about contract details
3. Getting updates on inventory
4. Requesting information about shipping routes or customs requirements
5. Updating shipment statuses
6. Any other logistics-related query

Please let me know what you need, and I'll be happy to help!

User: what can you do?
Assistant: ----Calling Agent Node-------
Certainly! I'd be happy to explain my capabilities as an AI-powered Logistics Assistant. I'm designed to help with various aspects of international shipping and logistics. Here's an overview of what I can do:

1. Information Retrieval:
   - Search and provide details on inventory, contracts, shipping items, and goods
   - Access real-time news related to specific shipments
   - Retrieve contract information based on transit or inventory status

2. Shipment Status Management:
   - Update the status of shipments in transit
   - Provide current status information for specific shipments

3. Contract and Inventory Analysis:
   - Analyze contract terms and conditions
   - Provide insights on inventory levels and statuses

4. Supply Chain Optimization:
   - Offer information on shipping routes and expected delivery timelines
   - Identify potential delays or issues in the supply chain

5. Customer Service Support:
   - Answer queries about customs requirements for different countries
   - Provide updates on shipment ETAs and any delays

6. Operational Efficiency:
   - Assist with understanding penalties for delays or contract breaches
   - Provide information on supplier performance and delivery rates

7. Regulatory Compliance:
   - Offer guidance on shipping regulations and requirements for different regions

To use these capabilities, you can ask me questions or request specific information. For example, you could ask:
- "What's the status of shipment SHP-2024-001?"
- "Are there any delayed shipments to Europe?"
- "What are the customs requirements for electronics shipped to Canada?"
- "Update the status of Shipment SHP-2024-002 to 'Delayed'"
- "What are the terms in our contract with supplier XYZ regarding delivery schedules?"

Is there a specific area you'd like to focus on or any particular information you need?

User: Can you gve me shippemts that are delayed
Assistant: ----Calling Agent Node-------
[{'text': 'Certainly! I can help you find information about delayed shipments. To get this information, we\'ll need to use the tool that retrieves contracts based on their transit status. In this case, we\'ll look for shipments with a "Delayed" status.\n\nLet\'s use the appropriate function to get this information:', 'type': 'text'}, {'id': 'toolu_01MAQain5hzVgF4ifioZLnW3', 'input': {'status': 'Delayed'}, 'name': 'get_contracts_by_transit_status', 'type': 'tool_use'}]
----Calling Tool Node-------

Using tool get_contracts_by_transit_status
Result: [{'_id': ObjectId('67361d6f96963026f329b2ed'), 'Contract Number': 'SHP-2024-0007', 'Shipper': 'Gonzales-Cox', 'Receiver': 'Smith, Garcia and Gilbert', 'Goods Description': 'Furniture', 'Origin': 'Port of Melbourne, Australia', 'Destination': 'Port of Piraeus, Greece', 'Current Transit Status': 'Delayed'}, {'_id': ObjectId('67361d6f96963026f329b2ee'), 'Contract Number': 'SHP-2024-0008', 'Shipper': 'Long Inc', 'Receiver': 'Herrera Group', 'Goods Description': 'Machinery', 'Origin': 'Shanghai Port, China', 'Destination': 'Port of Hamburg, Germany', 'Current Transit Status': 'Delayed'}, {'_id': ObjectId('67361d6f96963026f329b2ef'), 'Contract Number': 'SHP-2024-0009', 'Shipper': 'Rodriguez, Bray and Snyder', 'Receiver': 'Martin-Thompson', 'Goods Description': 'Pharmaceuticals', 'Origin': 'Port of New York, USA', 'Destination': 'Port of Tokyo, Japan', 'Current Transit Status': 'Delayed'}, {'_id': ObjectId('67361d6f96963026f329b2f1'), 'Contract Number': 'SHP-2024-0011', 'Shipper': 'Green, Huber and Palmer', 'Receiver': 'Jones, Ramirez and Baker', 'Goods Description': 'Cosmetics', 'Origin': 'Port of Miami, USA', 'Destination': 'Port of Marseille, France', 'Current Transit Status': 'Delayed'}, {'_id': ObjectId('67361d6f96963026f329b2f3'), 'Contract Number': 'SHP-2024-0013', 'Shipper': 'Thompson-Macias', 'Receiver': 'Fox PLC', 'Goods Description': 'Pharmaceuticals', 'Origin': 'Port of Tokyo, Japan', 'Destination': 'Port of Le Havre, France', 'Current Transit Status': 'Delayed'}]

----Calling Agent Node-------
Based on the information retrieved, I can provide you with details about the shipments that are currently delayed. Here's a summary of the delayed shipments:

1. Contract Number: SHP-2024-0007
   - Shipper: Gonzales-Cox
   - Receiver: Smith, Garcia and Gilbert
   - Goods: Furniture
   - Route: Port of Melbourne, Australia to Port of Piraeus, Greece

2. Contract Number: SHP-2024-0008
   - Shipper: Long Inc
   - Receiver: Herrera Group
   - Goods: Machinery
   - Route: Shanghai Port, China to Port of Hamburg, Germany

3. Contract Number: SHP-2024-0009
   - Shipper: Rodriguez, Bray and Snyder
   - Receiver: Martin-Thompson
   - Goods: Pharmaceuticals
   - Route: Port of New York, USA to Port of Tokyo, Japan

4. Contract Number: SHP-2024-0011
   - Shipper: Green, Huber and Palmer
   - Receiver: Jones, Ramirez and Baker
   - Goods: Cosmetics
   - Route: Port of Miami, USA to Port of Marseille, France

5. Contract Number: SHP-2024-0013
   - Shipper: Thompson-Macias
   - Receiver: Fox PLC
   - Goods: Pharmaceuticals
   - Route: Port of Tokyo, Japan to Port of Le Havre, France

All of these shipments are currently marked as "Delayed" in our system. 

Is there any specific information you'd like about these delayed shipments? For example, I could:
1. Provide more details about a particular shipment
2. Check for any news updates related to these delays
3. Look into the contract terms for these shipments to see if there are any penalty clauses for delays
4. Investigate possible reasons for the delays based on the routes or goods involved

Please let me know how you'd like to proceed or if you need any additional information.

User: update SHP-2024-0007 to not delayd
Assistant: ----Calling Agent Node-------
[{'text': 'Certainly! I\'ll update the status of shipment SHP-2024-0007 from "Delayed" to "Not Delayed". To do this, we\'ll use the update_transit_status tool. The correct status term in our system is likely "On Schedule" rather than "Not Delayed", so I\'ll use that for the update.\n\nLet\'s proceed with updating the status:', 'type': 'text'}, {'id': 'toolu_01Utu7CbLr19cEmrvzwAXYDr', 'input': {'input': 'SHP-2024-0007,On Schedule'}, 'name': 'update_transit_status', 'type': 'tool_use'}]
----Calling Tool Node-------

Using tool update_transit_status
Result: Successfully updated status of shipment SHP-2024-0007 to On Schedule

----Calling Agent Node-------
Great news! The status of shipment SHP-2024-0007 has been successfully updated from "Delayed" to "On Schedule". 

To summarize the action taken:
- Shipment Contract Number: SHP-2024-0007
- Previous Status: Delayed
- New Status: On Schedule

This update means that the shipment of furniture from Gonzales-Cox to Smith, Garcia and Gilbert, traveling from the Port of Melbourne, Australia to the Port of Piraeus, Greece, is no longer considered delayed.

Is there anything else you would like me to do regarding this shipment or any other logistics matters? For example:
1. Double-check the updated status
2. Notify the involved parties about the status change
3. Check for any other shipments that might need status updates
4. Provide more information about the updated shipment

Please let me know how else I can assist you.

User: can you get me some news on SHP-2024-0007
Assistant: ----Calling Agent Node-------
[{'text': "Certainly! I'd be happy to fetch some news related to the shipment SHP-2024-0007. We can use the get_real_time_news_on_shipment_by_contract function to retrieve this information. Let's do that now:", 'type': 'text'}, {'id': 'toolu_01DH9JX4LYZ3BDhLTjKEmYZA', 'input': {'contract_number': 'SHP-2024-0007'}, 'name': 'get_real_time_news_on_shipment_by_contract', 'type': 'tool_use'}]
----Calling Tool Node-------

Get real-time news about Ocean Freight disruptions, customs issues at Port of Piraeus, Greece, port congestion at Port of Melbourne, Australia or Port of Piraeus, Greece, and logistics or supply chain issues related to shipping Furniture from Port of Melbourne, Australia to Port of Piraeus, Greece.
Using tool get_real_time_news_on_shipment_by_contract
Result: [{'content': "6 Mar 2024 Sea news. 29 February 2024 (Lloyd's List) - THE Red Sea crisis has struck a blow to Greece's port of Piraeus, causing a dent in large containership calls and disrupting its standing as a prominent transhipment hub in Mediterranean region. According to data from Lloyd's List Intelligence, calls from megaships of 10,000 teu and", 'score': 0.59866416, 'origin': 'foreign'}, {'content': 'High freight rates strain global supply chains, threaten vulnerable economies | UNCTAD We help developing countries benefit from the global economy more fairly and effectively, providing data and analysis, facilitating consensus-building and offering technical assistance on issues related to trade and development. As freight rates rise, so do concerns over trade sustainability, economic growth and the global effort to achieve sustainable development goals. UN Trade and Development’s Review of Maritime Transport 2024 estimates that global consumer prices could increase by 0.6% by 2025 as shipping costs filter through supply chains. UN Trade and Development is calling for urgent, coordinated action to reduce volatility in freight markets, mitigate impacts and support vulnerable economies.', 'score': 0.047602657, 'origin': 'foreign'}, {'content': 'long-distance transport', 'score': 0.028114058, 'origin': 'local'}, {'content': "Brazil Port Congestion / Delay Status Data - GoComet Our port congestion report is a data-driven tool that can help you calculate how much of a congestion your shipment will experience based on the specific port in the Brazil where it's due to arrive or depart from. To avoid congestion, businesses can use GoComet's real-time port congestion tool to know live status of port situation in Brazil. Supported by\xa0GoComet platform’s real-time container tracking\xa0data, our machine learning algorithm calculates congestion/delays at ports based on the turnaround times of these containers at a given arrival/departure port. GoComet’s port congestion data gives real-time visibility over port congestion that uses a combination of multiple sources such as AIS data, geofencing around ports and live container events data – collected from over 45000 containers tracked every month.", 'score': 0.0060503976, 'origin': 'local'}, {'content': 'Brazil Port Congestion: Calls: Santos: Container Ships data is updated weekly, averaging 38.000 Unit from Jan 2022 (Median) to 28 Oct 2024, with 144 observations. | Brazil Port Congestion: Calls: Ilheus: Dry Breakbulk (Unit) | 1.000 13 May 2024 | weekly | 14 Mar 2022 - 13 May 2024 | | Brazil Port Congestion: Calls: Santos: Dry Bulk (Unit) | 20.000 04 Nov 2024 | weekly | 31 Jan 2022 - 04 Nov 2024 | | Brazil Port Congestion: Calls: Vila Do Conde: Other Markets (Unit) | 3.000 04 Nov 2024 | weekly | 07 Mar 2022 - 04 Nov 2024 | | Brazil Port Congestion: Calls: Manaus: Dry Breakbulk (Unit) | 1.000 07 Oct 2024 | weekly | 07 Mar 2022 - 07 Oct 2024 |', 'score': 0.0019267347, 'origin': 'local'}, {'content': 'Brazil Port Congestion: Calls: Santos: Container Ships data is updated weekly, averaging 38.000 Unit from Jan 2022 (Median) to 28 Oct 2024, with 144 observations. | Brazil Port Congestion: Calls: Ilheus: Dry Breakbulk (Unit) | 1.000 13 May 2024 | weekly | 14 Mar 2022 - 13 May 2024 | | Brazil Port Congestion: Calls: Santos: Dry Bulk (Unit) | 20.000 04 Nov 2024 | weekly | 31 Jan 2022 - 04 Nov 2024 | | Brazil Port Congestion: Calls: Vila Do Conde: Other Markets (Unit) | 3.000 04 Nov 2024 | weekly | 07 Mar 2022 - 04 Nov 2024 | | Brazil Port Congestion: Calls: Manaus: Dry Breakbulk (Unit) | 1.000 07 Oct 2024 | weekly | 07 Mar 2022 - 07 Oct 2024 |', 'score': 0.0019267347, 'origin': 'local'}, {'content': 'Santos Port struggles to encourage railway solutions for container transport - DatamarNews HomeNewsSantos Port struggles to encourage railway solutions for container transport Santos Port struggles to encourage railway solutions for container transport It is necessary to bring together concessionaires and independent railway operators with container port operators,” he adds. On the other hand, Ivam Jardim believes that the Port of Santos, which handles high-value-added cargo, cannot primarily focus on railways as the primary option because container transportation requires more agility, making road transport ideal for it. “Moreover, for container operations to be efficient in the railway mode, complex works would be necessary in the Serra do Mar mountain range, which is not financially feasible, precisely due to the low capacity to capture this cargo compared to road transport competition,” he argues.', 'score': 0.00055277866, 'origin': 'local'}]

----Calling Agent Node-------
Thank you for your patience. I've retrieved some news related to the shipment SHP-2024-0007. While there isn't any news specifically mentioning this shipment, I can provide you with some relevant information that might impact or be related to this shipment. Let me summarize the key points:

1. Red Sea Crisis Impact on Port of Piraeus:
   - The most relevant news item mentions that the Red Sea crisis has affected the Port of Piraeus in Greece, which is the destination port for SHP-2024-0007.
   - There's been a decrease in large containership calls, disrupting Piraeus' position as a prominent transhipment hub in the Mediterranean region.
   - This news is from February 29, 2024, which is relatively recent and could potentially affect our shipment.

2. Global Freight Rates and Supply Chain Issues:
   - There's a report from UNCTAD (UN Conference on Trade and Development) highlighting concerns over rising freight rates and their impact on global supply chains.
   - It's estimated that global consumer prices could increase by 0.6% by 2025 due to rising shipping costs.
   - This could potentially affect the overall cost and pricing of goods being shipped, including the furniture in SHP-2024-0007.

3. Port Congestion Data:
   - While not directly related to our shipment's route, there's information about port congestion data tools that can help predict delays based on specific ports.
   - This highlights the importance of monitoring port situations to anticipate potential delays.

4. General Maritime Transport News:
   - There are mentions of long-distance transport and container shipping data, which, while not specific to our shipment, indicate ongoing monitoring and analysis of global shipping trends.

It's important to note that while these news items don't directly mention SHP-2024-0007, they provide context about the current state of global shipping, particularly issues affecting Mediterranean ports like Piraeus. The Red Sea crisis impact on Piraeus could be particularly relevant to our shipment.

Given this information, you might want to:
1. Monitor the situation at the Port of Piraeus more closely.
2. Consider potential impacts of global freight rate increases on this and future shipments.
3. Use port congestion data tools to anticipate any potential delays at origin or destination ports.

Would you like me to look into any of these aspects further or provide any additional information about the shipment or its route?

User: q
Goodbye!
[59]