Processing Cycle

Understanding a Soul's Processing Cycle

The Soul processing model is an event driven interface that sends perceptions to be processed and receives interaction requests from the Soul Engine. In detail, the processing cycle for a Soul involves the following steps:

  1. Perceptions: The Soul client sends DeveloperDispatchedPerception events to the Soul Engine.
  2. Soul Engine Execution: The Soul Engine adds the perception to a processing queue, adds them sequentially to working memory, and executes the mental processes of the soul against the perception queue in a single-threaded manner.
  3. Interaction Request Dispatch: The soul sends InteractionRequest events to the client interface.
  4. Interaction Event Handling: The application handles these interaction requests (for example, showing a "say" interaction to a user, or navigating a set of decisions in a game).

Example: Supppose a person says "Hi!" to a soul. To represent this event, the Soul should dispatch a perception to the engine of the user saying "Hi!":

// executed on the client
// dispatch a perception to be processed by the soul
soul.dispatch({
  name: "User",
  action: "said",
  content: "Hi",
})

The engine adds the perception to working memory, executes the current mental process, e.g. "introduction.ts", and then it dispatches an interaction request to reply back to the user.

// executed on the engine
// interaction requests mirror perceptions
// it's recommended that actions are stated in present future tense for requests
dispatch({
  action: "says",
  content: "Hi there!",
  name: "Samantha",
})

Once the client-side Soul object receives the request, its listeners fire for the target event, e.g.

soul.on("says", async ({ content }) => {
  console.log("Samantha said", await content())
})