Home » AI Agents for Supply Chain Optimisation: Production Planning

AI Agents for Supply Chain Optimisation: Production Planning

, when combined with analytics products, can transform into powerful tools for supply chain optimisation.

In manufacturing, the real challenge is not producing goods, but deciding when and how much to produce.

This quote is from a plant director who contacted us for the implementation of an algorithm to improve their Master Production Schedule (MPS).

Production Planning Process (Image by Samir Saci)

The objective was to generate production schedules that balance economies of scale with minimal inventory.

Our initial solution was a web application connected to the factory systems.

Screenshot of the web application with some of the parameters to select (Image by Samir Saci)

While it generated optimal production plans, it still required planners to navigate dashboards and export results.  

How to improve the user experience with an AI layer on top?

As an experiment, we packaged the optimisation engine into a FastAPI microservice embedded within an AI workflow built using n8n. 

The tool evolved into an AI assistant (integrated in the planners’ workflow) that can understand inputs, run the algorithm and deliver optimised plans with explanations in plain English.  

Example of outputs from the AI Agent – (Image by Samir Saci)

In this article, I present how we conducted this experiment of using AI Agents for Supply Chain Optimisation with n8n.

This will be the first of a long series of experiments trying to build a Supply Chain Optimisation “super-agent” equipped with algorithms packaged in FastAPI microservices.

Production Planning with Python

Scenario

Let us assume that we are supporting a medium-sized factory in Europe.

The master production schedule is the primary communication tool between the commercial team and production.

In our client’s factory, customers send purchase orders (PO) with quantities and expected delivery dates to their planning team.

Demand Forecasts for the next 12 months – (Image by Samir Saci)

For example,

  • Expected delivery quantity in Month 2 is 150 boxes

Initial Solution

The objective of the planning team is to find the optimal production plan to minimise production costs, considering:

  • Setup Costs: fixed costs you have each time you set up a production line
    Example: 500 $ per production batch
  • Holding Costs: cost of storage per unit per time
    Example: 1 $/unit/month

If you produce only the quantity needed per month, you can minimise the holding costs.

Extreme Case 1: Producing only the quantity needed each month (Image by Samir Saci)

But setup costs will explode as you have to set up the production line 12 times.

On the contrary, if you produce the total quantity in the first month, you will only have one setup, but your holding costs will explode.

Extreme Case 2: Producing the total quantity in a single batch (Image by Samir Saci)

You build an inventory of 2,000 boxes in the first month, which will be slowly consumed over the 12 months.

There is an optimal scenario between these two edge cases.

How to find the right balance?

In another article, I explain how to use the Wagner-Within algorithm to generate an optimised plan.

This is a dynamic programming method for production planning that finds the cost-optimal schedule over multiple periods.

Wagner-Within Implementation explained in this article – (Image by Samir Saci)

It finds the best balance between setup and holding costs by evaluating all feasible production plans.

Optimal Production Plan generated by Wagner Within Algorithm (Image by Samir Saci)

The output is an optimal plan:

  • 4 months (only) of productions: Month 1, 6, 9 and 11 ;
  • The inventory is consumed between each production batch.

In the animated GIF below, you can visualise a demo of the deployed solution on a web application.

Demo of the Production Module (Image by Samir Saci)

Users can 

  • Upload their demand forecasts per month, week or day
  • Select the parameters (setup costs, holding costs, …)

Can we improve the user experience with the support of AI?

To improve the productivity of planners, we aim to eliminate the UI and directly integrate the solution into their workflow using AI.

In the next section, I will share the experiments we conducted using a prototype of this AI-powered workflow built with n8n.

👉 Check the video linked below for a live demo of the workflow

AI Workflow with FastAPI and n8n

From the feedback received during the User Acceptance Tests (UAT), we understood that they would need the tool to be better integrated into their current processes and workflows.

AI Agents equipped with tools

The planning optimisation algorithm has been packaged in a FastAPI backend with multiple endpoints

  • /upload_prod: this endpoint receives a POST request with the demand dataset included to upload it to the backend
  • /launch_plan: this endpoint receives a GET request with parameters like setup cost, holding cost, and time unit
FastAPI Backend that can be connected to n8n workflows – (Image by Samir Saci)

How to connect this backend with an AI Agent?

