Cli
Interactive human seam over a console: the person reads and types.
One menu per choice: every message class on offer, its intent when stated, and a prompt for the label (or its number) followed by the payload when the message carries one.
Functions
func__init__(self, console=None) -> NoneCreate an interactive seam over console (defaults to stdio).
› Source code
def __init__(self, console: Console | None = None) -> None:
"""Create an interactive seam over *console* (defaults to stdio).
Args:
console: The console to prompt on; ``StreamConsole`` when omitted.
"""
self._console: Console = StreamConsole() if console is None else consoleparamconsoleConsole | None= NoneThe console to prompt on; StreamConsole when omitted.
Returns
Nonefuncchoose(self, offer) -> MessagePrompt the person for a message among offer's classes.
› Source code
async def choose(self, offer: Offer) -> Message:
"""Prompt the person for a message among *offer*'s classes.
Args:
offer: What the person may send, and to whom.
Returns:
The message the person chose, decoded to its declared class.
"""
self._console.show(_cli_menu(offer))
while True:
chosen, error = await self._attempt_or_error(offer)
if chosen is not None:
return chosen
self._console.show(f'error: {error}')paramofferOfferWhat the person may send, and to whom.
Returns
agentsparty.message.MessageThe message the person chose, decoded to its declared class.
funcnotify(self, subject, envelope) -> NonePrint envelope to the console.
› Source code
async def notify(self, subject: Role, envelope: Envelope) -> None:
"""Print *envelope* to the console.
Args:
subject: The human's own role.
envelope: The protocol message being delivered.
"""
self._console.show(str(envelope))paramsubjectRoleThe human's own role.
paramenvelopeEnvelopeThe protocol message being delivered.
Returns
Nonefuncrecall(self, subject, envelope) -> NonePrint a message this person sent in an earlier process.
› Source code
async def recall(self, subject: Role, envelope: Envelope) -> None:
"""Print a message this person sent in an earlier process.
Args:
subject: The human's own role.
envelope: The protocol message they sent earlier.
"""
self._console.show(str(envelope))paramsubjectRoleThe human's own role.
paramenvelopeEnvelopeThe protocol message they sent earlier.
Returns
Nonefunccancel(self, subject, reason) -> NonePrint that the session ended, and why.
› Source code
async def cancel(self, subject: Role, reason: str) -> None:
"""Print that the session ended, and why.
Args:
subject: The human's own role.
reason: Why the session was rolled up.
"""
self._console.show(f'[{subject.name}] session ended: {reason}')paramsubjectRoleThe human's own role.
paramreasonstrWhy the session was rolled up.
Returns
None