aphilippov/python-server-api
0
1from typing import Dict, List, Optional, Union2 3 4class Agent:5 """(In preview) An abstract class for AI agent.6 7 An agent can communicate with other agents and perform actions.8 Different agents can differ in what actions they perform in the `receive` method.9 """10 11 def __init__(12 self,13 name: str,14 ):15 """16 Args:17 name (str): name of the agent.18 """19 # a dictionary of conversations, default value is list20 self._name = name21 22 @property23 def name(self):24 """Get the name of the agent."""25 return self._name26 27 def send(self, message: Union[Dict, str], recipient: "Agent", request_reply: Optional[bool] = None):28 """(Abstract method) Send a message to another agent."""29 30 async def a_send(self, message: Union[Dict, str], recipient: "Agent", request_reply: Optional[bool] = None):31 """(Abstract async method) Send a message to another agent."""32 33 def receive(self, message: Union[Dict, str], sender: "Agent", request_reply: Optional[bool] = None):34 """(Abstract method) Receive a message from another agent."""35 36 async def a_receive(self, message: Union[Dict, str], sender: "Agent", request_reply: Optional[bool] = None):37 """(Abstract async method) Receive a message from another agent."""38 39 def reset(self):40 """(Abstract method) Reset the agent."""41 42 def generate_reply(43 self,44 messages: Optional[List[Dict]] = None,45 sender: Optional["Agent"] = None,46 **kwargs,47 ) -> Union[str, Dict, None]:48 """(Abstract method) Generate a reply based on the received messages.49 50 Args:51 messages (list[dict]): a list of messages received.52 sender: sender of an Agent instance.53 Returns:54 str or dict or None: the generated reply. If None, no reply is generated.55 """56 57 async def a_generate_reply(58 self,59 messages: Optional[List[Dict]] = None,60 sender: Optional["Agent"] = None,61 **kwargs,62 ) -> Union[str, Dict, None]:63 """(Abstract async method) Generate a reply based on the received messages.64 65 Args:66 messages (list[dict]): a list of messages received.67 sender: sender of an Agent instance.68 Returns:69 str or dict or None: the generated reply. If None, no reply is generated.70 """71 