app:
  description: 在庫・過去販売・安全在庫ルールから次回発注量を簡易モデルで算出し、理由を説明するアシスタント。ユーザーは商品情報や在庫・販売データを1つのテキスト欄（query）に記入してください。
  icon: 📦
  icon_background: '#FFEAD5'
  mode: workflow
  name: 小売 発注量推奨アシスタント
  use_icon_as_answer_icon: false
kind: app
version: 0.6.0
workflow:
  conversation_variables: []
  environment_variables: []
  features:
    file_upload:
      image:
        enabled: false
    opening_statement: '商品ID、現在庫、平均日次販売数、リードタイム（日）、任意の安全在庫を1つのテキストで入力してください。例: 商品A,
      現在庫: 50, 平均日次販売: 5, リードタイム: 7, 安全在庫: 10'
    suggested_questions: []
    suggested_questions_after_answer:
      enabled: false
    text_to_speech:
      enabled: false
  graph:
    edges:
    - data:
        sourceType: start
        targetType: parameter-extractor
      id: start-to-extractor1
      source: start
      target: extractor1
    - data:
        sourceType: parameter-extractor
        targetType: code
      id: extractor1-to-code1
      source: extractor1
      target: code1
    - data:
        sourceType: code
        targetType: llm
      id: code1-to-llm1
      source: code1
      target: llm1
    - data:
        sourceType: llm
        targetType: end
      id: llm1-to-end
      source: llm1
      target: end
    nodes:
    - data:
        title: 開始
        type: start
        variables:
        - label: query
          max_length: 2048
          options: []
          required: true
          type: paragraph
          variable: query
      height: 90
      id: start
      position:
        x: 80
        y: 282
      type: custom
      width: 244
    - data:
        title: 入力項目抽出
        type: parameter-extractor
        model:
          provider: openai
          name: gpt-5-mini
          mode: chat
        query:
        - start
        - query
        parameters:
        - name: product_id
          type: string
          description: 商品IDまたは商品名
          required: true
        - name: current_stock
          type: number
          description: 現在庫数（数値）
          required: true
        - name: avg_daily_sales
          type: number
          description: 平均日次販売数（数値）
          required: true
        - name: lead_time_days
          type: number
          description: リードタイム（日）
          required: true
        - name: safety_stock
          type: number
          description: 安全在庫（任意、未指定なら0）
          required: false
        reasoning_mode: prompt
        instruction: ユーザーの自由記述から以下の項目を抽出してください。数値は可能な限り数字として抽出し、不明な項目は空欄にしてください。
      height: 90
      id: extractor1
      position:
        x: 380
        y: 282
      type: custom
      width: 244
    - data:
        title: 発注量計算（簡易モデル）
        type: code
        code_language: python3
        code: "def _safe_str(v):\n    \"\"\"Convert any value to string safely.\"\"\
          \"\n    if v is None:\n        return \"\"\n    if isinstance(v, list):\n\
          \        return \"\\n\".join(str(i) for i in v)\n    return str(v)\n\ndef\
          \ _safe_list(v):\n    \"\"\"Ensure value is a list.\"\"\"\n    if v is None:\n\
          \        return []\n    if isinstance(v, str):\n        return [v]\n   \
          \ if isinstance(v, list):\n        return v\n    return [v]\n\ndef main(**kwargs)\
          \ -> dict:\n    inputs = kwargs\n    # シンプルな発注量計算:\n    # target_stock =\
          \ avg_daily_sales * lead_time_days + safety_stock\n    # recommended = max(0,\
          \ round(target_stock - current_stock))\n    try:\n        current = float(inputs.get(\"\
          current_stock\", 0))\n    except Exception:\n        current = 0.0\n   \
          \ try:\n        avg_daily = float(inputs.get(\"avg_daily_sales\", 0))\n\
          \    except Exception:\n        avg_daily = 0.0\n    try:\n        lead\
          \ = float(inputs.get(\"lead_time_days\", 0))\n    except Exception:\n  \
          \      lead = 0.0\n    safety_val = inputs.get(\"safety_stock\")\n    try:\n\
          \        safety = float(safety_val) if safety_val is not None and safety_val\
          \ != \"\" else 0.0\n    except Exception:\n        safety = 0.0\n    target\
          \ = avg_daily * lead + safety\n    recommended = int(max(0, round(target\
          \ - current)))\n    details = \"計算式: target = avg_daily_sales * lead_time_days\
          \ + safety_stock; target=\" + str(target) + \"; 現在庫=\" + str(current)\n\
          \    # 出力は辞書形式で返す\n    return dict(recommended_quantity=recommended, calc_details=details)\n"
        variables:
        - value_selector:
          - extractor1
          - product_id
          variable: product_id
        - value_selector:
          - extractor1
          - current_stock
          variable: current_stock
        - value_selector:
          - extractor1
          - avg_daily_sales
          variable: avg_daily_sales
        - value_selector:
          - extractor1
          - lead_time_days
          variable: lead_time_days
        - value_selector:
          - extractor1
          - safety_stock
          variable: safety_stock
        outputs:
          recommended_quantity:
            type: number
            children: null
          calc_details:
            type: string
            children: null
      height: 90
      id: code1
      position:
        x: 680
        y: 282
      type: custom
      width: 244
    - data:
        title: 推奨説明生成
        type: llm
        model:
          provider: openai
          name: gpt-5-mini
          mode: chat
          completion_params:
            temperature: 0.5
        prompt_template:
        - role: system
          text: 'あなたは小売の在庫発注アシスタントです。出力は日本語で行い、推奨の理由と主要な仮定、注意点を簡潔に説明してください。出力は箇条書き（最大3点）で理由を示し、最後に「推奨発注数量:
            数値」の1行を必ず付けてください。'
        - role: user
          text: 'ユーザー入力: {{#start.query#}}


            抽出結果:

            - 商品ID: {{#extractor1.product_id#}}

            - 現在庫: {{#extractor1.current_stock#}}

            - 平均日次販売数: {{#extractor1.avg_daily_sales#}}

            - リードタイム(日): {{#extractor1.lead_time_days#}}

            - 安全在庫: {{#extractor1.safety_stock#}}


            計算結果:

            - 推奨発注数量: {{#code1.recommended_quantity#}}

            - 計算詳細: {{#code1.calc_details#}}


            タスク: 上記を元に、短く分かりやすい理由(箇条書き、最大3点)と注意点を出力し、最後に「推奨発注数量: 数値」を示してください。'
        vision:
          enabled: false
        memory: null
        context:
          enabled: false
      height: 90
      id: llm1
      position:
        x: 980
        y: 282
      type: custom
      width: 244
    - data:
        title: 終了
        type: end
        outputs:
        - value_selector:
          - llm1
          - text
          variable: result
      id: end
      position:
        x: 1280
        y: 282
      type: custom
      height: 90
      width: 244
  hash: null
