Skip to content

Commit 363ffa6

Browse files
authored
Merge pull request #1120 from kentbull/agenting-docs-main
docs: clean up and add agenting docs
2 parents a3514ed + 8cec4a7 commit 363ffa6

File tree

1 file changed

+41
-106
lines changed

1 file changed

+41
-106
lines changed

src/keri/app/agenting.py

Lines changed: 41 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -615,9 +615,7 @@ class WitnessPublisher(doing.DoDoer):
615615
"""
616616

617617
def __init__(self, hby, msgs=None, cues=None, **kwa):
618-
"""
619-
For the current event, gather the current set of witnesses, send the event,
620-
gather all receipts and send them to all other witnesses
618+
"""Initialize with publish queue (msgs) and completion cues.
621619
622620
Parameters:
623621
hby (Habery): Habitat of the identifier to populate witnesses
@@ -632,11 +630,9 @@ def __init__(self, hby, msgs=None, cues=None, **kwa):
632630
super(WitnessPublisher, self).__init__(doers=[doing.doify(self.sendDo)], **kwa)
633631

634632
def sendDo(self, tymth=None, tock=0.0, **opts):
635-
"""
636-
Returns doifiable Doist compatible generator method (doer dog)
633+
"""Doer loop that sends queued messages to each witness.
637634
638-
Usage:
639-
add result of doify on this method to doers list
635+
Pushes the original request to self.cues to signal completion
640636
"""
641637
self.wind(tymth)
642638
self.tock = tock
@@ -695,18 +691,17 @@ def idle(self):
695691

696692

697693
class TCPMessenger(doing.DoDoer):
698-
""" Send events to witnesses for receipting using TCP direct connection
699-
700-
"""
694+
"""Send outbound CESR messages to a witness via TCP and parse inbound receipts."""
701695

702696
def __init__(self, hab, wit, url, msgs=None, sent=None, doers=None, **kwa):
703-
"""
704-
For the current event, gather the current set of witnesses, send the event,
705-
gather all receipts and send them to all other witnesses
697+
"""Initialize TCP messenger with queues and parser wiring.
706698
707699
Parameters:
708-
hab: Habitat of the identifier to populate witnesses
709-
700+
hab (Hab): habitat for KEL parsing and db access.
701+
wit (str): qb64 witness identifier.
702+
url (str): tcp endpoint URL for the witness.
703+
msgs (Deck | None): outbound message queue.
704+
sent (Deck | None): sent message queue.
710705
"""
711706
self.hab = hab
712707
self.wit = wit
@@ -724,12 +719,7 @@ def __init__(self, hab, wit, url, msgs=None, sent=None, doers=None, **kwa):
724719
super(TCPMessenger, self).__init__(doers=doers)
725720

726721
def receiptDo(self, tymth=None, tock=0.0, **kwa):
727-
"""
728-
Returns doifiable Doist compatible generator method (doer dog)
729-
730-
Usage:
731-
add result of doify on this method to doers list
732-
"""
722+
"""Doer loop that sends queued messages over TCP."""
733723
self.wind(tymth)
734724
self.tock = tock
735725
_ = (yield self.tock)
@@ -763,25 +753,7 @@ def receiptDo(self, tymth=None, tock=0.0, **kwa):
763753
yield self.tock
764754

765755
def msgDo(self, tymth=None, tock=0.0, **opts):
766-
"""
767-
Returns doifiable Doist compatible generator method (doer dog) to process
768-
incoming message stream of .kevery
769-
770-
Doist Injected Attributes:
771-
g.tock = tock # default tock attributes
772-
g.done = None # default done state
773-
g.opts
774-
775-
Parameters:
776-
tymth is injected function wrapper closure returned by .tymen() of
777-
Tymist instance. Calling tymth() returns associated Tymist .tyme.
778-
tock is injected initial tock value
779-
opts is dict of injected optional additional parameters
780-
781-
782-
Usage:
783-
add result of doify on this method to doers list
784-
"""
756+
"""Doer loop that parses inbound TCP messages into the Kevery."""
785757
yield from self.parser.parsator(local=True) # process messages continuously
786758

787759
@property
@@ -790,18 +762,17 @@ def idle(self):
790762

791763

792764
class TCPStreamMessenger(doing.DoDoer):
793-
""" Send events to witnesses for receipting using TCP direct connection
794-
795-
"""
765+
"""Stream a CESR message to a witness via TCP and parse inbound receipts."""
796766

797767
def __init__(self, hab, wit, url, msgs=None, sent=None, doers=None, **kwa):
798-
"""
799-
For the current event, gather the current set of witnesses, send the event,
800-
gather all receipts and send them to all other witnesses
768+
"""Initialize TCP stream messenger with queues and parser wiring.
801769
802770
Parameters:
803-
hab: Habitat of the identifier to populate witnesses
804-
771+
hab (Hab): habitat for KEL parsing and db access.
772+
wit (str): qb64 witness identifier.
773+
url (str): tcp endpoint URL for the witness.
774+
msgs (Deck | None): outbound message queue.
775+
sent (Deck | None): sent message queue.
805776
"""
806777
self.hab = hab
807778
self.wit = wit
@@ -819,11 +790,9 @@ def __init__(self, hab, wit, url, msgs=None, sent=None, doers=None, **kwa):
819790
super(TCPStreamMessenger, self).__init__(doers=doers)
820791

