gabm.abm.agent module
- class gabm.abm.agent.Agent(agent_id: AgentID, environment: Environment)
Bases:
objectFor representing an entity within an Environment. The type annotation for environment is quoted as it is imported under TYPE_CHECKING to avoid circular imports.
- Attributes:
- agent_id (AgentID):
Unique identifier for the Agent instance.
- environment (Environment):
The Environment the Agent instance belongs to.
- groups (Set[Group]):
A Set of Groups that the Agent instance belongs to.
- class gabm.abm.agent.AgentID(agent_id: int)
Bases:
GABMIDA unique identifier for an Agent instance.
- Attributes:
id (int): The unique identifier for the agent.
- class gabm.abm.agent.Citizen(citizen_id: CitizenID, environment: Nation, year_of_birth: int = None, gender_id: GenderID = None, opinions: dict = None, region_id: int = None, education_id: int = None, ethnicity_id: int = None, employment_id: int = None, income_id: int = None)
Bases:
PersonA Person who belongs to a Nation.
Note
Inherits all attributes from
Person.- Attributes:
- region_id (RegionID):
The agent’s region, represented as a RegionID.
- education_id (EducationID):
The agent’s education level, represented as an EducationID.
- ethnicity_id (EthnicityID):
The agent’s ethnicity, represented as an EthnicityID.
- employment_id (EmploymentID):
The agent’s employment status, represented as an EmploymentID.
- income_id (IncomeID):
The agent’s income level, represented as an IncomeID.
- class gabm.abm.agent.Person(agent_id: AgentID, environment: Environment, year_of_birth: int = None, gender_id: GenderID = None, opinions: dict[OpinionTopicID, 'Opinion'] = None)
Bases:
AgentAn Agent with a year of birth and Gender.
Note
Inherits all attributes from
Agent.- Attributes:
- year_of_birth (int):
The year of birth attributed.
- gender_id (GenderID):
The GenderID attributed.
- opinions (Dict[OpinionTopicID, Opinion]):
A dictionary of Opinions. The keys are OpinionTopicIDs, and the values are Opinion objects. These are deep copied when the Person is initialised, so that the Person has their own opinions.
- add_opinion(opinion: Opinion, value: OpinionValue)
Add opinion to opinions.
- Args:
opinion: The Opinion to add. value: The OpinionValue to add for the opinion.
- communicate(i: int)
Communicate with another agent.
- Args:
i: The index of the agent to communicate with.
- Note:
This method should only be used when both self and the other agent are instances of Person (i.e., have an ‘opinions’ attribute). If not, the method will log a warning and do nothing.
- communicate_with_llm(message: str, model: str = None) dict
Communicate with an LLM to get a response based on the input message and model.
- Args:
message: The prompt to send to the LLM. model: The name of the LLM model to use (optional).
- Return:
The response from the LLM as a dictionary, or None if an error occurs
- get_age() int
Get the age in years based on the current year in the environment.
- Return:
Age in years, or None if year_of_birth is not set.
- get_gender() str
Get the gender as a string.
- Return:
Gender as a string.
- get_opinion(opinion_id: OpinionTopicID) Opinion
- Args:
opinion_id: The ID of the opinion to get.
- Return:
The Opinion object for the opinion_id, or None if not found.
- get_opinion_profile() str
An opinion profile is a summary of opinions reflecting the similarity and difference in opinions of the individual relative to their groups and others in the enviornment.
- Return:
A string summarizing the opinion profile.
- get_self_description() str
Get a self-description of the person.
- Return:
A string describing the person.
- set_opinion(opinion_id: OpinionTopicID, value: OpinionValue)
Set an opinion value.
- Args:
opinion_id: The ID of the opinion to set. value: The value to set the opinion to.
- year_of_birth
If year_of_birth is greater than the current year set year of birth to be the current year from the environment.