world
world
¶
Classes:
| Name | Description |
|---|---|
World |
|
Classes¶
World
¶
Bases: AgentBasics
Initializes a World object, which acts as a special agent without a processor or behavior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
world_folder
|
str
|
The path of the world folder, with JSON files of the behaviors (per role) and agent.py. |
required |
Methods:
| Name | Description |
|---|---|
assign_role |
Assigns an initial role to a newly connected agent. |
set_role |
Sets a new role for a specific agent and broadcasts this change to the agent. |
set_addresses_in_profile |
Updates the network addresses in an agent's profile. |
add_badge |
Requests a badge for a specific agent, which can be used to track and reward agent performance. |
get_all_badges |
Retrieves all badges that have been added to the world's record for all agents. |
clear_badges |
Clears all badge records from the world's memory. |
Source code in unaiverse/world.py
Methods:¶
assign_role
¶
assign_role(profile: NodeProfile, is_world_master: bool) -> str
Assigns an initial role to a newly connected agent.
In this basic implementation, the role is determined based on whether the agent is a world master or a regular world agent, ensuring there's only one master.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
profile
|
NodeProfile
|
The NodeProfile of the new agent. |
required |
is_world_master
|
bool
|
A boolean indicating if the new agent is attempting to be a master. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A string representing the assigned role. |
Source code in unaiverse/world.py
set_role
¶
Sets a new role for a specific agent and broadcasts this change to the agent.
It computes the new role and sends a message containing the new role and the corresponding default behavior for that role.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
peer_id
|
str
|
The ID of the agent whose role is to be set. |
required |
role
|
int
|
The new role to be assigned (as an integer). |
required |
Source code in unaiverse/world.py
set_addresses_in_profile
¶
Updates the network addresses in an agent's profile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
peer_id
|
The ID of the agent whose profile is being updated. |
required | |
addresses
|
A list of new addresses to set. |
required |
Source code in unaiverse/world.py
add_badge
¶
add_badge(peer_id: str, score: float, badge_type: str, agent_token: str, badge_description: str | None = None)
Requests a badge for a specific agent, which can be used to track and reward agent performance. It validates the score and badge type and stores the badge information in an internal dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
peer_id
|
str
|
The ID of the agent for whom the badge is requested. |
required |
score
|
float
|
The score associated with the badge (must be in [0, 1]). |
required |
badge_type
|
str
|
The type of badge to be awarded. |
required |
agent_token
|
str
|
The token of the agent receiving the badge. |
required |
badge_description
|
str | None
|
An optional text description for the badge. |
None
|
Source code in unaiverse/world.py
get_all_badges
¶
Retrieves all badges that have been added to the world's record for all agents. This provides a central log of achievements or performance metrics.
Returns:
| Type | Description |
|---|---|
|
A dictionary where keys are agent peer IDs and values are lists of badge dictionaries. |
Source code in unaiverse/world.py
clear_badges
¶
Clears all badge records from the world's memory. This can be used to reset competition results or clean up state after a specific event.