File size: 5,360 Bytes
5c6ca01 04b615f 5c6ca01 04b615f 5c6ca01 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | ---
title: Shopmanagereng Environment Server
emoji: ποΈ
colorFrom: green
colorTo: blue
sdk: docker
pinned: false
app_port: 7860
base_path: /web
tags:
- openenv
---
Link of the environment: https://huggingface.co/spaces/hard007ik/ShopManagerEng
Link of Blog.md: https://huggingface.co/spaces/hard007ik/ShopManagerEng/tree/main/Blog.md
# Jewelry Shop Manager β RL Environment
A reinforcement learning environment simulating a **jewelry shop management** pipeline. An AI agent navigates three sequential phases β buying raw materials, selecting products to craft based on demand, and negotiating sales β to maximize profit.
## Environment Overview
### Phase 1: Market (Buy / Wait)
- Gold prices **fluctuate Β±10% each round** (up to 3 rounds).
- The agent analyzes price trends and decides to **buy** gold or **wait** for a better price.
- Goal: Buy gold at the lowest possible price while reserving cash for crafting labor.
### Phase 2: Warehouse (Product Selection)
- The agent sees **demand levels** for each product type:
| Product | Gold (oz) | Labor ($) | Demand Range |
|-----------|-----------|-----------|--------------|
| Ring | 1.0 | $200 | 40-100% |
| Necklace | 2.0 | $300 | 20-80% |
| Bracelet | 0.5 | $100 | 10-60% |
- The agent picks the **highest-demand product** it can afford to craft.
- Goal: Match production to market demand.
### Phase 3: Showroom (Negotiation)
- A customer makes an initial offer based on cost basis and product demand.
- The agent can **accept**, **counter-offer**, or **reject**.
- Each counter raises the customer's offer by **5%** (up to 5 rounds).
- Goal: Sell at maximum profit through smart negotiation.
### Reward Structure
| Component | Weight | Description |
|-----------|--------|-------------|
| R1 (Market) | 20% | How close to the lowest price did the agent buy? |
| R2 (Warehouse) | 20% | Did the agent pick the highest-demand product? |
| R3 (Showroom) | 60% | Normalized profit margin on the sale |
**Final Score** = `0.2 Γ R1 + 0.2 Γ R2 + 0.6 Γ R3` (range [0, 1])
## Quick Start
```python
from ShopManagerEng import JewelryAction, JewelryShopEnv
async def run():
env = JewelryShopEnv(base_url="http://localhost:8000")
result = await env.reset()
print(f"Gold price: ${result.observation.gold_price}/oz")
# Phase 1 β Market: wait for better price
result = await env.step(JewelryAction(market_action="wait"))
# Phase 1 β Market: buy gold
result = await env.step(JewelryAction(market_action="buy", gold_qty=2.0))
# Phase 2 β Warehouse: choose product
result = await env.step(JewelryAction(product_choice="ring"))
# Phase 3 β Showroom: negotiate
result = await env.step(JewelryAction(message="How about $600?"))
result = await env.step(JewelryAction(message="I accept"))
print(f"Final reward: {result.reward}, Cash: {result.observation.cash}")
await env.close()
import asyncio
asyncio.run(run())
```
## Action Space
```python
class JewelryAction:
market_action: str # "buy" or "wait" (Phase 1)
gold_qty: float # Ounces to buy (Phase 1)
product_choice: str # "ring", "necklace", or "bracelet" (Phase 2)
message: str # Negotiation text (Phase 3)
```
## Observation Space
```python
class JewelryObservation:
phase: str # "market" | "warehouse" | "showroom"
cash: float # Current cash balance
gold_oz: float # Raw gold in inventory
gold_price: float # Current gold price ($/oz)
gold_price_history: List[float] # Price trend for analysis
market_round: int # Current market round
demand: Dict[str, float] # Demand per product (0-1)
product_catalog: Dict[str, dict] # Specs per product
inventory: Dict[str, int] # Crafted products in stock
product_for_sale: str # Product being sold (showroom)
cost_basis: float # Total manufacturing cost
current_offer: float # Customer's current offer
negotiation_round: int # Counter-offer round
message: str # Environment feedback
```
## Running the Inference Script
```bash
# Terminal 1: Start the server
cd ShopManagerEng
uv run server
# Terminal 2: Run inference (from parent directory or inside ShopManagerEng)
python inference.py
```
Required environment variables (set in `.env`):
- `HF_TOKEN` β Hugging Face API token
- `MODEL_NAME` β LLM model (default: `meta-llama/Llama-3.3-70B-Instruct`)
## Deploying to Hugging Face Spaces
```bash
openenv push
```
## Project Structure
```
ShopManagerEng/
βββ __init__.py # Module exports
βββ README.md # This file
βββ openenv.yaml # OpenEnv manifest
βββ pyproject.toml # Dependencies
βββ models.py # Action, Observation, State definitions
βββ client.py # JewelryShopEnv client
βββ inference.py # LLM-based agent inference script
βββ server/
βββ __init__.py
βββ ShopManagerEng_environment.py # Core environment logic
βββ app.py # FastAPI application
βββ Dockerfile # Container image
```
|