MemorySharingRule

MemorySharingRules define criteria that determines if a memory should be sharable between two actors.

It is the developer’s responsibility to use MemorySharingRules in their prompts to control Memory sharing. A typical pattern is to never include a specific Memory in a prompt if it is not sharable. This ensures the Memory is never known or considered when processing a RenderAction. An example of this in action is available below.

MemorySharingRule Scope

MemorySharingRules are evaluated across several scopes, from restrictive, to general.

If MemorySharingRules exist at a given scope, they are evaluated to determine if the specific memory is shareable. Only if no MemorySharingRules exist at a given scope, the next, more general scope is considered. This process continues until all scopes are considered.

Scope Description
Memory, Owner This rule applies to the specific Owner for the specific memory.
Memory, Any Owner This rule applies to any actor that owns the configured memory.
Tag, Owner This rule applies for all memories with the given tag that are owned by the configured Owner.
Tag, Any Owner This rule applies to all memories with the given tag, regardless of the memory’s owner.

Once a scope is found that contains MemorySharingRules, every MemorySharingRule at that scope is evaluated until one returns true. This allows for multiple, different MemorySharingRules to be defined that allow a memory to be shared based on different criteria.

If after evaluating all MemorySharingRules at all scopes, no rule evaluated to true, the memory is not sharable. If you want Memories to be sharable by default, define a MemorySharingRule at your preferred scope that always returns true.

Rules

Rules are expressions that must evaluate to true for a Memory to be sharable.

Every rule has access to a variety of data to use when writing rules:

Variable Type Description
s Snapshot The current snapshot that contains all relevant StoryEngine state.
owner Actor The Actor that owns the memory under evaluation.
actor Actor The Actor that is under consideration for gaining access to the memory.
rule MemorySharingRule The rule being evaluated.
ctx Context The context object from the Event that triggered the RenderAction. This typically contains the JSON payload from the game that emitted the event.

Refer to the Expression Reference documentation for details on how to write expressions.

Using MemorySharingRules

You can check in your prompt to see if a Memory is shareable by calling memory.IsSharableWithActor

For example, here is a prompt that only includes shareable memories:

<selected_character_memories>
{% set memoryOwner = actor %}
{%- set targetActor = s.GetActor(ra.TargetActorIDs[0]) %}

{%- for id in actor.GetMemoryIDs() %}
  {%- set memory = s.GetMemory(id) -%}
  {%- if memory.IsSharableWithActor(memoryOwner, targetActor, ctx, s) %}
  <memory><memory_id>{{ memory.GetID() }}</memory_id><memory_text>{{ memory.GetText() }}</memory_text></memory>
  {%- endif -%}
{% endfor %}
</selected_character_memories>

This example uses several variables exposed in the Prompt when it calls into IsSharableWithActor

Variable Type Description
actor Actor The Actor for whom the prompt is being generated.
s Snapshot The current snapshot that contains all relevant StoryEngine state.
ra RenderAction The RenderAction that invoked the Prompt evaluation
ctx Context The context object from the Event that triggered the RenderAction. This typically contains the JSON payload from the game that emitted the event.

Refer to the prompt reference documentation for a deeper explanation of the syntax and variables used for prompt generation.