sequenceDiagram
  participant M as Existing<br>member (M)
  participant MA as Existing<br>member<br>agent (MA)
  participant A as Alice (A)
  participant AA as Alice's<br>agent (AA)
  participant BA as Bob's<br>agent (BA)
  participant B as Bob (B)

  note over A, AA: 1. create new group (no members)
  A ->> AA: G:gidA? NEW<br>(gidA - group ID of this group for A,<br>can be generated by the agent)

  note over AA: create "internal" broadcast associated with the group<br>(B: NEW)

  AA ->> A: G:gidA OK

  note over A, BA: 2. add Bob to group

  A ->> AA: C:idAB INTRO G:gidA gInfo<br>(idAB - conn alias A has for B)
  
  note over AA: generate new random ID for member B (midB, unique per group)<br>initiate "internal" connection gidAB for B in group<br>(internal means that it is not visible to the clients<br>and cannot be used with client commands)

  AA ->> BA: via idAB: GROUP C:midB g:gInvAB gInfo
  BA ->> B: C:idBA REQ G:invID gInfo<br>(invID - to refer to it in ACPT)
  B ->> BA: G:gidB? ACPT G:invID<br>(RJCT G:invID could be added)

  note over BA: create group and "internal" broadcast associated with the group<br>(B: NEW)

  BA ->> B: G:gidB OK

  BA ->> AA: establish internal connection gidBA (using g:gInvAB) for A in group

  note over BA, AA: add connections gidBA and gidAB to broadcasts<br>(B: ADD)
 
  AA ->> A: G:gidA CON C:idAB
  BA ->> B: G:gidA CON C:idBA

  note over M, B: For each existing member M:<br>create and accept internal introduction between connections, related to the group, via gidAB/BA/AM/MA, connections created are gidBM and gidMB<br>The fact that the introduction arrives via connection allocated for the group, allows agents identify it as a new group member, ID used in introductions is group-scoped member ID.

  note over A, BA: once all members were sent to B
  AA ->> BA: via gidAB: MEM C:midB

  note over BA, B: once all members are connected
  BA ->> B: G:gidB MEM

  note over A, AA: once all members reported connection
  AA ->> A: G:gidA MEM C:idAB

  note over M, AA: for each member M

  AA ->> MA: via gidAM: MEM C:midB
  MA ->> M: G:gidM MEM C:idMB
  
  note over M, B: 3. B sends message to the group

  B ->> BA: G:gidB SEND msg

  note over BA: send message via associated broadcast and respond to client with SENT notifications

  BA ->> B: G:gidB SENT C:idBA intMsgID
  BA ->> B: G:gidB SENT C:idBM intMsgID
  
  note over BA, B: once sent to all
  BA ->> B: G:gidB SENT intMsgID

  AA ->> A: G:gidA MSG C:idAB intMsgID msgdata
  A ->> AA: G:gidA ACK intMsgID
  AA ->> BA: via gidAB: RCVD extMsgID hash sig
  BA ->> B: G:gidA RCVD C:idBA intMsgID status<br>(status - message integrity check)

  MA ->> M: G:gidM MSG C:idMB intMsgID msgdata
  M ->> MA: G:gidM ACK intMsgID
  MA ->> BA: via gidMB: RCVD extMsgID hash sig
  BA ->> B: G:gidM RCVD C:idBM intMsgID status

  note over BA, B: once received by all
  BA ->> B: G:gidM RCVD intMsgID status

  note over M, B: 4a. A leaves group

  A ->> AA: G:gidA LEAVE
  AA ->> A: G:gidA OK
  AA ->> BA: via gidAB: LEFT
  note over AA: remove gidAB, remove from broadcast
  note over BA: remove gidBA, remove from broadcast
  BA ->> B: G:gidB LEFT C:idBA

  AA ->> MA: via gidAM: LEFT
  note over AA: remove gidAM, remove from broadcast
  note over MA: remove gidMA, remove from broadcast
  MA ->> M: G:gidM LEFT C:idMA

  AA ->> A: G:gidA LEFT

  note over B, BA: if all members left
  BA ->> B: G:gidB: EMPTY

  note over M, B: 4b. A removes B from group

  A ->> AA: G:gidA REM C:idAB
  AA ->> A: G:gidA OK
  AA ->> BA: via gidAB: OUT
  note over BA: remove gidBA, all gidBM
  BA ->> B: G:gidB OUT C:idBA

  note over AA: remove gidAB
  AA ->> A: G:gidA OK

  note over M, B: below steps happen for each existing member M

  AA ->> MA: via gidAM: REM C:midB
  note over MA: remove gidMB
  MA ->> AA: via gidMA: REMD C:midB
  MA ->> M: G:gidM REMD C:idMB C:idMA<br>(B removed by A)

  note over A, AA: once all members removed B

  AA ->> A: G:gidA REMD C:idAB<br>(B removed by this agent)

  note over M, B: 4c. A deletes group
  A ->> AA: G:gidA DEL
  AA ->> A: G:gidA OK
  
  AA ->> BA: via gidAB: DEL
  note over BA: remove all group connections and messages
  BA ->> B: G:gidB DELD C:idBA<br>(group deleted by A)
  BA ->> AA: via gidBA: DELD
  AA ->> A: G:gidA DELD C:idAB

  AA ->> MA: via gidAM: DEL
  note over MA: remove all group connections and messages
  MA ->> M: G:gidM DELD C:idMA<br>(group deleted by A)
  MA ->> AA: via gidMA: DELD
  AA ->> A: G:gidA DELD C:idAM

  AA ->> A: G:gidA DELD<br>(group deleted by this agent - all confirmed)
