app:
  description: 勤怠データから異常値を検出し、上長・本人・人事向けの通知文を自動生成するワークフロー。過重労働防止と36協定遵守を支援します。
  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: ''
    suggested_questions: []
    suggested_questions_after_answer:
      enabled: false
    text_to_speech:
      enabled: false
  graph:
    edges:
    - data:
        sourceType: start
        targetType: code
      id: start-to-code1
      source: start
      target: code1
    - data:
        sourceType: code
        targetType: if-else
      id: code1-to-ifelse1
      source: code1
      target: ifelse1
    - data:
        sourceType: if-else
        targetType: llm
      id: ifelse1-true-to-llm1
      source: ifelse1
      sourceHandle: 'true'
      target: llm1
    - data:
        sourceType: if-else
        targetType: code
      id: ifelse1-false-to-code_no
      source: ifelse1
      sourceHandle: 'false'
      target: code_no
    - data:
        sourceType: llm
        targetType: code
      id: llm1-to-code_merge
      source: llm1
      target: code_merge
    - data:
        sourceType: code
        targetType: code
      id: code_no-to-code_merge
      source: code_no
      target: code_merge
    - data:
        sourceType: code
        targetType: end
      id: code_merge-to-end
      source: code_merge
      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: 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    import json\n    raw = inputs.get(\"\
          query\", \"\")\n    parsed = {}\n    try:\n        parsed = json.loads(raw)\n\
          \    except Exception:\n        parsed = {}\n        for line in raw.splitlines():\n\
          \            if \":\" in line:\n                parts = line.split(\":\"\
          , 1)\n                key = parts[0].strip()\n                val = parts[1].strip()\n\
          \                parsed[key] = val\n    employee_name = parsed.get(\"employee_name\"\
          ) or parsed.get(\"name\") or parsed.get(\"社員名\") or \"\"\n    manager_name\
          \ = parsed.get(\"manager_name\") or parsed.get(\"manager\") or parsed.get(\"\
          上長\") or \"\"\n    employee_id = parsed.get(\"employee_id\") or parsed.get(\"\
          id\") or \"\"\n    period = parsed.get(\"period\") or parsed.get(\"期間\"\
          ) or \"\"\n    try:\n        overtime = float(parsed.get(\"overtime_hours\"\
          ) or parsed.get(\"overtime\") or 0)\n    except Exception:\n        overtime\
          \ = 0.0\n    try:\n        holiday_days = float(parsed.get(\"holiday_work_days\"\
          ) or parsed.get(\"holiday_days\") or 0)\n    except Exception:\n       \
          \ holiday_days = 0.0\n    try:\n        paid_leave_rate = float(parsed.get(\"\
          paid_leave_rate\") or parsed.get(\"paid_leave\") or 0)\n    except Exception:\n\
          \        paid_leave_rate = 0.0\n    overtime_threshold = 45.0\n    holiday_threshold\
          \ = 1.0\n    paid_leave_threshold = 0.5\n    anomalies = []\n    if overtime\
          \ > overtime_threshold:\n        anomalies.append(\"長時間残業\")\n    if holiday_days\
          \ > holiday_threshold:\n        anomalies.append(\"休日出勤\")\n    if paid_leave_rate\
          \ < paid_leave_threshold:\n        anomalies.append(\"有給消化率低下\")\n    summary\
          \ = \"従業員: \" + str(employee_name) + \" (ID: \" + str(employee_id) + \"\
          ), 期間: \" + str(period) + \"; 残業時間: \" + str(overtime) + \"; 休日出勤日数: \"\
          \ + str(holiday_days) + \"; 有給消化率: \" + str(paid_leave_rate)\n    anomalies_str\
          \ = \",\".join(anomalies)\n    result = dict(summary=summary, anomalies=anomalies_str,\
          \ employee_name=str(employee_name), manager_name=str(manager_name), employee_id=str(employee_id),\
          \ period=str(period), overtime=str(overtime))\n    return result\n"
        variables:
        - value_selector:
          - start
          - query
          variable: query
        outputs:
          summary:
            type: string
            children: null
          anomalies:
            type: string
            children: null
          employee_name:
            type: string
            children: null
          manager_name:
            type: string
            children: null
          employee_id:
            type: string
            children: null
          period:
            type: string
            children: null
          overtime:
            type: string
            children: null
      height: 90
      id: code1
      position:
        x: 380
        y: 282
      type: custom
      width: 244
    - data:
        title: 異常判定
        type: if-else
        conditions:
        - comparison_operator: not empty
          id: cond1
          value: ''
          variable_selector:
          - code1
          - anomalies
        logical_operator: and
      height: 90
      id: ifelse1
      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.6
        prompt_template:
        - role: system
          text: 'あなたは勤怠データの通知文を生成するシニアHRアシスタントです。出力は必ずJSON形式で、キーは manager_message,
            employee_message, hr_message の3つとしてください。各メッセージは日本語で書き、要点（検出された異常、該当する数値、36協定や過重労働防止に関する注意、推奨アクション）を含め、対応期限や緊急度があれば明記してください。個人情報を取り扱う注意点（必要以上の詳細は避ける）も盛り込んでください。


            ---


            【最終出力フォーマット (この指示が最優先)】

            最終出力は **読みやすい日本語の Markdown** で返してください。JSON

            配列・オブジェクトをそのまま出力してはいけません。

            - 見出し (## / ###) でセクションを区切る

            - リスト (- / 1.) や表 (| ... |) で構造化

            - 各項目の意図や根拠が分かるよう短い説明文を添える

            - 営業デモで顧客に直接見せられる体裁にする


            (構造化されたデータ項目を内部で扱うのは構いませんが、出力時に Markdown

            に変換してください。)'
        - role: user
          text: "入力要約:\n{{#code1.summary#}}\n検出された異常: {{#code1.anomalies#}}\n従業員:\
            \ {{#code1.employee_name#}} (ID: {{#code1.employee_id#}}), 上長: {{#code1.manager_name#}},\
            \ 期間: {{#code1.period#}}\n\n上記をもとに、上長・本人・人事向けの通知文をそれぞれ作成してください。出力は必ずJSONで、例:\n\
            {\n  \"manager_message\": \"...\",\n  \"employee_message\": \"...\",\n\
            \  \"hr_message\": \"...\"\n}\n各文は200〜500文字程度を目安に、簡潔に。"
        vision:
          enabled: false
        memory: null
        context:
          enabled: false
      height: 90
      id: llm1
      position:
        x: 980
        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    summary = inputs.get(\"summary_input\"\
          , \"\")\n    message = \"異常は検出されませんでした。データ概要: \" + str(summary)\n    return\
          \ dict(message=message)\n"
        variables:
        - value_selector:
          - code1
          - summary
          variable: summary_input
        outputs:
          message:
            type: string
            children: null
      height: 90
      id: code_no
      position:
        x: 1280
        y: 282
      type: custom
      width: 244
    - data:
        title: メッセージ統合
        type: code
        code_language: python3
        code: "def main(**kwargs) -> dict:\n    candidates = ['llm_text_0']\n    text\
          \ = ''\n    for name in candidates:\n        v = kwargs.get(name)\n    \
          \    if v:\n            text = str(v)\n            break\n    return {\n\
          \        'final_message': text,\n    }\n"
        variables:
        - value_selector:
          - llm1
          - text
          variable: llm_text_0
        outputs:
          final_message:
            type: string
            children: null
      height: 90
      id: code_merge
      position:
        x: 1580
        y: 282
      type: custom
      width: 244
    - data:
        title: 終了
        type: end
        outputs:
        - value_selector:
          - code_merge
          - final_message
          variable: result
      height: 90
      id: end
      position:
        x: 1880
        y: 282
      type: custom
      width: 244
  hash: null