We will use an AI Agent node in n8n, equipped with a tool node that can send and receive HTTP requests.

AI Agent Node Equipped with API Tool Node – (Image by Samir Saci)

For all usages, the architecture of this AI Agent node will be identical:

  • Large Language Model: In the example above, we use an OpenAI model
  • HTTP request node with a system message that explains how to connect to the API and what type of data to expect as outputs

This node will be used to generate a summary of the optimal production plan, which will be sent via email.

AI Workflow: Automated Email Reply

Production planners typically receive their requests from the commercial team via email, which includes details in the body and requested volumes by period in the attachment.

Example of Email received by the planning team (Image by Samir Saci)

They wanted to automatically answer these requests without manually downloading the attachment, uploading it to the UI and generating an email based on the results shown in the UI.

It has been agreed with them that they will follow a specific format of emails to ensure that all information required is included:

  • Attachment: demand dataset in (.csv) format
  • Email body: all the parameters needed, like holding costs, setup costs, currency
Example of Request Received by Email – (Image by Samir Saci)

The AI Agent presented before will receive data from another agent that will parse the email to extract the relevant parameters.

AI Workflow for fully automated email reply (Image by Samir Saci)

Step 1: Collect Email and Download the Attachment

The Gmail trigger node collects the email body and downloads the attachment.

Focus on the upload of demand data – (Image by Samir Saci)

The (.csv) file is converted into JSON and sent via POST request to the backend.

Now that the dataset is uploaded, we can provide the email body to the first AI Agent node.

Step 2: Generating the Optimal Production Plan

We have two AI agent nodes in this workflow

  • The AI Agent Parser parses the email content to extract the parameters, which are returned in JSON format.
  • The AI Agent API Request ingests these parameters and queries the FastAPI backend to retrieve the outputs used to generate the written analysis.
Focus on the agentic part of the workflow – (Image by Samir Saci)

In the system prompt of the first AI Agent node, we detail how to parse the email to collect the proper parameters.

System Prompt – (Image by Samir Saci)

The outputs of this AI Agent Parser are sent to the second AI Agent that will query the backend.

Outputs of the AI Agent Parser from the email shared above – (Image by Samir Saci)

In a minimal system prompt, we instruct the AI Agent API Request on how to use the tool.

We provide an overview of the parameters available:

Overview of parameters in the system prompt – (Image by Samir Saci)

We list the outputs of the API’s endpoint:

List of the outputs in the system prompt – (Image by Samir Saci)

We detail the task expected:

Task detailed in the system prompt – (Image by Samir Saci)

The output of the second agent is sent back to the commercial team via email using the last Gmail node.

Example of Summary Provided by the AI Agent – (Image by Samir Saci)

The summary includes the minimal set of information (costs, production batches) needed by the commercial to provide a quotation to the customer.

Conclusion

This workflow has been deployed as a POC with two users who provided encouraging feedback.

We are looking for business cases to productize this approach and propose the feature for all our analytics products.

So far, it has been decided that this feature would be used for orders with non-critical items.

AI Workflows as enablers

Based on my experience in designing and implementing analytics products, the primary obstacle to the rapid adoption of a tool is its integration into existing processes and workflows.

For product planners who manage 100+ references with dozens of customers and internal stakeholders, it is preferable to avoid learning a new tool with a specific interface and additional manual steps.

Therefore, AI agents can be utilised to integrate a tool into any existing workflow with minimal impact and additional workload for users.

With the support of n8n, we have experimented with integrating our analytics products with Jira for workforce planning, as well as utilising Telegram for transportation routing and ERP modules used by our customers.

What’s next?

This workflow can be enhanced to leverage the full potential of large language models (LLMs).

For instance, we can ask the agents to simulate multiple scenarios of volumes to advise the customer on whether to increase or reduce their ordered quantity to obtain a better price.

As long as we have explained to the agent how to use the tool (i.e., our analytic product, packaged in a FastAPI microservice), we can work with it as if we have an analyst who can run scenarios.

About Me

Let’s connect on Linkedin and Twitter. I am a Supply Chain Engineer who uses data analytics to improve logistics operations and reduce costs.

For consulting or advice on analytics and sustainable supply chain transformation, feel free to contact me via Logigreen Consulting.

If you are interested in Data Analytics and Supply Chain, look at my website.

Samir Saci | Data Science & Productivity

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *