WiseAgentEvent

TODO

Source code in wiseagents/wise_agent_messaging.py
22
23
24
25
class WiseAgentEvent:
    """
    TODO
    """

WiseAgentMessage

Bases: YAMLObject

A message that can be sent between agents.

Source code in wiseagents/wise_agent_messaging.py
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
class WiseAgentMessage(YAMLObject):
    ''' A message that can be sent between agents. '''
    yaml_tag = u'!wiseagents.WiseAgentMessage'
    def __init__(self, message: str, context_name: str, sender: Optional[str] = None, message_type: Optional[WiseAgentMessageType] = None, 
                 tool_id : Optional[str] = None,
                 route_response_to: Optional[str] = None):
        '''Initialize the message.

        Args:
            message (str): the message contents (a natural language string)
            sender Optional(str): the sender of the message (or None if the sender was not specified)
            message_type Optional(WiseAgentMessageType): the type of the message (or None if the type was not specified)
            tool_id Optional(str): the id of the tool
            context_name Optional(str): the context name of the message
            route_response_to Optional(str): the id of the tool to route the response to
            ''' 
        self._message = message
        self._sender = sender
        self._message_type = message_type
        self._tool_id = tool_id
        self._route_response_to = route_response_to
        self._context_name = context_name
        self.__class__.yaml_dumper.add_representer(WiseAgentMessageType, wiseAgentMessageType_representer)

    def __setstate__(self, state):
        self._message = state["_message"]
        self._sender =  state["_sender"]
        if state["_message_type"] is not None and state["_message_type"] != "":
            logging.getLogger(__name__).debug(f"__setstate__ state[_message_type]: {state['_message_type']}")
            self._message_type = WiseAgentMessageType(state["_message_type"])
        else:
            self._message_type = None
        self._tool_id =  state["_tool_id"]
        self._route_response_to =  state["_route_response_to"]
        self._context_name = state["_context_name"]


    def __repr__(self) -> str:
        return f"{self.__class__.__name__}(message={self.message}, sender={self.sender}, message_type={self.message_type}, tool_id={self.tool_id}, context_name={self.context_name}, route_response_to={self.route_response_to}, route_response_to={self.route_response_to})"

    @property
    def context_name(self) -> str:
        """Get the context name of the message."""
        return self._context_name

    @property
    def message(self) -> str:
        """Get the message contents (a natural language string)."""
        return self._message

    @property
    def sender(self) -> str:
        """Get the sender of the message (or None if the sender was not specified)."""
        return self._sender
    @sender.setter
    def sender(self, sender: str):
        '''Set the sender of the message.

        Args:
            sender (str): the sender of the message
        '''
        self._sender = sender

    @property
    def message_type(self) -> WiseAgentMessageType:
        """Get the type of the message (or None if the type was not specified)."""
        return self._message_type

    @property
    def tool_id(self) -> str:
        """Get the id of the tool."""
        return self._tool_id

    @property
    def route_response_to(self) -> str:
        """Get the id of the tool."""
        return self._route_response_to

context_name: str property

Get the context name of the message.

message: str property

Get the message contents (a natural language string).

message_type: WiseAgentMessageType property

Get the type of the message (or None if the type was not specified).

route_response_to: str property

Get the id of the tool.

sender: str property writable

Get the sender of the message (or None if the sender was not specified).

tool_id: str property

Get the id of the tool.

__init__(message, context_name, sender=None, message_type=None, tool_id=None, route_response_to=None)

Initialize the message.

