[docs]classAgentId:""" Agent ID uniquely identifies an agent instance within an agent runtime - including distributed runtime. It is the 'address' of the agent instance for receiving messages. See here for more information: :ref:`agentid_and_lifecycle` """def__init__(self,type:str|AgentType,key:str)->None:ifisinstance(type,AgentType):type=type.typeifnotis_valid_agent_type(type):raiseValueError(rf"Invalid agent type: {type}. Allowed values MUST match the regex: `^[\w\-\.]+\Z`")self._type=typeself._key=keydef__hash__(self)->int:returnhash((self._type,self._key))def__str__(self)->str:returnf"{self._type}/{self._key}"def__repr__(self)->str:returnf'AgentId(type="{self._type}", key="{self._key}")'def__eq__(self,value:object)->bool:ifnotisinstance(value,AgentId):returnFalsereturnself._type==value.typeandself._key==value.key
[docs]@classmethoddeffrom_str(cls,agent_id:str)->Self:"""Convert a string of the format ``type/key`` into an AgentId"""items=agent_id.split("/",maxsplit=1)iflen(items)!=2:raiseValueError(f"Invalid agent id: {agent_id}")type,key=items[0],items[1]returncls(type,key)
@propertydeftype(self)->str:""" An identifier that associates an agent with a specific factory function. Strings may only be composed of alphanumeric letters (a-z) and (0-9), or underscores (_). """returnself._type@propertydefkey(self)->str:""" Agent instance identifier. Strings may only be composed of alphanumeric letters (a-z) and (0-9), or underscores (_). """returnself._key