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
- Write one skill per task (the previous recipes); a skill is the action of one task only.
- Declare the playbook:
name,goal(the result, in a sentence), andtasks, by name. A task is{skill: x}(or{skill: x, kind: k}), or aone_ofchoice between at least two methods. - Order them with
after: [a, b]; make a task optional withrequired: false; give each alabel, what the person reads. - The order that sends several tasks is declared once, on the playbook:
submitwith$selection[task=a,b], and itssubmit_guard. - A call that reads another:
outputon the first,$submitted[<task>.<call>].<output>(or$submitted[<call>]for a call of the playbook) in the second, or in a task'sparams. activation.intentsays what it is for; withoutactivation, 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
$selectionis 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 throughline:, 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
whenreads$selection.kindsonly, and never the kinds of its own task (refused: the condition would close it for ever). - A kind's
whenreads a presented field ($fields.category): a field missing frompresent.fieldsis refused. - A line leaves by one call only: two calls of the playbook taking the same kind are refused.
- A price set by an
updateand sent by a playbook's call needs$line.pricein itsline:. clearis always written out independs_on: the platform never throws answers away on its own.
Reference: Playbooks, The playbook's submit, How it opens.