swarm verify catches it before you deploy.
create_entity
Create (“mint”) a new entity at the flow’s initial state. Use it when the event starts a new item in this flow (a fresh ticket arriving):entity_id is ignored for
state operations. Every declared field already has a value the moment the entity exists — its
initial: value, or the type default — so a guard in the same handler can read any field
immediately.
- Cannot be combined with
accumulate— an accumulator targets one entity, butcreate_entitymints a new one each time. - Can be combined with
fan_out— one entity is created and every fanned-out event shares it.
select_entity
Attach to one existing entity, matched by a business key. Theby map pairs entity fields with
payload.* values from the triggering event:
select_or_create_entity
Resolve one existing entity by the key, or mint a fresh one from that key if none matches. Use it when an event might be the first the flow has seen for a given key, or a follow-up:data_accumulation, as the accordion below shows.
Complete flows
Both examples below passswarm verify.
create_entity then select_entity: an order through its lifecycle
create_entity then select_entity: an order through its lifecycle
The first event mints the order; every later event finds that same order by its business key.
This is the most common shape: one handler creates, the rest select.What happens:
package.yaml
schema.yaml
entities.yaml
events.yaml
nodes.yaml
order.placed runs create_entity, so it mints a fresh order at the
placed state and records order_id and customer. When order.shipped arrives later, the
handler has no entity of its own, so select_entity finds the existing order whose order_id
matches the event’s payload.order_id, then advances it to shipped. order.delivered does the
same and moves it to the terminal delivered state. The order_id field is what links every
later event back to the order it created.select_or_create_entity: a session that starts on its first event
select_or_create_entity: a session that starts on its first event
Use What happens: the very first
select_or_create_entity when an event might be the first the flow has seen for a key, or a
follow-up, and you do not want to handle the two cases separately.package.yaml
schema.yaml
entities.yaml
events.yaml
nodes.yaml
page.viewed for a session_id finds no matching session, so
select_or_create_entity mints one at active; every later view for that id finds the existing
session. Either way the handler then writes session_id and increments view_count, so the
count rises with each view. session.ended uses plain select_entity (the session must already
exist by then) and moves it to ended. The computed write reads entity.view_count as it stood
before this handler, which is why it increments cleanly across events.Flows and entities
What an entity is, and how instances give each work item its own.

