Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Static Inventory Tutorial

Introduction

Static inventory refers to the fixed list of items that are pre-defined and do not change dynamically. In the context of CrewAI, this means the set of items that are available for a crew to use, which remains consistent unless manually updated. This tutorial will guide you through the basics of static inventory management, including creating, maintaining, and utilizing a static inventory.

Creating a Static Inventory

To create a static inventory, you typically define a list of items that will be part of this inventory. Here is an example of how you can define a static inventory in a JSON format:

{ "inventory": [ {"item_id": 1, "item_name": "Helmet", "quantity": 10}, {"item_id": 2, "item_name": "Gloves", "quantity": 15}, {"item_id": 3, "item_name": "Boots", "quantity": 5} ] }

This JSON structure includes an array of items, each with a unique item_id, an item_name, and a quantity.

Maintaining a Static Inventory

Maintaining a static inventory involves updating the quantities and possibly adding or removing items as necessary. Since the inventory is static, these changes are done manually. Here is an example of updating an item quantity:

// Update quantity of Gloves { "inventory": [ {"item_id": 1, "item_name": "Helmet", "quantity": 10}, {"item_id": 2, "item_name": "Gloves", "quantity": 20}, // Updated quantity {"item_id": 3, "item_name": "Boots", "quantity": 5} ] }

In this example, the quantity of "Gloves" has been updated from 15 to 20.

Utilizing a Static Inventory

Utilizing a static inventory involves accessing the items and their quantities for various purposes such as allocation, reporting, or replenishment. Here is an example of accessing the inventory items:

function getInventory() { const inventory = [ {item_id: 1, item_name: "Helmet", quantity: 10}, {item_id: 2, item_name: "Gloves", quantity: 20}, {item_id: 3, item_name: "Boots", quantity: 5} ]; return inventory; } // Example usage const inventory = getInventory(); console.log(inventory);
[ {"item_id": 1, "item_name": "Helmet", "quantity": 10}, {"item_id": 2, "item_name": "Gloves", "quantity": 20}, {"item_id": 3, "item_name": "Boots", "quantity": 5} ]

This JavaScript function, getInventory, returns the static inventory list. The example usage shows how to call this function and log the inventory to the console.

Conclusion

Static inventory management is a straightforward way to keep track of a fixed set of items. While it requires manual updates, it is suitable for scenarios where the inventory does not change frequently. By following this tutorial, you should have a basic understanding of how to create, maintain, and utilize a static inventory in the context of CrewAI.