{
  "schema_version": "1",
  "id": "wf-clinic-reception",
  "name": "Clinic reception",
  "strict_mode": false,
  "channels": ["phone"],
  "global_instructions": "You are the receptionist for a dental clinic in Tel Aviv. Be brief, warm and concrete. Never invent an appointment time you have not been given by the booking tool.",

  "request_schema": {
    "type": "object",
    "properties": {
      "first_name": { "type": "string" },
      "language": { "type": "string", "enum": ["he", "en"] }
    },
    "additionalProperties": false
  },

  "stored_schema": {
    "type": "object",
    "properties": {
      "clinic_id": { "type": "string" }
    },
    "additionalProperties": false
  },

  "bindings": [
    {
      "id": "book-visit",
      "tool_revision_id": "6f1b2c3d-4e5f-4a7b-8c9d-0e1f2a3b4c5d",
      "tool_revision_policy": "follow_current",
      "inputs": {
        "patient_name": { "kind": "model", "path": "/patient_name" },
        "starts_at": { "kind": "model", "path": "/starts_at" },
        "clinic_id": { "kind": "stored", "path": "/clinic_id" },
        "preferred_language": {
          "kind": "request",
          "path": "/language",
          "fallback": { "value": "he" }
        },
        "channel": { "kind": "literal", "value": "phone" }
      }
    },
    {
      "id": "log-visit",
      "tool_revision_id": "7a2c3d4e-5f6a-4b8c-9d0e-1f2a3b4c5d6e",
      "inputs": {
        "booking_id": { "kind": "sequence", "path": "/booking_id" }
      }
    },
    {
      "id": "sms-confirm",
      "tool_revision_id": "8b3d4e5f-6a7b-4c9d-8e1f-2a3b4c5d6e7f",
      "inputs": {
        "booking_id": { "kind": "sequence", "path": "/booking_id" },
        "reference": { "kind": "step", "scope": "local", "step_id": "log", "path": "/reference" }
      }
    },
    {
      "id": "email-summary",
      "tool_revision_id": "9c4e5f6a-7b8c-4d0e-9f2a-3b4c5d6e7f80",
      "inputs": {
        "transcript": { "kind": "artifact", "artifact": "transcript", "path": "/text" },
        "clinic_id": { "kind": "stored", "path": "/clinic_id" }
      }
    },
    {
      "id": "missed-call-sms",
      "tool_revision_id": "ad5f6a7b-8c9d-4e1f-a03b-4c5d6e7f8091",
      "inputs": {
        "clinic_id": { "kind": "stored", "path": "/clinic_id" }
      }
    },
    {
      "id": "calendar-event",
      "tool_revision_id": "0d5f6a7b-8c9d-4e1f-8a3b-4c5d6e7f8091",
      "inputs": {
        "summary": { "kind": "literal", "value": "Visit" },
        "start_datetime": { "kind": "extract", "instruction": "the time slot the caller agreed to" },
        "end_datetime": { "kind": "extract", "instruction": "the time it ends, only if the caller named an end time later than the start" }
      }
    }
  ],

  "before": {
    "steps": [],
    "on_failure": "stop_admission"
  },

  "conversation": {
    "entry_node_id": "greet",
    "nodes": [
      {
        "id": "greet",
        "type": "conversation",
        "label": "Greet and find out what they need",
        "instructions": "Greet the caller, ask what they need, and if they want an appointment collect their full name and the day and time they want. Read the time back to them before you book it.",
        "available_binding_ids": []
      },
      {
        "id": "book",
        "type": "action",
        "label": "Book the appointment",
        "binding_id": "book-visit"
      },
      {
        "id": "confirm",
        "type": "sequence",
        "label": "Confirm and log the booking",
        "sequence_id": "confirm-and-log"
      },
      {
        "id": "apologise",
        "type": "conversation",
        "label": "Booking did not go through",
        "instructions": "Tell the caller the booking system did not accept the appointment, apologise once, and say a member of staff will call them back today. Do not promise a specific time."
      },
      {
        "id": "end",
        "type": "end",
        "label": "End call"
      }
    ],
    "edges": [
      {
        "id": "greet-to-book",
        "kind": "conversation",
        "source": "greet",
        "target": "book",
        "condition": "The caller wants an appointment and has given a name and a day and time"
      },
      {
        "id": "greet-to-end",
        "kind": "conversation",
        "source": "greet",
        "target": "end",
        "condition": "The caller does not want an appointment, or has finished"
      },
      {
        "id": "book-ok",
        "kind": "result",
        "source": "book",
        "target": "confirm",
        "outcome": "succeeded"
      },
      {
        "id": "book-failed",
        "kind": "result",
        "source": "book",
        "target": "apologise",
        "outcome": "failed"
      },
      {
        "id": "confirm-ok",
        "kind": "result",
        "source": "confirm",
        "target": "end",
        "outcome": "succeeded"
      },
      {
        "id": "confirm-failed",
        "kind": "result",
        "source": "confirm",
        "target": "apologise",
        "outcome": "failed"
      },
      {
        "id": "apologise-to-end",
        "kind": "conversation",
        "source": "apologise",
        "target": "end",
        "condition": "The caller has nothing else to ask"
      }
    ],
    "global_edges": []
  },

  "sequences": [
    {
      "id": "confirm-and-log",
      "name": "Confirm and log the booking",
      "description": "Write the booking to the practice system and text the patient their confirmation.",
      "input_schema": {
        "type": "object",
        "properties": {
          "booking_id": { "type": "string" }
        },
        "required": ["booking_id"],
        "additionalProperties": false
      },
      "output_schema": {
        "type": "object",
        "properties": {
          "confirmation_sent": { "type": "boolean" }
        },
        "required": ["confirmation_sent"],
        "additionalProperties": false
      },
      "output_mapping": {
        "confirmation_sent": { "kind": "step", "scope": "local", "step_id": "sms", "path": "/sent" }
      },
      "steps": [
        {
          "id": "log",
          "label": "Write it to the practice system",
          "binding_id": "log-visit"
        },
        {
          "id": "sms",
          "label": "Text the confirmation",
          "binding_id": "sms-confirm",
          "depends_on": ["log"]
        }
      ]
    }
  ],

  "after": [
    {
      "id": "summary-to-clinic",
      "event": "call.ended",
      "steps": [
        {
          "id": "email",
          "label": "Email the clinic the call summary",
          "binding_id": "email-summary",
          "requires": ["transcript"],
          "on_failure": "continue"
        }
      ]
    },
    {
      "id": "missed-call",
      "event": "call.no_answer",
      "steps": [
        {
          "id": "text-clinic",
          "label": "Text the clinic that a call went unanswered",
          "binding_id": "missed-call-sms",
          "on_failure": "continue"
        }
      ]
    },
    {
      "id": "book-after-call",
      "event": "call.ended",
      "steps": [
        { "id": "book", "label": "Put the visit in the calendar", "binding_id": "calendar-event" }
      ]
    }
  ],

  "editor": {
    "positions": {
      "greet": { "x": 0, "y": 0 },
      "book": { "x": 260, "y": 0 },
      "confirm": { "x": 520, "y": 0 },
      "apologise": { "x": 260, "y": 180 },
      "end": { "x": 780, "y": 0 }
    }
  }
}
