File tree Expand file tree Collapse file tree 2 files changed +17
-6
lines changed
Expand file tree Collapse file tree 2 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -245,6 +245,15 @@ async def _handle_control(self, msg: ControlMessage) -> None:
245245 case Cancel ():
246246 # Delete the agent when cancelled.
247247 await self .delete ()
248+ case _:
249+ await self ._handle_control_custom (msg , Context ())
250+
251+ async def _handle_control_custom (self , msg : ControlMessage , ctx : Context ) -> None :
252+ """Handle user-defined CONTROL messages."""
253+ h : Handler = self .__get_handler (msg )
254+ # By design, CONTROL messages are management commands that must be
255+ # processed instantly and do not wait for any return value.
256+ await h (self , msg , ctx )
248257
249258 async def _handle_data (self ) -> None :
250259 """Handle DATA messages."""
Original file line number Diff line number Diff line change @@ -58,12 +58,14 @@ class ControlMessage(Message):
5858 """ControlMessage is the base class for all control messages.
5959
6060 A control message is used to control the behavior of an agent. For example,
61- a `Cancel` message can be sent to an agent to cancel the processing of DATA
62- messages.
63-
64- Note that for a given agent, CONTROL messages and DATA messages are processed
65- in separate coroutines. So the CONTROL messages can be processed in a timely
66- manner without being blocked by the DATA messages.
61+ a `Cancel` message can be sent to an agent to cancel the processing of the
62+ agent and delete it.
63+
64+ For a specific agent, CONTROL messages and DATA messages are processed in
65+ separate coroutines, so CONTROL messages can be processed in a timely manner
66+ without being blocked by DATA messages. By design, CONTROL messages are
67+ management commands that must be processed instantly and do not wait for
68+ any return value.
6769
6870 Any CONTROL message should be a subclass of this class. And any other messages,
6971 inherited from `Message`, are DATA messages.
You can’t perform that action at this time.
0 commit comments