agent_basics
agent_basics
¶
Classes:
| Name | Description |
|---|---|
AgentBasics |
This class contains those methods and properties that are about building the agent, known agents, |
Classes¶
AgentBasics
¶
AgentBasics(proc: ModuleWrapper | Module | None, proc_inputs: list[Data4Proc] | None = None, proc_outputs: list[Data4Proc] | None = None, proc_opts: dict | None = None, behav: HybridStateMachine | None = None, behav_lone_wolf: HybridStateMachine | str = 'serve', merge_flat_stream_labels: bool = False, buffer_generated: bool = False, buffer_generated_by_others: str = 'none', world_folder: str | None = None)
This class contains those methods and properties that are about building the agent, known agents, known streams, etc., and no actions at all (see the class "Agent" for actions).
Create a new agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
proc
|
ModuleWrapper | Module | None
|
The processing module (e.g., a neural network) for the agent. Can be None or "default". |
required |
proc_inputs
|
list[Data4Proc] | None
|
list of DataProps defining the expected inputs for processor (if None it will be guessed). |
None
|
proc_outputs
|
list[Data4Proc] | None
|
list of DataProps defining the expected outputs from processor (if None it will be guessed). |
None
|
proc_opts
|
dict | None
|
A dictionary of options for the processor. |
None
|
behav
|
HybridStateMachine | None
|
The HybridStateMachine that describes the agent's behavior when joining a world. |
None
|
behav_lone_wolf
|
HybridStateMachine | str
|
The HybridStateMachine that describes the agent's behavior when in the public net (it can also be a string "serve" or "ask", that will load pre-designed HSMs). |
'serve'
|
merge_flat_stream_labels
|
bool
|
If True, merges flat stream labels across all owned streams. |
False
|
buffer_generated
|
bool
|
If True, generated streams will be buffered. |
False
|
buffer_generated_by_others
|
str
|
If set to "one" or "last", streams generated by other agents will be buffered ("one" per peer or "all"). If set to "none", no buffering will happen (default). |
'none'
|
world_folder
|
str | None
|
World only. Folder where the world data is (role files, represented by *.json behavior files). |
None
|
Methods:
| Name | Description |
|---|---|
set_node_info |
Set the required information from the node that hosts this agent. |
augment_roles |
Augment the custom roles (role1, role2, etc.) with the default ones (public, world_master, etc.), generating |
clear_world_related_data |
Destroy all the cached information that is about a world (useful when leaving a world). |
load_and_refactor_action_file_and_behav_files |
This method is called when building a world object. It loads the behavior files and refactors them. |
create_behav_files |
This method is called when building a world object. In your custom world-class, you can overload this method |
out |
Print a message to the console, if enabled at node level (it reuses the node-out-function). |
err |
Print an error message to the console, if enabled at node level (it reuses the node-err-function). |
deb |
Print an error message to the console, if debug is enabled for this agent (it reuses the agent-out-function). |
get_name |
Returns the name of the agent or world from the node's profile. |
get_profile |
Returns the profile of the node hosting this agent/world. |
get_current_role |
Returns the current role of the agent. |
add_agent |
Add a new known agent. |
remove_agent |
Remove an agent. |
remove_all_agents |
Remove all known agents. |
add_behav_wildcard |
Adds a wildcard mapping for the agent's behavior state machine. |
add_stream |
Add a new stream to the set of known streams. |
add_streams |
Add a list of new streams to this environment. |
remove_streams |
Remove a known stream. |
remove_all_streams |
Remove all not-owned streams. |
find_streams |
Find streams associated with a given peer ID and optionally by name or group. |
get_last_streamed_data |
Find streams associated with a given peer ID and optionally by name or group. |
merge_flat_data_stream_props |
Merge the labels of the descriptor components, across all streams, sharing them. |
user_stream_hash_to_net_hash |
Converts a user-defined stream hash (peer_id:name_or_group) to a network hash |
create_proc_output_streams |
Creates the processor output streams based on the |
add_compatible_streams |
Add to the list of processor-compatible-streams those streams provided as arguments that are actually |
subscribe_to_pubsub_owned_streams |
Subscribes to all owned streams that are marked as PubSub. |
update_streams_in_profile |
Updates the agent's profile with information about its owned (environmental and processor) streams. |
send_profile_to_all |
Sends the agent's profile to all known agents. |
generate |
Generate new signals. |
learn_generate |
Learn (i.e., update model params) by matching the given processor outputs with a set of targets (if any). |
behave |
Behave in the current environment, calling the state-machines of the public and private networks. |
learn_behave |
A placeholder method for behavioral learning, intended to be implemented by child classes. |
get_peer_ids |
Retrieve the public and private peer IDs of the agent, from the underlying node's dynamic profile. |
evaluate_profile |
Evaluate if a given profile is valid for this agent based on its role. It helps in identifying and filtering |
accept_new_role |
Set the agent's role and optionally load a default behavior (private/world behaviour). |
in_world |
Check if the agent is currently operating within a 'world'. |
behaving_in_world |
Checks if the agent's world-specific behavior state machine is currently active. |
get_stream_sample |
Receive and process stream samples that were provided by another agent. |
send_stream_samples |
Collect and send stream samples from all owned streams to appropriate recipients. |
get_action_step |
Retrieve the current action step from the agent's private/world behavior. |
is_last_action_step |
Check if the agent's current action (private/world behaviour) is on its last step. |
is_multi_steps_action |
Determines if the current action is a multistep action. |
proc_callback_inputs |
A callback method that saves the inputs to the processor right before execution. |
proc_callback_outputs |
A callback method that saves the outputs from the processor right after execution. |
save |
Save the agent's state, including its processor and other attributes, to a specified location. |
load |
Load the agent's state from a specified location. |
remove_peer_from_agent_status_attrs |
Remove a peer ID from the status of the agent, assuming it to be the represented by attributes that start |
reset_agent_status_attrs |
Resets attributes that represent the status of the agent, assuming to be the ones that start with '_'. |
Source code in unaiverse/agent_basics.py
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 108 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 | |
Methods:¶
set_node_info
¶
set_node_info(clock: Clock, conn: ConnectionPools, profile: NodeProfile, out_fcn, ask_to_get_in_touch_fcn, purge_fcn, agents_waiting, print_level)
Set the required information from the node that hosts this agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
clock
|
Clock
|
The global clock instance from the node. |
required |
conn
|
ConnectionPools
|
The connection pool manager from the node. |
required |
profile
|
NodeProfile
|
The profile of the hosting node. |
required |
out_fcn
|
The function to use for general output messages. |
required | |
ask_to_get_in_touch_fcn
|
The function to call to request getting in touch with another peer. |
required | |
purge_fcn
|
The function to call to purge (kill/disconnect) a connection. |
required | |
agents_waiting
|
Set of agents that connected to this node but have not been evaluated yet to be added. |
required | |
print_level
|
The level of output printing verbosity (0, 1, 2). |
required |
Source code in unaiverse/agent_basics.py
augment_roles
¶
Augment the custom roles (role1, role2, etc.) with the default ones (public, world_master, etc.), generating all the mixed roles (world_master~role1, world_master~role2, ...)
Source code in unaiverse/agent_basics.py
clear_world_related_data
¶
Destroy all the cached information that is about a world (useful when leaving a world).
Source code in unaiverse/agent_basics.py
load_and_refactor_action_file_and_behav_files
¶
This method is called when building a world object. It loads the behavior files and refactors them. It loads the action file agent.py. It checks consistency between the agent action files agent.py and the roles in the behavior files.
Args:
force_save: Boolean to force the saving of the JSON and of a "pdf" folder with the PDFs of the state
machines.
Source code in unaiverse/agent_basics.py
create_behav_files
¶
This method is called when building a world object. In your custom world-class, you can overload this method and create the JSON files with the role-related behaviors, if you like. Recall that acting like this is not mandatory at all: you can just manually create the JSON files, and this method will simply do nothing.
Source code in unaiverse/agent_basics.py
out
¶
Print a message to the console, if enabled at node level (it reuses the node-out-function).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msg
|
str
|
The message string to print. |
required |
err
¶
Print an error message to the console, if enabled at node level (it reuses the node-err-function).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msg
|
str
|
The error message string to print. |
required |
deb
¶
Print an error message to the console, if debug is enabled for this agent (it reuses the agent-out-function).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msg
|
str
|
The error message string to print. |
required |
Source code in unaiverse/agent_basics.py
get_name
¶
Returns the name of the agent or world from the node's profile.
Returns:
| Type | Description |
|---|---|
str
|
The name of the agent or world. |
get_profile
¶
get_profile() -> NodeProfile
Returns the profile of the node hosting this agent/world.
Returns:
| Type | Description |
|---|---|
NodeProfile
|
The NodeProfile of this node. |
get_current_role
¶
Returns the current role of the agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
return_int
|
bool
|
If True, returns the integer representation of the role. |
False
|
ignore_base_role
|
bool
|
If True, returns only the specific role part, not the base. |
True
|
Returns:
| Type | Description |
|---|---|
str | int | None
|
The role as a string or integer, or None if the agent is not living in any worlds. |
Source code in unaiverse/agent_basics.py
add_agent
¶
add_agent(peer_id: str, profile: NodeProfile) -> bool
Add a new known agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
peer_id
|
str
|
The unique identifier of the peer. |
required |
profile
|
NodeProfile
|
The NodeProfile object containing the peer's/agent's information. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the agent was successfully added, False otherwise. |
Source code in unaiverse/agent_basics.py
remove_agent
¶
Remove an agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
peer_id
|
str
|
The unique identifier of the peer to remove. |
required |
Source code in unaiverse/agent_basics.py
remove_all_agents
¶
Remove all known agents.
Source code in unaiverse/agent_basics.py
add_behav_wildcard
¶
Adds a wildcard mapping for the agent's behavior state machine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wildcard_from
|
str
|
The string to be used as a wildcard. |
required |
wildcard_to
|
object
|
The object to replace the wildcard. |
required |
Source code in unaiverse/agent_basics.py
add_stream
¶
add_stream(stream: DataStream, owned: bool = True, net_hash: str | None = None) -> dict[str, DataStream]
Add a new stream to the set of known streams.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stream
|
DataStream
|
The DataStream object to add. |
required |
owned
|
bool
|
If True, the streams are considered owned by this agent. |
True
|
net_hash
|
str | None
|
Optional network hash for the streams. If None, it will be generated. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, DataStream]
|
A dictionary containing the added stream and the possibly already present streams belonging to the same |
dict[str, DataStream]
|
group (stream name -> stream object). |
Source code in unaiverse/agent_basics.py
add_streams
¶
add_streams(streams: list[DataStream], owned: bool = True, net_hash: str | None = None) -> list[dict[str, DataStream]]
Add a list of new streams to this environment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
streams
|
list[DataStream]
|
A list of DataStream objects to add. |
required |
owned
|
bool
|
If True, the streams are considered owned by this agent. |
True
|
net_hash
|
str | None
|
Optional network hash for the streams. If None, it will be generated for each. |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, DataStream]]
|
A list of dictionaries (it could be empty in case of issues), where each dictionary is what |
list[dict[str, DataStream]]
|
is returned by add_stream(). |
Source code in unaiverse/agent_basics.py
remove_streams
¶
Remove a known stream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
peer_id
|
str
|
The hash of each stream included the peer ID of the owner, so this is the peer ID associated with the stream(s) to remove. |
required |
name
|
str | None
|
The optional name of the stream to remove. If None, all streams with this peer_id are removed. |
None
|
owned_too
|
bool
|
If True, also removes streams from the owned stream dict (so also environmental and processor). |
False
|
Source code in unaiverse/agent_basics.py
remove_all_streams
¶
Remove all not-owned streams.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
owned_too
|
bool
|
If True, also removes the owned streams of this agent (so also environmental and processor ones). |
False
|
Source code in unaiverse/agent_basics.py
find_streams
¶
find_streams(peer_id: str, name_or_group: str | None = None) -> dict[str, dict[str, DataStream]]
Find streams associated with a given peer ID and optionally by name or group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
peer_id
|
str
|
The peer ID of the (owner of the) streams to find. |
required |
name_or_group
|
str | None
|
Optional name or group of the streams to find. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, DataStream]]
|
A dictionary where keys are network hashes and values are dictionaries of streams |
dict[str, dict[str, DataStream]]
|
(stream name to DataStream object) matching the criteria. |
Source code in unaiverse/agent_basics.py
get_last_streamed_data
¶
Find streams associated with a given peer ID and optionally by name or group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_name
|
str
|
The name of the agent. |
required |
Returns:
| Type | Description |
|---|---|
|
A list of data samples taken from all the known streams associated to the provided agent. |
Source code in unaiverse/agent_basics.py
merge_flat_data_stream_props
¶
Merge the labels of the descriptor components, across all streams, sharing them.
Source code in unaiverse/agent_basics.py
user_stream_hash_to_net_hash
¶
Converts a user-defined stream hash (peer_id:name_or_group) to a network hash
(peer_id:... or peer_id:
name_or_group) by searching the known hashes in the known streams.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_stream_hash
|
str
|
The user-defined stream hash string (peer_id:name_or_group). |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The corresponding network hash string (peer_id: |
Source code in unaiverse/agent_basics.py
create_proc_output_streams
¶
Creates the processor output streams based on the proc_outputs defined for the agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
buffered
|
bool
|
If True, the created streams will be of type BufferedDataStream. |
False
|
Source code in unaiverse/agent_basics.py
add_compatible_streams
¶
add_compatible_streams(peer_id: str, streams_in_profile: list[DataProps], buffered: bool = False, add_all: bool = False, public: bool = True) -> bool
Add to the list of processor-compatible-streams those streams provided as arguments that are actually found to be compatible with the processor (if they are pubsub, it also subscribes to them).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
peer_id
|
str
|
The peer ID of the agent providing the streams. |
required |
streams_in_profile
|
list[DataProps]
|
A list of DataProps objects representing the streams from the peer's profile. |
required |
buffered
|
bool
|
If True, the added streams will be of type BufferedDataStream. |
False
|
add_all
|
bool
|
If True, all streams from the profile are added, regardless of processor compatibility. |
False
|
public
|
bool
|
Consider public streams only (or private streams only). |
True
|
Returns:
| Type | Description |
|---|---|
bool
|
True if compatible streams were successfully added and subscribed to, False otherwise. |
Source code in unaiverse/agent_basics.py
856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 | |
subscribe_to_pubsub_owned_streams
¶
Subscribes to all owned streams that are marked as PubSub.
Returns:
| Type | Description |
|---|---|
bool
|
True if all subscriptions were successful, False otherwise. |
Source code in unaiverse/agent_basics.py
update_streams_in_profile
¶
Updates the agent's profile with information about its owned (environmental and processor) streams.
Source code in unaiverse/agent_basics.py
send_profile_to_all
¶
Sends the agent's profile to all known agents.
Source code in unaiverse/agent_basics.py
generate
¶
generate(input_net_hashes: list[str] | None = None, inputs: list[str | Tensor | Image] | None = None, first: bool = False, last: bool = False, ref_uuid: str | None = None) -> tuple[tuple[Tensor] | None, int]
Generate new signals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_net_hashes
|
list[str] | None
|
A list of network hashes to be considered as input streams (they will be sub-selected). |
None
|
inputs
|
list[str | Tensor | Image] | None
|
A list of data to be directly provided as input to the processor (if not None, input_net_hashes is ignored). |
None
|
first
|
bool
|
If True, indicates this is the first generation call in a sequence. |
False
|
last
|
bool
|
If True, indicates this is the last generation call in a sequence. |
False
|
ref_uuid
|
str | None
|
An optional UUID to match against input stream UUIDs (it can be None). |
None
|
Returns:
| Type | Description |
|---|---|
tuple[tuple[Tensor] | None, int]
|
A tuple containing: - A tuple of torch.Tensor objects representing the generated output, or None if generation failed. - An integer representing a data tag or status. |
Source code in unaiverse/agent_basics.py
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 | |
learn_generate
¶
learn_generate(outputs: tuple[Tensor], targets_net_hashes: list[str] | None) -> tuple[list[float] | None, list[float] | None]
Learn (i.e., update model params) by matching the given processor outputs with a set of targets (if any).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outputs
|
tuple[Tensor]
|
A tuple of torch.Tensor representing the outputs generated by the agent's processor. |
required |
targets_net_hashes
|
list[str] | None
|
An optional list of network hashes identifying the streams from which target data should be retrieved for learning. If None, losses are evaluated without explicit targets. |
required |
Returns:
| Type | Description |
|---|---|
list[float] | None
|
A tuple containing: |
list[float] | None
|
|
tuple[list[float] | None, list[float] | None]
|
|
Source code in unaiverse/agent_basics.py
1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 | |
behave
¶
Behave in the current environment, calling the state-machines of the public and private networks.
Source code in unaiverse/agent_basics.py
learn_behave
¶
A placeholder method for behavioral learning, intended to be implemented by child classes. It receives state and action information to update a behavioral model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
int
|
The current state of the agent. |
required |
last_action
|
int
|
The last action taken. |
required |
prev_state
|
int
|
The previous state of the agent. |
required |
Returns:
| Type | Description |
|---|---|
|
An integer representing a new state, or similar feedback. |
Source code in unaiverse/agent_basics.py
get_peer_ids
¶
Retrieve the public and private peer IDs of the agent, from the underlying node's dynamic profile.
Returns:
| Type | Description |
|---|---|
|
A tuple containing the public peer ID and the private peer ID. |
|
|
If either ID is not available, a placeholder string is returned |
Source code in unaiverse/agent_basics.py
evaluate_profile
¶
evaluate_profile(role: int, profile: NodeProfile) -> bool
Evaluate if a given profile is valid for this agent based on its role. It helps in identifying and filtering out invalid or 'cheating' profiles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
role
|
int
|
The expected integer role (e.g., ROLE_PUBLIC, ROLE_WORLD_MASTER) for the profile. |
required |
profile
|
NodeProfile
|
The NodeProfile object to be evaluated. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the profile is considered valid for the specified role, False otherwise. |
Source code in unaiverse/agent_basics.py
accept_new_role
¶
Set the agent's role and optionally load a default behavior (private/world behaviour).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
role
|
int
|
The integer role to assign to the agent (e.g., ROLE_PUBLIC, ROLE_WORLD_MASTER). |
required |
Source code in unaiverse/agent_basics.py
in_world
¶
Check if the agent is currently operating within a 'world'.
Returns:
| Type | Description |
|---|---|
|
True if the agent is in a world, False otherwise. |
Source code in unaiverse/agent_basics.py
behaving_in_world
¶
Checks if the agent's world-specific behavior state machine is currently active.
Returns:
| Type | Description |
|---|---|
|
True if the world behavior is active, False otherwise. |
get_stream_sample
¶
Receive and process stream samples that were provided by another agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
net_hash
|
str
|
The network hash identifying the source of the stream samples. |
required |
sample_dict
|
dict[str, dict[str, Tensor | None | int | str]]
|
A dictionary where keys are stream names and values are dictionaries containing 'data', 'data_tag', and 'data_uuid' for each sample. |
required |
Returns:
| Type | Description |
|---|---|
|
True if the stream samples were successfully processed and stored, False otherwise |
|
|
(e.g., if the stream is unknown, not compatible, or data is None/stale). |
Source code in unaiverse/agent_basics.py
1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 | |
send_stream_samples
¶
Collect and send stream samples from all owned streams to appropriate recipients.
Source code in unaiverse/agent_basics.py
1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 | |
get_action_step
¶
Retrieve the current action step from the agent's private/world behavior.
Returns:
| Type | Description |
|---|---|
|
The current action step object from the HybridStateMachine's active action, or None if no action. |
Source code in unaiverse/agent_basics.py
is_last_action_step
¶
Check if the agent's current action (private/world behaviour) is on its last step.
Returns:
| Type | Description |
|---|---|
|
True if the current action was its last step, False otherwise. Returns None if there is no active action. |
Source code in unaiverse/agent_basics.py
is_multi_steps_action
¶
Determines if the current action is a multistep action.
Returns:
| Type | Description |
|---|---|
|
True if the action is multistep, False otherwise. |
Source code in unaiverse/agent_basics.py
proc_callback_inputs
¶
A callback method that saves the inputs to the processor right before execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
The data inputs for the processor. |
required |
Returns:
| Type | Description |
|---|---|
|
The same inputs passed to the function. |
Source code in unaiverse/agent_basics.py
proc_callback_outputs
¶
A callback method that saves the outputs from the processor right after execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outputs
|
The data outputs from the processor. |
required |
Returns:
| Type | Description |
|---|---|
|
The same outputs passed to the function. |
Source code in unaiverse/agent_basics.py
save
¶
Save the agent's state, including its processor and other attributes, to a specified location.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
where
|
str
|
The directory path where the agent's state should be saved. Defaults to "output". |
'output'
|
Returns:
| Type | Description |
|---|---|
|
The string " |
Raises:
| Type | Description |
|---|---|
IOError
|
If there is an issue with file operations (e.g., directory creation, writing files). |
(TypeError, ValueError, RuntimeError)
|
For other potential issues during serialization or saving. |
Source code in unaiverse/agent_basics.py
load
¶
Load the agent's state from a specified location.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
where
|
str
|
The directory path from which the agent's state should be loaded. Defaults to "output". |
'output'
|
Returns:
| Type | Description |
|---|---|
|
The loaded AgentBasics object. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If the specified load path does not exist. |
IOError
|
If there is an issue with file operations (e.g., reading files). |
Source code in unaiverse/agent_basics.py
remove_peer_from_agent_status_attrs
¶
Remove a peer ID from the status of the agent, assuming it to be the represented by attributes that start with '_'.
Source code in unaiverse/agent_basics.py
reset_agent_status_attrs
¶
Resets attributes that represent the status of the agent, assuming to be the ones that start with '_'.