Sequence code reference
The complete sequence code syntax, exactly as the assistant and connected AI apps get it.
This is the reference the in-app assistant has in its instructions when you work on a sequence diagram, and connected AI apps get from lookup_guidance with the topic sequence-code. For a walk-through, see Sequence code.
Sequence code syntax (what write_diagram takes and get_diagram returns)
title <text> the diagram's name
autonumber number the messages 1, 2, 3
participant <name> [as <alias>] declare a column; actor and database draw a figure or a cylinder
actor <name> / database <name>
<from>-><to>: <text> a call: solid line, filled head; the caller waits for an answer
<from>--><to>: <text> a reply to an earlier call: dashed line
<from>->><to>: <text> an async message: solid line, open head; nobody waits
<from>-><to> ++: <text> the message activates the receiver (starts its bar)
<from>--><to> --: <text> the message ends the sender's bar
activate <name> / deactivate <name> start or end a bar on a line of its own
note over <a>[, <b>]: <text> a note over one or more participants; also note left of / note right of <a>
note over <a> a note of several lines, closed by "end note"
alt <condition> / else <condition> / end branches, one taken; par <label> / and <label> / end runs them together
opt <condition> ... end happens only when the condition holds
loop <condition> ... end repeats; also break, critical and group, each with one branch
== <text> == a divider between phases
// <text> a comment on a line of its own
Participants are created by the first line that names them, left to right in that order. Declare them at the top to fix the order, set a kind, or give a long name a short alias.
Names with spaces or symbols go in quotes: "Users DB"->API: Query. In message text, \n is a line break.
Indent the lines inside alt, opt, loop, par, break, critical and group by two spaces.
get_diagram prints every element's id. Keep those ids when you rewrite a diagram, so the user's comments stay on their elements.Example
The reference ends with this example.
title Sign in with Google
actor User
participant App
participant Google
database Users DB as DB
User->App: Continue with Google
activate App
App->Google: Authorization request
Google-->App: Authorization code
App->Google: Exchange code for tokens
Google-->App: ID token
alt invited email
App->DB: Find or create user
DB-->App: User
App-->User: Signed in
else not invited
App-->User: Not invited yet
end
deactivate App