Lab Inventory Predictor
Predicts reagent depletion time by analyzing historical usage frequency, and automatically generates reminders when purchases are needed.
Input Validation
This skill accepts: lab reagent inventory data (stock levels, usage records) for the purpose of predicting depletion dates and generating purchase alerts.
If the user's request does not involve lab reagent inventory management or depletion prediction — for example, asking to analyze experimental results, manage equipment, or perform general data analysis — do not proceed with the workflow. Instead respond:
"lab-inventory-predictor is designed to predict reagent depletion and generate purchase alerts based on usage history. Your request appears to be outside this scope. Please provide reagent inventory data, or use a more appropriate tool for your task."
Do not continue the workflow when the request is out of scope, missing the required --action parameter, or would require unsupported assumptions. For missing inputs, state exactly which fields are missing.
Quick Check
CODEBLOCK0
Prerequisites
- - Python 3.8+ is strictly required (uses
dataclasses module). On Python 3.6 the script will fail at import with ModuleNotFoundError. Upgrade with pyenv install 3.8 or conda create -n lab python=3.8. - The script should include a version guard:
if sys.version_info < (3, 8): sys.exit('Error: Python 3.8+ required') before the dataclasses import. - No external dependencies (uses only standard library)
CODEBLOCK1
When to Use
- - Predict when lab reagents will run out based on historical consumption data
- Generate purchase alerts before reagents deplete below safety thresholds
- Track stock levels and usage history for multiple reagents
- Generate inventory reports in text, JSON, or CSV format
Workflow
- 1. Validate input — confirm the request is within scope before any processing.
- Confirm the user objective, required inputs, and non-negotiable constraints before doing detailed work.
- Use the packaged script path or the documented reasoning path with only the inputs that are actually available.
- Return a structured result that separates assumptions, deliverables, risks, and unresolved items.
- If execution fails or inputs are incomplete, switch to the fallback path and state exactly what blocked full completion.
Core Capabilities
- 1. Inventory Tracking — Record current reagent stock levels
- Usage Frequency Analysis — Calculate consumption rate based on experiment records
- Depletion Prediction — Predict reagent depletion date based on consumption rate
- Purchase Alerts — Generate alerts before reagents are about to deplete
- Safety Stock Alerts — Alert when inventory falls below safety threshold
Usage
Command Line
CODEBLOCK2
Python API
CODEBLOCK3
Parameters
Global Parameters
| Parameter | Type | Default | Required | Description |
|---|
| INLINECODE6 | string | - | Yes | Action: status, add-reagent, record-usage, alerts, report |
| INLINECODE7 |
string | ~/.openclaw/workspace/data/lab-inventory.json | No | Path to inventory data file (must be within workspace;
../ paths rejected) |
add-reagent Action
| Parameter | Type | Default | Required | Description |
|---|
| INLINECODE9 | string | - | Yes | Reagent name |
| INLINECODE10 |
float | - | Yes | Current stock quantity |
|
--unit | string | - | Yes | Unit of measurement (ml, mg, etc.) |
|
--safety-days | int | 7 | No | Safety buffer days |
|
--lead-time-days | int | 3 | No | Expected delivery time |
|
--safety-stock | float | - | No | Safety stock threshold |
record-usage Action
| Parameter | Type | Default | Required | Description |
|---|
| INLINECODE15 | string | - | Yes | Reagent name |
| INLINECODE16 |
float | - | Yes | Amount consumed |
|
--experiment | string | - | No | Experiment identifier |
report Action
| Parameter | Type | Default | Required | Description |
|---|
| INLINECODE18 , INLINECODE19 | string | stdout | No | Output file path |
| INLINECODE20 |
string | text | No | Output format (text, json, csv) |
Prediction Algorithm
Consumption Rate
CODEBLOCK4
Depletion Date
CODEBLOCK5
Purchase Alert Trigger Conditions
- 1. Time-based: When INLINECODE21
- Stock-based: When INLINECODE22
Confidence Warning
When a reagent has
fewer than 3 usage records, the prediction is flagged as
LOW_CONFIDENCE. The output will include:
"Warning: Only [N] usage records available for [reagent]. Prediction reliability is low — collect more usage data before relying on this estimate."
Each LOW_CONFIDENCE prediction must include an inline risk note adjacent to the prediction result, not only in the aggregate Risks section.
Fallback Behavior
If scripts/main.py fails or required inputs are incomplete:
- 1. Report the exact failure point and error message.
- State what can still be completed (e.g., status check without prediction).
- Manual fallback: verify the inventory JSON file exists at the configured path, then re-run with
--action status to confirm data integrity. - Do not fabricate execution outcomes or inventory data.
Output Requirements
Every final response must make these items explicit when relevant:
- - Objective or requested deliverable
- Inputs used and assumptions introduced
- Workflow or decision path
- Core result, recommendation, or artifact
- Constraints, risks, caveats, or validation needs (including LOW_CONFIDENCE flags for sparse data, noted inline per reagent)
- Unresolved items and next-step checks
Error Handling
- - If required inputs are missing, state exactly which fields are missing and request only the minimum additional information.
- If the task goes outside the documented scope, stop instead of guessing or silently widening the assignment.
- If
--data-file path contains ../ or points outside the workspace, reject with a path traversal warning. - If
scripts/main.py fails, report the failure point, summarize what still can be completed safely, and provide a manual fallback. - Do not fabricate files, citations, data, search results, or execution outcomes.
Response Template
Use the following fixed structure for non-trivial requests:
- 1. Objective
- Inputs Received
- Assumptions
- Workflow
- Deliverable
- Risks and Limits (include LOW_CONFIDENCE flag inline per reagent if fewer than 3 usage records)
- Next Checks
For stress/multi-constraint requests, also include:
- - Constraints checklist (compliance, performance, error paths)
- Unresolved items with explicit blocking reasons
If the request is simple, you may compress the structure, but still keep assumptions and limits explicit when they affect correctness.
实验室库存预测器
通过分析历史使用频率预测试剂耗尽时间,并在需要采购时自动生成提醒。
输入验证
本技能接受:实验室试剂库存数据(库存水平、使用记录),用于预测耗尽日期并生成采购提醒。
如果用户请求不涉及实验室试剂库存管理或耗尽预测——例如要求分析实验结果、管理设备或执行常规数据分析——请勿继续工作流程。而是回复:
lab-inventory-predictor 旨在根据使用历史预测试剂耗尽并生成采购提醒。您的请求似乎超出了此范围。请提供试剂库存数据,或使用更适合您任务的工具。
当请求超出范围、缺少必需的 --action 参数或需要不支持的假设时,请勿继续工作流程。对于缺少的输入,请明确指出缺少哪些字段。
快速检查
bash
python -m py_compile scripts/main.py
python scripts/main.py --help
python scripts/main.py --action status
前提条件
- - 严格需要 Python 3.8+(使用 dataclasses 模块)。在 Python 3.6 上,脚本将在导入时失败并显示 ModuleNotFoundError。使用 pyenv install 3.8 或 conda create -n lab python=3.8 升级。
- 脚本应在 dataclasses 导入之前包含版本检查:if sys.version_info < (3, 8): sys.exit(Error: Python 3.8+ required)
- 无外部依赖(仅使用标准库)
text
pip install -r requirements.txt
使用时机
- - 根据历史消耗数据预测实验室试剂何时耗尽
- 在试剂低于安全阈值之前生成采购提醒
- 跟踪多种试剂的库存水平和使用历史
- 以文本、JSON 或 CSV 格式生成库存报告
工作流程
- 1. 验证输入——在任何处理之前确认请求在范围内。
- 在进行详细工作之前,确认用户目标、所需输入和不可协商的约束条件。
- 使用打包的脚本路径或文档化的推理路径,仅使用实际可用的输入。
- 返回结构化结果,区分假设、交付物、风险和未解决项。
- 如果执行失败或输入不完整,切换到备用路径并明确指出阻止完全完成的原因。
核心功能
- 1. 库存跟踪——记录当前试剂库存水平
- 使用频率分析——根据实验记录计算消耗率
- 耗尽预测——根据消耗率预测试剂耗尽日期
- 采购提醒——在试剂即将耗尽前生成提醒
- 安全库存提醒——当库存低于安全阈值时发出提醒
使用方法
命令行
text
查看所有试剂状态
python scripts/main.py --action status
添加或更新试剂信息
python scripts/main.py --action add-reagent \
--name PBS 缓冲液 \
--current-stock 500 \
--unit ml \
--safety-days 7
记录实验消耗
python scripts/main.py --action record-usage \
--name PBS 缓冲液 \
--amount 50 \
--experiment 细胞培养实验 #2024-001
获取采购提醒
python scripts/main.py --action alerts
生成预测报告
python scripts/main.py --action report
Python API
python
from skills.labinventorypredictor import InventoryPredictor
predictor = InventoryPredictor(/path/to/inventory.json)
predictor.addreagent(name=PBS 缓冲液, currentstock=500, unit=ml, safetydays=7, leadtime_days=3)
predictor.record_usage(PBS 缓冲液, 50, 实验 #001)
prediction = predictor.predict_depletion(PBS 缓冲液)
print(f预测耗尽时间:{prediction[depletion_date]})
alerts = predictor.get_alerts()
参数
全局参数
| 参数 | 类型 | 默认值 | 必需 | 描述 |
|---|
| --action | 字符串 | - | 是 | 操作:status, add-reagent, record-usage, alerts, report |
| --data-file |
字符串 | ~/.openclaw/workspace/data/lab-inventory.json | 否 | 库存数据文件路径(必须在工作空间内;拒绝 ../ 路径) |
add-reagent 操作
| 参数 | 类型 | 默认值 | 必需 | 描述 |
|---|
| --name | 字符串 | - | 是 | 试剂名称 |
| --current-stock |
浮点数 | - | 是 | 当前库存数量 |
| --unit | 字符串 | - | 是 | 计量单位(ml, mg 等) |
| --safety-days | 整数 | 7 | 否 | 安全缓冲天数 |
| --lead-time-days | 整数 | 3 | 否 | 预期交货时间 |
| --safety-stock | 浮点数 | - | 否 | 安全库存阈值 |
record-usage 操作
| 参数 | 类型 | 默认值 | 必需 | 描述 |
|---|
| --name | 字符串 | - | 是 | 试剂名称 |
| --amount |
浮点数 | - | 是 | 消耗量 |
| --experiment | 字符串 | - | 否 | 实验标识符 |
report 操作
| 参数 | 类型 | 默认值 | 必需 | 描述 |
|---|
| --output, -o | 字符串 | stdout | 否 | 输出文件路径 |
| --format |
字符串 | text | 否 | 输出格式(text, json, csv) |
预测算法
消耗率
dailyconsumption = Σ(usageamount) / days_span
耗尽日期
daysuntildepletion = currentstock / dailyconsumption
depletiondate = today + daysuntil_depletion
采购提醒触发条件
- 1. 基于时间:当 daysuntildepletion <= safetydays + leadtimedays
- 基于库存:当 currentstock <= safety_stock
置信度警告
当试剂
使用记录少于 3 条时,预测被标记为 LOW_CONFIDENCE。输出将包括:
警告:[试剂] 仅有 [N] 条使用记录。预测可靠性较低——在依赖此估计之前请收集更多使用数据。
每个 LOW_CONFIDENCE 预测必须在预测结果旁边包含内联风险说明,而不仅仅在总风险部分。
备用行为
如果 scripts/main.py 失败或所需输入不完整:
- 1. 报告确切的失败点和错误信息。
- 说明仍可完成的内容(例如,不带预测的状态检查)。
- 手动备用:验证库存 JSON 文件存在于配置路径,然后重新运行 --action status 以确认数据完整性。
- 不要编造执行结果或库存数据。
输出要求
每个最终响应在相关时必须明确以下项目:
- - 目标或请求的交付物
- 使用的输入和引入的假设
- 工作流程或决策路径
- 核心结果、建议或产物
- 约束条件、风险、注意事项或验证需求(包括稀疏数据的 LOW_CONFIDENCE 标记,按试剂内联注明)
- 未解决项和下一步检查
错误处理
- - 如果缺少必需输入,明确指出缺少哪些字段,并仅请求最少附加信息。
- 如果任务超出文档范围,停止而不是猜测或悄然扩大任务范围。
- 如果 --data-file 路径包含 ../ 或指向工作空间外部,拒绝并发出路径遍历警告。
- 如果 scripts/main.py 失败,报告失败点,总结仍可安全完成的内容,并提供手动备用方案。
- 不要编造文件、引用、数据、搜索结果或执行结果。
响应模板
对于非平凡请求,使用以下固定结构:
- 1. 目标
- 收到的输入
- 假设
- 工作流程
- 交付物
- 风险和限制(如果使用记录少于 3 条,按试剂内联包含 LOW_CONFIDENCE 标记)
- 下一步检查
对于压力/多约束请求,还需包括:
- - 约束检查清单(合规性、性能、错误路径)
- 带有明确阻止原因的未解决项
如果请求简单,可以压缩结构,但在影响正确性时仍需明确说明假设和限制。