Inspiration
Pharmacies face a difficult operational balance every day. If they order too little, fast-moving medicines may run out before the next supplier delivery. If they order too much, slow-moving medicines may expire before they are sold, locking working capital into unusable inventory.
The challenge becomes more complicated because purchasing decisions are not based on stock levels alone. Pharmacy managers must also compare supplier prices, discounts, minimum-order quantities, delivery times, credit periods, remaining shelf life, reliability, and return policies.
In many existing workflows, this information is spread across inventory systems, spreadsheets, invoices, supplier catalogues, phone calls, emails, and messaging applications. Traditional inventory systems may display a low-stock or expiry warning, but the manager must still investigate the problem, compare alternatives, contact suppliers, and decide what to do next.
This inspired us to design PharmaFlow AI, an autonomous B2B inventory and procurement-support agent for pharmacies.
What It Does
PharmaFlow AI helps pharmacies determine:
- Which medicines require restocking
- When they should be reordered
- How many units should be purchased
- Which supplier provides the safest overall option
- Whether a discount creates a real saving or an overstocking risk
- Whether a near-expiry batch should be returned, transferred, or prioritized
- Whether cash payment or supplier credit is more appropriate
- What alternative action should be taken when a supplier fails
The agent continuously considers:
- Current and incoming stock
- Historical sales and sales velocity
- Batch-level expiry dates
- Predicted stockouts
- Slow-moving and excess inventory
- Supplier prices and promotional offers
- Minimum-order quantities
- Delivery lead times
- Credit terms
- Return and replacement policies
- Supplier reliability
Unlike a conventional inventory dashboard, PharmaFlow AI does not stop after identifying a problem. It gathers the required information, generates possible actions, evaluates their financial and operational risks, recommends the best plan, requests human approval, prepares the approved action, monitors the supplier response, and revises the plan when necessary.
How the Agent Works
PharmaFlow AI follows an end-to-end agentic workflow:
Observe Retrieve inventory, sales, expiry, purchase-order, and supplier information.
Detect Identify stockout risk, excess stock, slow-moving products, near-expiry batches, supplier delays, or approaching return deadlines.
Investigate Check supplier documents and request clarification when essential information is unavailable or ambiguous.
Generate options Consider actions such as restocking, delaying a purchase, reducing the order quantity, changing suppliers, returning stock, or transferring usable stock to another branch.
Evaluate trade-offs Compare total expected cost, demand, expiry risk, supplier lead time, credit terms, return eligibility, and supplier performance.
Recommend Select the strongest option and explain the evidence, calculations, alternatives, remaining risks, and confidence level.
Request human approval Present high-impact purchasing, credit, return, and supplier decisions to the pharmacy manager.
Prepare the approved action Generate a purchase-order draft, quotation request, return request, or branch-transfer request.
Monitor and adapt Detect supplier rejection, unavailable stock, changed prices, expired offers, delays, or exceeded credit limits and generate a revised plan.
Verify Confirm the approved quantity, price, batch expiry, credit terms, supplier response, and final inventory update.
Example Decision
Consider two possible suppliers for a fast-moving medicine.
Supplier A offers:
- A 20% discount
- A minimum order of 300 units
- Shorter remaining shelf life
- Short credit terms
- A weak return policy
Supplier B offers:
- A 10% discount
- A minimum order of 80 units
- Longer remaining shelf life
- 60-day credit
- A stronger near-expiry return policy
- Better delivery reliability
A simple price-comparison system may select Supplier A because it offers the larger discount.
PharmaFlow AI may recommend Supplier B because its quantity better matches expected demand, its longer shelf life reduces expiry risk, and its credit and return terms create a safer overall outcome.
The system therefore evaluates the expected total cost and operational risk, not only the unit price or discount percentage.
Technical Approach
Our proposed Phase 2 architecture consists of:
- A React pharmacy-manager dashboard
- A FastAPI backend
- A Python-based agent orchestrator
- An inventory and sales tool
- A supplier-intelligence tool
- A forecasting and deterministic decision engine
- An approval workflow
- A communication and purchase-request tool
- A PostgreSQL or SQLite database
- A complete agent audit log
The agent orchestrator manages workflow state, tool selection, missing-data handling, approval gates, failure recovery, and final verification.
Deterministic Calculation Layer
Normal code performs:
- Demand calculations
- Safety-stock calculations
- Reorder-quantity calculations
- Stockout prediction
- Expiry-loss estimation
- Discount calculations
- Payment due-date calculations
- Supplier scoring
- Expected total-cost calculations
- Approval-rule validation
AI Reasoning Layer
The language model supports:
- Supplier-policy interpretation
- Ambiguity handling
- Clarification-question generation
- Qualitative trade-off analysis
- Alternative-plan generation
- Recommendation explanations
- Supplier communication drafting
This separation ensures that mathematical and financial values remain consistent and traceable, while the AI layer focuses on reasoning, communication, and uncertainty.
Human-in-the-Loop Design
PharmaFlow AI does not independently commit pharmacy funds.
Human approval is required for:
- High-value purchase orders
- Large quantities
- New supplier selection
- Supplier credit commitments
- Return and replacement requests
- Branch transfers
- Critical medicine shortages
- Low-confidence recommendations
The pharmacy manager can:
- Approve
- Reject
- Edit the order quantity
- Change the supplier
- Request another option
- Add a comment
- Override the recommendation
Every agent recommendation, calculation, human decision, supplier response, and final outcome is stored in an audit timeline.
Phase 2 MVP
The proposed MVP will focus on one complete and realistic workflow.
It will include:
- One pharmacy
- One pharmacy manager
- Approximately 20–30 medicines
- Batch-level inventory
- Six months of simulated sales data
- Three simulated suppliers
- Supplier prices and discounts
- Minimum-order quantities
- Delivery lead times
- Credit terms
- Return policies
- Supplier reliability records
- Stockout prediction
- Expiry-risk detection
- Supplier comparison
- One manager-approval workflow
- Purchase-order draft generation
- Simulated supplier responses
- Agent reasoning and audit history
The main demonstration will show the agent detecting a predicted shortage and a near-expiry batch, comparing suppliers, recommending a quantity and supplier, requesting approval, and generating a purchase-order draft.
The selected supplier will then report that the required quantity is unavailable. PharmaFlow AI will reassess the remaining options, recalculate cost and risk, produce a revised recommendation, and record the complete process.
Challenges
One of the main design challenges was ensuring that PharmaFlow AI would be more than a dashboard or a chatbot.
We addressed this by designing a full autonomous operational loop that includes tool use, option generation, decision-making, human approval, action preparation, supplier monitoring, failure recovery, and final verification.
Another challenge was preventing unreliable AI-generated calculations. Our proposed solution separates language-model reasoning from deterministic financial and inventory calculations.
Supplier integrations are also a practical limitation for an early prototype. Therefore, Phase 2 will use clearly labelled simulated supplier services while maintaining modular adapters for future real-world integrations.
What We Learned
Designing PharmaFlow AI helped us understand that autonomous agents should not replace every business decision.
The strongest design combines:
- AI reasoning for ambiguity and explanations
- Deterministic tools for calculations
- Clear operational policies
- Human approval for high-impact decisions
- Audit logs for explainability
- Failure recovery for changing business conditions
We also learned that the cheapest option is not always the safest business decision. Procurement decisions must account for demand, expiry, credit, reliability, and return conditions together.
Responsible Boundaries
PharmaFlow AI is strictly an inventory and procurement-operations agent.
It does not:
- Diagnose medical conditions
- Recommend medicine to patients
- Suggest dosages
- Modify prescriptions
- Analyze drug interactions
- Process patient medical records
- Replace pharmacists
- Automatically transfer funds
- Independently make legally binding supplier commitments
- Recommend expired medicine for resale or normal transfer
Expired products are escalated for authorized handling or disposal procedures.
What's Next
Future development may include:
- Real pharmacy POS integrations
- Distributor and supplier APIs
- Multi-branch inventory support
- Branch-transfer optimization
- Advanced demand forecasting
- Automated invoice reconciliation
- Accounting-system integration
- Hospital-pharmacy support
- Supplier-performance analytics
Our goal is to transform pharmacy inventory management from a reactive warning process into an explainable, approval-controlled, autonomous operational workflow.
PharmaFlow AI: Smarter pharmacy decisions. Human-approved actions.
Built With
- agentic
- ai
- analytics
- api
- data
- deterministic
- engine
- fastapi
- generation
- healthcare
- human-in-the-loop
- inventory
- language
- large
- management
- models
- postgresql
- procurement
- python
- react
- rest
- retrieval-augmented
- rules
- sqlite