Parameters:
  • message (str) –

    the message contents (a natural language string)

  • sender (Optional(str, default: None ) –

    the sender of the message (or None if the sender was not specified)

  • message_type (Optional(WiseAgentMessageType, default: None ) –

    the type of the message (or None if the type was not specified)

  • tool_id (Optional(str, default: None ) –

    the id of the tool

  • context_name (Optional(str) –

    the context name of the message

  • route_response_to (Optional(str, default: None ) –

    the id of the tool to route the response to

Source code in wiseagents/wise_agent_messaging.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
def __init__(self, message: str, context_name: str, sender: Optional[str] = None, message_type: Optional[WiseAgentMessageType] = None, 
             tool_id : Optional[str] = None,
             route_response_to: Optional[str] = None):
    '''Initialize the message.

    Args:
        message (str): the message contents (a natural language string)
        sender Optional(str): the sender of the message (or None if the sender was not specified)
        message_type Optional(WiseAgentMessageType): the type of the message (or None if the type was not specified)
        tool_id Optional(str): the id of the tool
        context_name Optional(str): the context name of the message
        route_response_to Optional(str): the id of the tool to route the response to
        ''' 
    self._message = message
    self._sender = sender
    self._message_type = message_type
    self._tool_id = tool_id
    self._route_response_to = route_response_to
    self._context_name = context_name
    self.__class__.yaml_dumper.add_representer(WiseAgentMessageType, wiseAgentMessageType_representer)

WiseAgentTransport

Bases: WiseAgentsYAMLObject

Source code in wiseagents/wise_agent_messaging.py
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
class WiseAgentTransport(WiseAgentsYAMLObject):

    def __init__(self):
        enforce_no_abstract_class_instances(self.__class__, WiseAgentTransport)

    ''' A transport for sending messages between agents. '''    
    def set_call_backs(self, request_receiver: Optional[Callable[[], WiseAgentMessage]] = None,
                 event_receiver: Optional[Callable[[], WiseAgentEvent]] = None,
                 error_receiver: Optional[Callable[[], WiseAgentMessage]] = None,
                 response_receiver: Optional[Callable[[], WiseAgentMessage]] = None):
        '''Set the call back functions for the transport.

        Args:
            request_receiver Optional(Callable[[], WiseAgentMessage]): the call back function for receiving requests
            event_receiver Optional(Callable[[], WiseAgentEvent]): the call back function for receiving events
            error_receiver Optional(Callable[[], WiseAgentMessage]): the call back function for receiving errors
            response_receiver Optional(Callable[[], WiseAgentMessage]): the call back function for receiving responses
        '''
        self._request_receiver = request_receiver
        self._event_receiver = event_receiver
        self._error_receiver = error_receiver
        self._response_receiver = response_receiver

    def __getstate__(self) -> object:
        '''Return the state of the transport. Removing the instance variable chain to avoid it is serialized/deserialized by pyyaml.'''
        state = super().__getstate__()
        del state['request_receiver']
        del state['response_receiver']
        del state['event_receiver']
        del state['error_receiver']
        return state


    @abstractmethod
    def start(self):
        """
        Start the transport.
        """
        pass

    @abstractmethod
    def send_request(self, message: WiseAgentMessage, dest_agent_name: str):
        """
        Send a request message to an agent.


        Args:
            message (WiseAgentMessage): the message to send
        """
        pass

    @abstractmethod
    def send_response(self, message: WiseAgentMessage, dest_agent_name: str):
        """
        Send a request message to an agent.


        Args:
            message (WiseAgentMessage): the message to send
        """
        pass

    @abstractmethod
    def stop(self):
        """
        Stop the transport.
        """
        pass

    @property
    def request_receiver(self) -> Optional[Callable[[], WiseAgentMessage]]:
        """Get the message receiver callback."""
        return self._request_receiver

    @property
    def event_receiver(self) -> Optional[Callable[[], WiseAgentEvent]]:
        """Get the event receiver callback."""
        return self._event_receiver

    @property
    def error_receiver(self) -> Optional[Callable[[], WiseAgentMessage]]:
        """Get the error receiver callback."""
        return self._error_receiver

    @property
    def response_receiver(self) -> Optional[Callable[[], WiseAgentMessage]]:
        """Get the response receiver callback."""
        return self._response_receiver

error_receiver: Optional[Callable[[], WiseAgentMessage]] property

Get the error receiver callback.

event_receiver: Optional[Callable[[], WiseAgentEvent]] property

Get the event receiver callback.

request_receiver: Optional[Callable[[], WiseAgentMessage]] property

Get the message receiver callback.

response_receiver: Optional[Callable[[], WiseAgentMessage]] property

Get the response receiver callback.

__getstate__()

Return the state of the transport. Removing the instance variable chain to avoid it is serialized/deserialized by pyyaml.

Source code in wiseagents/wise_agent_messaging.py
132
133
134
135
136
137
138
139
def __getstate__(self) -> object:
    '''Return the state of the transport. Removing the instance variable chain to avoid it is serialized/deserialized by pyyaml.'''
    state = super().__getstate__()
    del state['request_receiver']
    del state['response_receiver']
    del state['event_receiver']
    del state['error_receiver']
    return state

send_request(message, dest_agent_name)

Send a request message to an agent.

Parameters:
Source code in wiseagents/wise_agent_messaging.py
149
150
151
152
153
154
155
156
157
158
@abstractmethod
def send_request(self, message: WiseAgentMessage, dest_agent_name: str):
    """
    Send a request message to an agent.


    Args:
        message (WiseAgentMessage): the message to send
    """
    pass

send_response(message, dest_agent_name)

Send a request message to an agent.

Parameters:
Source code in wiseagents/wise_agent_messaging.py
160
161
162
163
164
165
166
167
168
169
@abstractmethod
def send_response(self, message: WiseAgentMessage, dest_agent_name: str):
    """
    Send a request message to an agent.


    Args:
        message (WiseAgentMessage): the message to send
    """
    pass

set_call_backs(request_receiver=None, event_receiver=None, error_receiver=None, response_receiver=None)

Set the call back functions for the transport.

Parameters:
  • request_receiver (Optional(Callable[[], WiseAgentMessage], default: None ) –

    the call back function for receiving requests

  • event_receiver (Optional(Callable[[], WiseAgentEvent], default: None ) –

    the call back function for receiving events

  • error_receiver (Optional(Callable[[], WiseAgentMessage], default: None ) –

    the call back function for receiving errors

  • response_receiver (Optional(Callable[[], WiseAgentMessage], default: None ) –

    the call back function for receiving responses

Source code in wiseagents/wise_agent_messaging.py
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
def set_call_backs(self, request_receiver: Optional[Callable[[], WiseAgentMessage]] = None,
             event_receiver: Optional[Callable[[], WiseAgentEvent]] = None,
             error_receiver: Optional[Callable[[], WiseAgentMessage]] = None,
             response_receiver: Optional[Callable[[], WiseAgentMessage]] = None):
    '''Set the call back functions for the transport.

    Args:
        request_receiver Optional(Callable[[], WiseAgentMessage]): the call back function for receiving requests
        event_receiver Optional(Callable[[], WiseAgentEvent]): the call back function for receiving events
        error_receiver Optional(Callable[[], WiseAgentMessage]): the call back function for receiving errors
        response_receiver Optional(Callable[[], WiseAgentMessage]): the call back function for receiving responses
    '''
    self._request_receiver = request_receiver
    self._event_receiver = event_receiver
    self._error_receiver = error_receiver
    self._response_receiver = response_receiver

start()

Start the transport.

Source code in wiseagents/wise_agent_messaging.py
142
143
144
145
146
147
@abstractmethod
def start(self):
    """
    Start the transport.
    """
    pass

stop()

Stop the transport.

Source code in wiseagents/wise_agent_messaging.py
171
172
173
174
175
176
@abstractmethod
def stop(self):
    """
    Stop the transport.
    """
    pass