Introduction
In this AI agent design, we focus on an Inventory Management & Restocking Agent. This agent is designed to help businesses optimize their inventory control by tracking stock levels, identifying products that need restocking, and triggering automatic orders based on predefined thresholds. The agent ensures that restocking decisions are in line with company policies, and it automatically generates the necessary purchase orders. It never claims success until the action is completed and receipts are provided, ensuring that every step in the process is tracked for audit purposes.
The Use Case
Inventory management is a crucial process for any retail or warehouse-based business. The AI agent checks stock levels of various products, compares them against predefined minimum stock thresholds, and automatically triggers purchase orders for restocking. It can integrate with existing ERP (Enterprise Resource Planning) systems to ensure that inventory is consistently managed and replenished in a timely manner, preventing stockouts and ensuring that customers’ demands are met.
Prompt Contract (agent interface)
# file: contracts/inventory_management_v1.yaml
role: "InventoryManagementAgent"
scope: >
Monitor inventory levels and restock when necessary. Trigger purchase orders when thresholds are breached.
Ask once for missing fields (product_id, current_stock, minimum_stock_level, reorder_quantity).
Propose tool calls; never assert success without a receipt.
output:
type: object
required: [summary, decision, inventory_details, citations, next_steps, tool_proposals]
properties:
summary: {type: string, maxWords: 100}
decision: {type: string, enum: ["approve","reject","need_approval","need_more_info"]}
inventory_details:
type: object
required: [product_id, current_stock, minimum_stock_level, reorder_quantity, restock_order_created]
properties:
product_id: {type: string}
current_stock: {type: integer}
minimum_stock_level: {type: integer}
reorder_quantity: {type: integer}
restock_order_created: {type: boolean}
citations: {type: array, items: {type: string}}
next_steps: {type: array, items: {type: string}, maxItems: 5}
tool_proposals:
type: array
items:
type: object
required: [name, args, preconditions, idempotency_key]
properties:
name: {type: string, enum: [CheckStockLevel, CheckRestockingPolicy, CreateRestockOrder, RequestApproval]}
args: {type: object}
preconditions: {type: string}
idempotency_key: {type: string}
policy_id: "inventory_policy.v4"
citation_rule: "1–2 minimal-span claim_ids per factual sentence"
decoding:
narrative: {top_p: 0.92, temperature: 0.72, stop: ["\n\n## "]}
bullets: {top_p: 0.82, temperature: 0.45}
Example claims (context provided to the model)
[
{"claim_id":"policy:inventory:min_stock_level","text":"Products must have at least 10 units in stock at all times.",
"effective_date":"2025-01-01","source_id":"doc:inventory_policy_v4","span":"at least 10 units in stock"},
{"claim_id":"policy:inventory:reorder_quantity","text":"Restock orders should always be in multiples of 100 units.",
"effective_date":"2025-01-01","source_id":"doc:inventory_policy_v4","span":"multiples of 100 units"},
{"claim_id":"policy:inventory:restock_threshold","text":"Restock threshold for popular products is 20 units.",
"effective_date":"2025-01-01","source_id":"doc:inventory_policy_v4","span":"Restock threshold for popular products is 20 units"}
]
Tool Interfaces (typed, with receipts)
# tools.py
from pydantic import BaseModel
from typing import Optional, List, Dict
from datetime import datetime
class CheckStockLevelArgs(BaseModel):
product_id: str
current_stock: int
minimum_stock_level: int
class CheckRestockingPolicyArgs(BaseModel):
product_id: str
current_stock: int
reorder_quantity: int
class CreateRestockOrderArgs(BaseModel):
product_id: str
reorder_quantity: int
supplier: str
class RequestApprovalArgs(BaseModel):
product_id: str
reorder_quantity: int
approver_id: str
class ToolReceipt(BaseModel):
tool: str
ok: bool
ref: str
message: str = ""
data: Optional[Dict] = None
# adapters.py (demo logic)
from tools import *
from datetime import datetime
MIN_STOCK_LEVEL = 10 # units
RESTOCK_THRESHOLD = 20 # units
REORDER_MULTIPLE = 100 # units
PRODUCTS = {
"prod-001": {"stock": 15, "min_stock_level": 10, "reorder_quantity": 100, "supplier": "SupplierA"},
"prod-002": {"stock": 5, "min_stock_level": 10, "reorder_quantity": 100, "supplier": "SupplierB"}
}
def check_stock_level(a: CheckStockLevelArgs) -> ToolReceipt:
product = PRODUCTS.get(a.product_id)
if not product:
return ToolReceipt(tool="CheckStockLevel", ok=False, ref="product-not-found", message="Product not found")
stock_needed = max(0, a.minimum_stock_level - a.current_stock)
return ToolReceipt(tool="CheckStockLevel", ok=True, ref=f"stock-{a.product_id}",
message="Stock checked", data={"stock_needed": stock_needed})
def check_restocking_policy(a: CheckRestockingPolicyArgs) -> ToolReceipt:
if a.current_stock >= a.reorder_quantity:
return ToolReceipt(tool="CheckRestockingPolicy", ok=True, ref="policy-ok", message="Reorder quantity meets policy")
return ToolReceipt(tool="CheckRestockingPolicy", ok=False, ref="policy-reorder-issue",
message="Reorder quantity is not met")
def create_restock_order(a: CreateRestockOrderArgs) -> ToolReceipt:
return ToolReceipt(tool="CreateRestockOrder", ok=True, ref=f"restock-{a.product_id}",
message="Restock order created", data={"reorder_quantity": a.reorder_quantity})
def request_approval(a: RequestApprovalArgs) -> ToolReceipt:
return ToolReceipt(tool="RequestApproval", ok=True, ref=f"approval-{a.product_id}",
message=f"Approval requested for {a.reorder_quantity} units.", data={"approver_id": a.approver_id})

Join the conversation! Your thoughts help the community grow.