IntentExamples

Intent Examples

These patterns come from the Concert App tutorial. Open the playground to step through them interactively.


Follow an artist

Validation in preflight, array mutation in core, event emission in side_effects:

actions:
  FOLLOW_ARTIST:
    state: user
    entity_id_expr: intent.user_id
    input:
      user_id:   { type: string, required: true }
      artist_id: { type: string, required: true }
 
    preflight:
      rules:
        - name: reject_self_follow
          when: { expr: "intent.user_id == intent.artist_id" }
          then:
            - op: reject
              code: CANNOT_FOLLOW_SELF
 
    core:
      rules:
        - name: add_following
          when: {}
          then:
            - op: push
              path: /following
              value: intent.artist_id
 
    side_effects:
      rules:
        - name: emit_followed
          then:
            - op: emit
              event_type: ARTIST_FOLLOWED
              payload:
                user_id:   intent.user_id
                artist_id: intent.artist_id

The emitted ARTIST_FOLLOWED event feeds projections like user_following and artist_leaderboard.


Purchase a ticket

Multi-field validation, numeric mutation with cap, chained notification:

actions:
  PURCHASE_TICKET:
    state: ticket
    entity_id_expr: intent.ticket_id
    input:
      ticket_id:  { type: string,  required: true }
      user_id:    { type: string,  required: true }
      show_id:    { type: string,  required: true }
      quantity:   { type: integer, required: true }
 
    preflight:
      rules:
        - name: validate_quantity
          when: { expr: "intent.quantity <= 0" }
          then:
            - op: reject
              code: INVALID_QUANTITY
 
    core:
      rules:
        - name: mark_purchased
          when: {}
          then:
            - op: set
              path: /status
              value: purchased
            - op: set
              path: /owner_id
              value: intent.user_id
 
    side_effects:
      rules:
        - name: emit_purchase
          then:
            - op: emit
              event_type: TICKET_PURCHASED
              payload:
                ticket_id: intent.ticket_id
                user_id:   intent.user_id
                show_id:   intent.show_id
                quantity:  intent.quantity

Submit a follow-up intent

Use submit in side_effects to fan out work to another entity stream:

side_effects:
  rules:
    - name: notify_user
      then:
        - op: submit
          intent_type: CREATE_NOTIFICATION
          target_stream: user_stream
          payload:
            user_id: intent.user_id
            message: "Your ticket has been confirmed"

More examples

ExampleWhat it demonstrates
Concert AppFull intent catalog — follow, check-in, purchase
Support CopilotAI decision op in side_effects
User NotificationsChained intents via submit
Billing EventsFinancial invariants in preflight

Next steps