Skip to main content

Build a playbook

When. The result asks for several choices in an order (the dishes, then a drink), or one order must send the lines of several skills.

Steps​

  1. Write one skill per task (the previous recipes); a skill is the action of one task only.
  2. Declare the playbook: name, goal (the result, in a sentence), and tasks, by name. A task is {skill: x} (or {skill: x, kind: k}), or a one_of choice between at least two methods.
  3. Order them with after: [a, b]; make a task optional with required: false; give each a label, what the person reads.
  4. The order that sends several tasks is declared once, on the playbook: submit with $selection[task=a,b], and its submit_guard.
  5. A call that reads another: output on the first, $submitted[<task>.<call>].<output> (or $submitted[<call>] for a call of the playbook) in the second, or in a task's params.
  6. activation.intent says what it is for; without activation, it opens only when the agent starts it.

The example​

build-a-playbook.yaml
# A playbook: a journey of tasks that leads to one result. The dishes first, then an optional
# drink; one order sends both, declared once on the playbook. Replace api.example.com by the API.
station:
id: noodle-bar
name: Noodle Bar

global:
language: en
currency: EUR
locale: en-GB

domain:
domain_type: retail
entity_name: dish
entity_name_plural: dishes

voice:
tone: friendly
persona: "a cook who takes orders at the counter"
rules:
- "Never say an order is placed before the submit returned it."

apis:
- name: kitchen
openapi_url: https://api.example.com/openapi.json
base_url: https://api.example.com
operations:
- {id: getMenu, access: read}
- {id: placeOrder, access: write}
auth: {type: none}

profiles:
everyone:
when: "true"
grants: [kitchen.getMenu, kitchen.placeOrder]

skills:
- name: dishes
cognitive:
objective: show the dishes of the menu
invoke: {method: getMenu}
kinds: {dish: {when: "$fields.category != 'drink'"}} # one operation, two skills
present:
fields:
name: {from: name, type: text, role: title}
price: {from: price, type: price, role: billed}
category: {from: category, type: text} # presented: `when` reads it
render: {component: cards}

- name: drinks
cognitive:
objective: offer a drink with the dishes already chosen
invoke: {method: getMenu}
kinds: {drink: {when: "$fields.category == 'drink'"}}
present:
fields:
name: {from: name, type: text, role: title}
price: {from: price, type: price, role: billed}
category: {from: category, type: text}
render: {component: cards}

playbooks:
- name: take-an-order
goal: "order a meal: the dishes, then a drink if the person wants one"
activation:
intent: "order a meal"
tasks:
meal: {skill: dishes, label: "Your dishes"}
drink: {skill: drinks, label: "Your drink", after: [meal], required: false}
submit: # one order for the lines of both tasks
- name: order
tool: placeOrder
args:
body.items: "$selection[task=meal,drink]"
body.idempotency_key: "$action.key"
line: {slug: "$line.ref", quantity: "$line.quantity"}
submit_guard:
confirm: true

The pitfalls​

  • A bare $selection is refused on a playbook's call: it would send whatever lines the room holds. Name the tasks: $selection[task=meal,drink].
  • No $item… on a playbook's call: it sends several lines. What comes from a line goes through line:, what comes from the person through $submit.<field>.
  • One skill, one task: the same skill in two tasks is refused.
  • References cite the task, not the skill: $submitted[<task>.<call>].
  • A task's when reads $selection.kinds only, and never the kinds of its own task (refused: the condition would close it for ever).
  • A kind's when reads a presented field ($fields.category): a field missing from present.fields is refused.
  • A line leaves by one call only: two calls of the playbook taking the same kind are refused.
  • A price set by an update and sent by a playbook's call needs $line.price in its line:.
  • clear is always written out in depends_on: the platform never throws answers away on its own.

Reference: Playbooks, The playbook's submit, How it opens.