StateExamples

State & Memory Examples

From the Concert App tutorial.


User entity

# states/user.state.causet
state:
  user:
    entity_key: user_id
    fields:
      - name: following_count
        type: int
        default: 0
      - name: checkin_count
        type: int
        default: 0
      - name: blocked_artists
        type: string_list
        default: []

following_count can be updated in core on follow intents, or via Listeners on ARTIST_FOLLOWED.


Artist entity

state:
  artist:
    entity_key: artist_id
    fields:
      - name: name
        type: string
        default: ""
      - name: follower_count
        type: int
        default: 0
      - name: show_count
        type: int
        default: 0

show_count increments in core when ANNOUNCE_SHOW succeeds.


Application memory — concert history

Accumulated on the user via core rules and CONCERT_MEMORY_CREATED events; also materialized in user_concert_memory projection — see Projection Examples.

state:
  user:
    entity_key: user_id
    fields:
      - name: concert_count
        type: int
        default: 0
core:
  rules:
    - name: increment_concert_count
      when: {}
      then:
        - op: add
          path: /concert_count
          value: 1

Saga scratch space

state:
  ticket_import:
    entity_key: import_id
    fields:
      - name: _tmp/saga_step
        type: int
        default: 0
      - name: _tmp/error_code
        type: string
        default: ""

See Ticket Import Workflow and Defining Sagas.


More examples

ExampleState demonstrated
Concert AppFull entity model
Recommendation MemoryDeterministic user memory
Application MemoryAI-ready structured context

Next steps