Operation
Operation is the base class for something the agent can change for a caller.
Subclass it, declare Field attributes, give it a docstring (its first
paragraph is what the model reads about the tool), and implement prepare(). Register
it with operation() on an Operations or ServiceAgent.
The generated tool takes the fields plus a required boolean, data_supplied_by_user,
in which the model says the caller gave the details themselves. Unless it’s true,
nothing runs. An operation with no fields has no data_supplied_by_user argument and
runs without it.
Properties
Optional class attributes.
kind
The change’s name in the call’s record and in confirm_change. Defaults to the class
name in lower case.
tool
The tool’s name. Defaults to the class name in snake case.
combine
The fields that must match for a request of this operation, made “as well”, to merge
into one of the same operation waiting for the caller’s yes. None means the two
never merge.
goes_before
Kinds of change that wait for this one when both are for the same things, such as an address change before an item change.
guidance
Instructions for a step of the operation’s own, entered when prepare() raises
Need. None gives no step of its own.
fillers
Short phrases said while the tool runs: one list for every language, or lists keyed by language code.
confirm
False makes the change go through when the tool is called, with no read-back and no
yes, such as a move in a game.
before_identity
True for an operation a caller can use before they’re identified.
ask_in_order
True to ask for one missing field at a time, in declaration order.
offered_in
The steps that offer the tool, by name. None offers it in every step.
secure
Whether the tool takes the agent’s per-call security token.
Methods
prepare
prepare(self, call, values) checks the request and builds its change. It returns a
Change, or raises Need when something wasn’t said or
Refuse when the request breaks a rule. It may look things up and may be
async, but never writes. call is a CallContext and values a
Values holding the fields.
apply
apply(self, call, write) carries out one Write and raises WriteFailed
when the backend refuses it. Defaults to the service’s writer (writes_with()). May
be async.
merge
merge(self, held, new) returns one request from the change waiting (held) and a
request made as well (new), both as argument dicts. By default, list fields are
joined, an item asked for again takes its new form (see same_item), and other fields
take the new value.
same_item
same_item(self, field, a, b) returns whether two entries of a list field are the same
thing asked for twice. Defaults to a == b.
conflicts_with
conflicts_with(self, other, mine, theirs) returns why this change and another of kind
other can’t both happen, or None. mine and theirs are the two Changes.
without
without(self, args, gone) returns this operation’s arguments with the things named in
gone (a set of touches keys another change takes over) removed, or None when the
change can’t be split and the whole change is replaced.
Requests while a change waits
When the caller asks for something new while a change waits for their yes, the SDK compares the new request with the waiting change by what both touch:
- Same operation, asked for “as well”, and
combineallows it: one change frommerge(), read back as one. - Same operation,
combineset, and the model didn’t say whether it’s “as well”: when the new request touches some of the same things plus something the waiting change doesn’t, nothing changes, and the model asks “as well, or instead?” - Same operation otherwise, or
conflicts_with()objects: the new request replaces the waiting change for what both touch, and the rest (without()) is set aside. - A conflict asked for “as well”: nothing changes, and the model is told why.
- The waiting operation lists the new kind in
goes_before: the waiting change stays, and the new one is set aside for right after. - Anything else: the new change is read back now, and the waiting one is set aside.