As was suggested upthread, do check the sendmail milter documentation for questions about the milter protocol. Technical design, API, interaction of multiple milters, succession of milter callback stages, it’s all there.
On Ubuntu or Debian install package sendmail-doc and start at /usr/share/doc/sendmail-doc/libmilter/html/index.html.