821792
def receiptDo(self, tymth=None, tock=0.0, **kwa):
822-
"""
823-
Returns doifiable Doist compatible generator method (doer dog)
793+
"""Doer loop that sends queued messages over TCP.
824794
825-
Usage:
826-
add result of doify on this method to doers list
795+
Pushes the original request to self.sent to signal completion
827796
"""
828797
self.wind(tymth)
829798
self.tock = tock
@@ -858,25 +827,7 @@ def receiptDo(self, tymth=None, tock=0.0, **kwa):
858827
yield self.tock
859828

860829
def msgDo(self, tymth=None, tock=0.0, **opts):
861-
"""
862-
Returns doifiable Doist compatible generator method (doer dog) to process
863-
incoming message stream of .kevery
864-
865-
Doist Injected Attributes:
866-
g.tock = tock # default tock attributes
867-
g.done = None # default done state
868-
g.opts
869-
870-
Parameters:
871-
tymth is injected function wrapper closure returned by .tymen() of
872-
Tymist instance. Calling tymth() returns associated Tymist .tyme.
873-
tock is injected initial tock value
874-
opts is dict of injected optional additional parameters
875-
876-
877-
Usage:
878-
add result of doify on this method to doers list
879-
"""
830+
"""Doer loop that parses inbound TCP messages into the Kevery."""
880831
yield from self.parser.parsator(local=True) # process messages continuously
881832

882833
@property
@@ -885,19 +836,18 @@ def idle(self):
885836

886837

887838
class HTTPMessenger(doing.DoDoer):
888-
"""
889-
Interacts with Recipients on HTTP and SSE for sending events and receiving receipts
890-
891-
"""
839+
"""Send CESR messages to a witness over HTTP and capture responses."""
892840

893841
def __init__(self, hab, wit, url, msgs=None, sent=None, doers=None, auth=None, **kwa):
894-
"""
895-
For the current event, gather the current set of witnesses, send the event,
896-
gather all receipts and send them to all other witnesses
842+
"""Initialize HTTP messenger with queues and optional auth.
897843
898844
Parameters:
899-
hab: Habitat of the identifier to populate witnesses
900-
845+
hab (Hab): habitat for KEL parsing and db access.
846+
wit (str): qb64 witness identifier.
847+
url (str): http/https endpoint URL for the witness.
848+
msgs (Deck | None): outbound message queue.
849+
sent (Deck | None): response queue.
850+
auth (str | None): optional 2FA auth codes for witnesses.
901851
"""
902852
self.hab = hab
903853
self.wit = wit
@@ -921,12 +871,7 @@ def __init__(self, hab, wit, url, msgs=None, sent=None, doers=None, auth=None, *
921871
super(HTTPMessenger, self).__init__(doers=doers, **kwa)
922872

923873
def msgDo(self, tymth=None, tock=0.0, **kwa):
924-
"""
925-
Returns doifiable Doist compatible generator method (doer dog)
926-
927-
Usage:
928-
add result of doify on this method to doers list
929-
"""
874+
"""Doer loop that sends queued messages over HTTP."""
930875
self.wind(tymth)
931876
self.tock = tock
932877
_ = (yield self.tock)
@@ -947,10 +892,7 @@ def msgDo(self, tymth=None, tock=0.0, **kwa):
947892
yield self.tock
948893

949894
def responseDo(self, tymth=None, tock=0.0, **kwa):
950-
"""
951-
Processes responses from client and adds them to sent cue
952-
953-
"""
895+
"""Doer loop that processes HTTP responses from the client and adds them into `sent` cues."""
954896
self.wind(tymth)
955897
self.tock = tock
956898
_ = (yield self.tock)
@@ -968,19 +910,17 @@ def idle(self):
968910

969911

970912
class HTTPStreamMessenger(doing.DoDoer):
971-
"""
972-
Interacts with Recipients on HTTP and SSE for sending events and receiving receipts
973-
974-
"""
913+
"""Stream a single CESR message via HTTP PUT and capture the response."""
975914

976915
def __init__(self, hab, wit, url, msg=b'', headers=None, **kwa):
977-
"""
978-
For the current event, gather the current set of witnesses, send the event,
979-
gather all receipts and send them to all other witnesses
916+
"""Initialize a single-request HTTP messenger and add the HTTP client Doer to this DoDoer.
980917
981918
Parameters:
982-
hab: Habitat of the identifier to populate witnesses
983-
919+
hab (Hab): habitat for KEL parsing and db access.
920+
wit (str): qb64 witness identifier.
921+
url (str): http/https endpoint URL for the witness.
922+
msg (bytes): CESR message body to send.
923+
headers (dict | None): extra HTTP headers.
984924
"""
985925
self.hab = hab
986926
self.wit = wit
@@ -1012,12 +952,7 @@ def __init__(self, hab, wit, url, msg=b'', headers=None, **kwa):
1012952
super(HTTPStreamMessenger, self).__init__(doers=doers, **kwa)
1013953

1014954
def recur(self, tyme, deeds=None):
1015-
"""
1016-
Returns doifiable Doist compatible generator method (doer dog)
1017-
1018-
Usage:
1019-
add result of doify on this method to doers list
1020-
"""
955+
"""Poll for a response and stop once received."""
1021956
if self.client.responses:
1022957
self.rep = self.client.respond()
1023958
self.remove([self.client])
@@ -1092,7 +1027,7 @@ def messengerFrom(hab, pre, urls, auth=None):
10921027

10931028

10941029
def streamMessengerFrom(hab, pre, urls, msg, headers=None):
1095-
""" Create a Witnesser (tcp or http) based on provided endpoints
1030+
"""Create a stream messenger (HTTP or TCP) for a single outbound message.
10961031
10971032
Parameters:
10981033
hab (Habitat): Environment to use to look up witness URLs

0 commit comments

Comments
 (0)