Preview
Previews returns the expected outcome of executing the Skill. Skill.preview()
enables an application developer to perform a "dry run" of Skill execution in
order to preview the effect of executing the Skill, but without any real-world
side effects that normal execution may entail. To be able to use the Preview and
Fast Preview process execution modes, a Skill must implement Skill.preview().
Skill.preview() is very similar to Skill.execute(). The main difference is
that the implementation will not have access to all of the Services that are
provided to Skill.execute(), but instead will have access to a belief world in
which to preview the execution.
To learn more about the belief and simulation worlds, see world concepts
Prerequisites
Before attempting this guide, you should:
- Deploy a Solution
- Set up your development environment
- Connect to an Organization
- Know how to create Skills
- Understand the Skill interface
- Understand the
Executemethod
Purpose
The primary purpose of the preview() method is to simulate the potential
outcome of a Skill's execution without affecting the real world. Unlike
execute(), which interacts directly with the environment, preview() operates
within a hypothetical world that mirrors the current world state. This allows
developers to assess a Skill's behavior, identify potential issues, and plan for
execution without risk.
It is crucial to understand that the world in the preview mode represents the actual state of the physical world, not the belief state used during normal execution. This means that Skills cannot introduce or correct discrepancies between the two worlds (since they are identical) when in preview mode.
For example, if a perception Skill only updates the belief state when it is
executed, then its implementation of preview would necessarily be a no-op. See
PreviewContext for more details.
Args
The preview() method takes two arguments:
PreviewRequest: input toSkill.preview(), containing the parameter set.PreviewContext: additional conext needed to access the world state, as well as other services that the Skill may use.
Return Value
The preview() method should either return a result proto message, which is
defined by the Skill developer, or None if the Skill does not provide a
result. If you look inside
skill_interface.py,
you can see that the return type of the preview() method is TResultType
(where
TResultType = TypeVar('TResultType', bound=Union[message.Message, None])),
allowing for either the user defined type or None.