unaiverse.interaction
What this module does 🔴
Models inter-agent interactions and their lifecycle, with an InteractionManager that registers, matches, resolves and completes sent/received/lazy interactions across streams.
interaction
¶
█████ █████ ██████ █████ █████ █████ █████ ██████████ ███████████ █████████ ██████████ ░░███ ░░███ ░░██████ ░░███ ░░███ ░░███ ░░███ ░░███░░░░░█░░███░░░░░███ ███░░░░░███░░███░░░░░█ ░███ ░███ ░███░███ ░███ ██████ ░███ ░███ ░███ ░███ █ ░ ░███ ░███ ░███ ░░░ ░███ █ ░ ░███ ░███ ░███░░███░███ ░░░░░███ ░███ ░███ ░███ ░██████ ░██████████ ░░█████████ ░██████ ░███ ░███ ░███ ░░██████ ███████ ░███ ░░███ ███ ░███░░█ ░███░░░░░███ ░░░░░░░░███ ░███░░█ ░███ ░███ ░███ ░░█████ ███░░███ ░███ ░░░█████░ ░███ ░ █ ░███ ░███ ███ ░███ ░███ ░ █ ░░████████ █████ ░░█████░░████████ █████ ░░███ ██████████ █████ █████░░█████████ ██████████ ░░░░░░░░ ░░░░░ ░░░░░ ░░░░░░░░ ░░░░░ ░░░ ░░░░░░░░░░ ░░░░░ ░░░░░ ░░░░░░░░░ ░░░░░░░░░░ A Collectionless AI Project (https://collectionless.ai) Registration/Login: https://unaiverse.io Code Repositories: https://github.com/collectionlessai/ Main Developers: Stefano Melacci (Project Leader), Christian Di Maio, Tommaso Guidi
Interaction
¶
Interaction(action_name: str | None = None, action_kwargs: dict | None = None, streams: dict[str, str] | list[str] | None = None, data_samples: list | dict | None = None, num_steps: int = -1, requester: str | None = None, target: str | list[str] | None = None, from_state: str | None = None, to_state: str | None = None, timeout: float = -1.0, callback: str | None = None, volatile: bool = False, forced_uuid: str | None = 'do_not_force', id: str | None = 'random')
A single interaction between agents in the UNaIVERSE network.
An Interaction is the fundamental unit of communication between agents. It
encapsulates the requested action (by name and keyword arguments), the set of data
streams or concrete data samples to be exchanged, timing and timeout information,
status tracking, and the stream-based data-access interface exposed to the processor.
Interactions can be created by the local agent (and then registered as
InteractionType.SENT or InteractionType.LAZY) or received from a remote
agent (InteractionType.RECEIVED). In all cases an Interaction goes through
the state machine defined by InteractionStatus: CREATED -> REQUESTED/
RECEIVED/LAZY -> RUNNING <-> PAUSED -> COMPLETED.
Streams attached to an interaction are organized in three categories:
stdin_streams: processor input streams.stdtar_streams: processor target (output reference) streams.stdext_streams: extra streams not consumed by the processor directly.
A StreamProxy provides unified read/write access across all attached streams.
Attributes:
| Name | Type | Description |
|---|---|---|
requester |
str | None
|
Peer ID of the agent that originated this interaction, or |
target |
list[str | None]
|
List of peer IDs of the agents that should handle the interaction. |
id |
str
|
Short identifier string (not necessarily unique; used to build |
uuid |
str
|
Fully-qualified unique identifier built from |
action_name |
str
|
Name of the action being requested (e.g. |
action_kwargs |
dict
|
Keyword arguments forwarded to the action. |
streams |
dict
|
Parsed stream specification dict with keys |
data_samples |
list
|
List of concrete data objects attached to the interaction when no stream-based specification is used. |
num_steps |
int
|
Total number of execution steps for the interaction, or |
from_state |
str | None
|
Name of the HSM state from which the interaction is expected to originate. |
to_state |
str | None
|
Name of the HSM state the interaction is expected to yield. |
timeout |
float
|
Maximum lifetime of the interaction in seconds; |
status |
InteractionStatus
|
Current |
volatile |
When |
|
callback |
Name of the agent method to invoke when the interaction completes. |
|
completion_reason |
CompletionReason | None
|
|
destination_state |
str | None
|
Name of the HSM state reached after completion (set by the action handler). |
stream_proxy |
|
Examples:
Create a minimal interaction requesting a "process" action on a remote agent:
>>> from unaiverse.interaction import Interaction
>>> inter = Interaction(
... action_name="process",
... action_kwargs={"mode": "fast"},
... requester="peer_abc",
... target="peer_xyz",
... )
>>> inter.uuid
'..._peer_abc'
Create a data-carrying interaction using concrete samples:
>>> import torch
>>> tensor = torch.zeros(3, 224, 224)
>>> inter = Interaction(
... action_name="infer",
... data_samples=[tensor],
... requester="peer_abc",
... target="peer_xyz",
... )
>>> inter.num_steps
1
Initialize a new Interaction with all its identity, data, and timing fields.
Builds the unique identifier (uuid) from id and requester via
build_uuid, then parses and normalizes streams or data_samples
into the internal stream dictionaries. If both streams and data_samples
are provided, data_samples is ignored in favour of the stream specification.
When data_samples is a JSON string it is deserialized from base-64-encoded
payload format. When it is a plain Python list it is stored as-is. In either
case num_steps is forced to 1.
A GenException is raised immediately if both callback and volatile
are set, because a volatile interaction never sends back a completion status and
therefore the callback would never be invoked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action_name
|
str | None
|
Name of the action being requested (e.g. |
None
|
action_kwargs
|
dict | None
|
Keyword arguments for the action. Must not contain stream
objects. Defaults to |
None
|
streams
|
dict[str, str] | list[str] | None
|
Stream specification. Either a plain list of stream hashes
(user hash, net hash, name, or group), or a dict with keys
|
None
|
data_samples
|
list | dict | None
|
Concrete data samples to attach (used when no stream
specification is given). Can be a list of objects (e.g.
|
None
|
num_steps
|
int
|
Total number of execution steps (-1 for non-data-based
interactions). Overridden to |
-1
|
requester
|
str | None
|
Peer ID of the agent originating this interaction. Defaults to None, which indicates a system-generated interaction. |
None
|
target
|
str | list[str] | None
|
Peer ID of the target agent, or a list of peer IDs. Defaults to None. |
None
|
from_state
|
str | None
|
Name of the HSM state from which this interaction is expected to originate. Defaults to None. |
None
|
to_state
|
str | None
|
Name of the HSM state this interaction is expected to yield. Defaults to None. |
None
|
timeout
|
float
|
Maximum lifetime in seconds; |
-1.0
|
callback
|
str | None
|
Name of an agent method to call when this interaction completes.
The method must accept a single |
None
|
volatile
|
bool
|
When |
False
|
forced_uuid
|
str | None
|
Overrides the automatically built UUID. |
'do_not_force'
|
id
|
str | None
|
Short identifier string (not guaranteed to be unique across agents).
|
'random'
|
Raises:
| Type | Description |
|---|---|
GenException
|
If both |
Source code in unaiverse/interaction.py
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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
target
instance-attribute
¶
id
instance-attribute
¶
id: str = hex[0:8] if id is not None and id == 'random' else id if id is not None else SYSTEM_INTERACTION_UUID
action_kwargs
instance-attribute
¶
target_data_tags
instance-attribute
¶
target_timestamp_completed
instance-attribute
¶
target_completion_reason
instance-attribute
¶
target_completion_reason: list[CompletionReason | None] = [None] * len(target)
target_destination_state
instance-attribute
¶
created
property
¶
Return True when the interaction has been created but not yet dispatched.
An interaction is in the CREATED state immediately after __init__
and before any InteractionManager registration step transitions it to
REQUESTED, RECEIVED, or LAZY.
Returns:
| Type | Description |
|---|---|
bool
|
|
completed
property
¶
Return True when the interaction has finished executing.
An interaction enters the COMPLETED state via mark_completed (called
directly) or via InteractionManager.complete. Once completed it is moved
to the recently-completed set and eventually drained by drain_completed.
The completion_reason attribute records the cause.
Returns:
| Type | Description |
|---|---|
bool
|
|
running
property
¶
Return True when the interaction is actively being executed.
An interaction enters the RUNNING state when it is set as the current
interaction by InteractionManager.set_current, which calls
mark_running. It transitions back to PAUSED if another interaction
preempts it, or to COMPLETED when the action finishes.
Returns:
| Type | Description |
|---|---|
bool
|
|
paused
property
¶
Return True when the interaction has been temporarily suspended.
An interaction is paused when another interaction is set as current by
InteractionManager.set_current_as_paused, which calls mark_paused.
A paused interaction may be resumed later by setting it as the current one
again.
Returns:
| Type | Description |
|---|---|
bool
|
|
registered_as_sent
property
¶
Return True when this interaction was registered as sent by the local agent.
The type attribute is set to InteractionType.SENT by
InteractionManager.register_sent. A sent interaction tracks a request
that the local agent dispatched to a remote target.
Returns:
| Type | Description |
|---|---|
bool
|
|
registered_as_received
property
¶
Return True when this interaction was registered as received from another agent.
The type attribute is set to InteractionType.RECEIVED by
InteractionManager.register_received. A received interaction represents a
request that a remote agent sent to the local agent.
Returns:
| Type | Description |
|---|---|
bool
|
|
build_uuid
staticmethod
¶
Build the canonical UUID string for an interaction from its id and requester.
The UUID is the concatenation of id and requester separated by "_".
If id is None it is replaced by Custom.SYSTEM_INTERACTION_ID; if
requester is None it is replaced by Custom.SYSTEM_INTERACTION_LABEL.
The resulting UUID uniquely identifies the interaction within the session because
it encodes both the short local identifier and the originating peer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str | None
|
Short identifier part of the UUID. |
required |
requester
|
str | None
|
Peer ID part of the UUID. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
A string of the form |
Examples:
>>> Interaction.build_uuid("abc12345", "peer_xyz")
'abc12345_peer_xyz'
>>> Interaction.build_uuid(None, None) # system interaction UUID
'system_system'
Source code in unaiverse/interaction.py
get_id_from_uuid
staticmethod
¶
Extract the short id component from a full interaction UUID.
The UUID format is "<id>_<requester>". This method splits on the first
underscore and returns the left part. It is the inverse of the first argument
passed to build_uuid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid
|
str
|
A UUID string previously produced by |
required |
Returns:
| Type | Description |
|---|---|
str
|
The |
Examples:
Source code in unaiverse/interaction.py
registered_as_lazy
¶
Return True when this interaction was registered as lazy by the local agent.
The type attribute is set to InteractionType.LAZY by
InteractionManager.register_lazy. A lazy interaction is one that the local
agent generated internally (not dispatched from, or received from, a remote peer)
and that targets either a local action or a remote agent.
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in unaiverse/interaction.py
update_target
¶
Replace the target list and reset all per-target tracking arrays.
When the destination of an interaction changes after construction (for example
when the InteractionManager resolves an agent name to its peer ID), this
method updates target and reinitializes every array that is indexed in
parallel with it: target_completion_reason, target_data_tags,
target_timestamp_completed, target_destination_state, and
target_cycle_completed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str | list[str]
|
New target peer ID, or a list of peer IDs. A bare string is automatically wrapped in a list. |
required |
Source code in unaiverse/interaction.py
set_manager
¶
set_manager(im: InteractionManager, stdin_streams: dict[str, Stream | object], stdtar_streams: dict[str, Stream | object], stdext_streams: dict[str, Stream | object], owned_streams: dict[str, Stream | object]) -> None
Bind this interaction to its owning InteractionManager and initialize its stream references.
Records the creation time (timestamp_created and cycle_created) from the
global clock, stores the four stream dictionaries, and binds the stream_proxy
to the union of all provided streams plus any concrete data samples. This method
is called by InteractionManager.register_sent and
InteractionManager.__register_received_or_lazy immediately after the streams
have been matched and validated.
After this call the interaction's stream_proxy provides unified access to
all attached streams and data samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
im
|
InteractionManager
|
The |
required |
stdin_streams
|
dict[str, Stream | object]
|
Mapping from user hash to stream objects used as processor input arguments. |
required |
stdtar_streams
|
dict[str, Stream | object]
|
Mapping from user hash to stream objects used as processor target (output reference) arguments. |
required |
stdext_streams
|
dict[str, Stream | object]
|
Mapping from user hash to stream objects that are extra (not consumed directly by the processor). |
required |
owned_streams
|
dict[str, Stream | object]
|
Mapping from user hash to stream objects owned by the local agent (a subset of the union of the three dicts above). |
required |
Note
Data samples stored in data_samples are also exposed through the
stream_proxy under synthetic keys of the form "<data_sample_i>".
Source code in unaiverse/interaction.py
reset_state
¶
Reset the execution state of the interaction so it can be re-run from the beginning.
Clears the step index (set to -1, meaning no steps done yet), the
starting-time record, and the timeout-baseline time. The interaction status
and stream bindings are not touched, so the caller is responsible for setting
the status back to a suitable value before re-scheduling the interaction.
Note
This is intended for internal framework use (e.g., when an action retries after a transient failure). User code should rarely need to call it directly.
Source code in unaiverse/interaction.py
set_mark
¶
Store an arbitrary marker object on the interaction.
The mark is a free-form annotation slot that action handlers can use to
attach bookkeeping data to the interaction without adding new attributes.
It is initialized to None and is not serialized by to_dict.
Use get_mark to retrieve the value and clear_mark to remove it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mark
|
object
|
Any Python object to associate with this interaction. |
required |
Source code in unaiverse/interaction.py
get_mark
¶
Return the marker object previously stored by set_mark.
Returns:
| Type | Description |
|---|---|
object
|
The marker object, or |
object
|
cleared by |
clear_mark
¶
Remove the marker object previously stored by set_mark.
Sets the internal mark to None. Equivalent to calling
set_mark(None).
get_step_idx
¶
Return the index of the last completed execution step.
The step index starts at -1 (no steps done yet) and is incremented by
inc_step_idx each time the action completes a step. The final step index
is num_steps - 1 for data-carrying interactions, or 0 for interactions
with no data steps (num_steps < 0).
Returns:
| Type | Description |
|---|---|
int
|
An integer step index. |
Source code in unaiverse/interaction.py
set_step_idx
¶
Directly assign the current execution step index.
Prefer inc_step_idx for normal step advancement. Use this method only
when the framework needs to restore or override the step counter (for example
when retrying or replaying an interaction).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
steps
|
int
|
The step index to assign. |
required |
Source code in unaiverse/interaction.py
inc_step_idx
¶
Increment the execution step index by one.
Called by the action handler after each successful step. The step index
transitions from -1 to 0 on the first step, then increases until
was_last_step_done returns True.
Note
The complementary dec_step_idx method decrements the counter by one
and is available for special retry scenarios.
Source code in unaiverse/interaction.py
dec_step_idx
¶
Decrement the execution step index by one.
Reverses the effect of inc_step_idx. Intended for special retry scenarios where the
framework needs to re-execute the last step (for example when a transient transmission
error means the step result was not delivered and must be regenerated). Normal action
handlers should rely on inc_step_idx instead.
Note
The complementary inc_step_idx method increments the counter by one and is the
standard way to advance through interaction steps.
Source code in unaiverse/interaction.py
set_starting_time
¶
Record the wall-clock time at which execution of this interaction started.
The stored value is later read by is_timed_out to evaluate the global
total_time limit of the associated action: if more than action_ref.get_total_time()
seconds have elapsed since this timestamp, the interaction is considered timed out.
Retrieve the stored value with get_starting_time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
Starting timestamp in seconds, as returned by |
required |
Note
This method is called by the action scheduling machinery and is not meant to be called from user code.
Source code in unaiverse/interaction.py
set_timeout_starting_time
¶
Record the wall-clock time used as the baseline for per-step timeout checks.
The stored value is read by is_timed_out to evaluate the next-step retry timeout
limit of the associated action: if more than action_ref.get_timeout() seconds have
elapsed since this timestamp, the interaction is considered timed out at the step level.
Retrieve the stored value with get_timeout_starting_time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
Timeout baseline timestamp in seconds, as returned by |
required |
Note
This is distinct from the global starting_time (set by set_starting_time),
which guards the total lifetime of the interaction. The per-step timeout resets each
time the action scheduler records a new attempt, whereas the global timeout is set
once when execution first begins.
Source code in unaiverse/interaction.py
get_total_steps
¶
Return the total number of execution steps configured for this interaction.
The value mirrors the num_steps attribute, which is set at construction time and
may be overridden to 1 when data_samples is provided. A value of -1 means
the interaction carries no data-based steps (e.g. a pure control message). A positive
integer indicates the exact number of steps the action handler must complete before
was_last_step_done returns True.
Returns:
| Type | Description |
|---|---|
int
|
The total step count. |
int
|
single-sample interactions, or a larger positive integer for multi-step ones. |
Source code in unaiverse/interaction.py
get_starting_time
¶
Return the wall-clock timestamp at which execution of this interaction started.
The value is set by set_starting_time when the action scheduling machinery first
begins executing this interaction. is_timed_out uses this timestamp to evaluate the
global total_time limit defined by the associated action. A value of 0. means
execution has not yet begun.
Returns:
| Type | Description |
|---|---|
float
|
A float timestamp in seconds ( |
float
|
has not started yet. |
Source code in unaiverse/interaction.py
get_timeout_starting_time
¶
Return the wall-clock timestamp used as the baseline for per-step timeout checks.
The value is set by set_timeout_starting_time each time the action scheduler records
a new execution attempt. is_timed_out compares the elapsed time since this baseline
against the per-step retry timeout defined by the associated action. A value of 0.
means no per-step timeout baseline has been recorded yet.
Returns:
| Type | Description |
|---|---|
float
|
A float timestamp in seconds ( |
float
|
per-step timeout baseline has been set yet. |
Source code in unaiverse/interaction.py
is_multi_steps
¶
Return True if this interaction requires more than one execution step.
An interaction is considered multi-step when num_steps is a plain integer greater
than 1, OR when num_steps is a string (a wildcard placeholder such as
"<eval_steps>" that will be resolved at runtime by the action handler before
execution begins). Single-sample interactions (num_steps == 1) and data-free
interactions (num_steps < 0) return False.
Returns:
| Type | Description |
|---|---|
bool
|
|
Note
The string case occurs when the behaviour JSON specifies a wildcard number of
steps. The action scheduling machinery resolves such placeholders before the
first step is attempted, at which point num_steps becomes a plain integer.
Source code in unaiverse/interaction.py
is_single_step
¶
Return True if this interaction completes in a single execution step.
An interaction is single-step when num_steps equals 1 (exactly one data
sample attached) or when num_steps is negative (a pure control or data-free
interaction). In both cases was_last_step_done will return True after the
first step increment.
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in unaiverse/interaction.py
is_valid
¶
Return True if the interaction has been fully registered with its action.
An interaction is valid once the action has assigned both by_insertion_order_id
(a global monotonic index among all interactions handled by the action) and
by_requester_insertion_order_id (a per-requester monotonic index). Both start at
-1 and are set to non-negative values during action registration.
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
are greater than or equal to |
Source code in unaiverse/interaction.py
is_system
¶
Return True if this interaction was generated by the framework itself.
System interactions are those whose requester equals
Custom.SYSTEM_INTERACTION_LABEL. They are created internally by the UNaIVERSE
framework (for example to drive lifecycle transitions) rather than by a remote peer.
System interactions have no owning InteractionManager and are always considered
doable as long as they are not yet completed (see check_if_doable).
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in unaiverse/interaction.py
is_completed
¶
Return True if this interaction has reached the COMPLETED status.
Equivalent to the completed property, provided as a regular method for
contexts where a callable is required (for example when passing as a predicate).
Once completed, completion_reason and destination_state are populated and
the interaction is moved to the recently-completed set by the
InteractionManager.
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in unaiverse/interaction.py
was_data_sent_after_completion
¶
Return True if data was generated and sent after this interaction completed.
The data_sent_after_completion flag is set by the agent's output machinery when it
detects that a stream write occurred after the interaction's status transitioned to
COMPLETED. This typically happens in edge cases where the action handler produces
a final output sample concurrently with the completion event.
Returns:
| Type | Description |
|---|---|
bool
|
|
Note
This flag is informational and is used for logging and diagnostics. It does not affect the completion status of the interaction itself.
Source code in unaiverse/interaction.py
has_dummy_requester
¶
Return True if no requester peer ID is set on this interaction.
A None requester indicates that the interaction was created without an explicit
originating peer, for example as a placeholder or an internally generated trigger.
This is distinct from a system interaction (is_system), where requester is
set to Custom.SYSTEM_INTERACTION_LABEL rather than None.
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in unaiverse/interaction.py
set_arg
¶
Set or overwrite a keyword argument in action_kwargs.
Inserts or replaces the entry arg_name in action_kwargs. Unlike
alter_arg, this method always writes the value regardless of whether the key
was previously present.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg_name
|
str
|
The name of the argument to set. |
required |
arg_value
|
object
|
The value to assign to the argument. |
required |
Examples:
>>> inter = Interaction(action_name="process", requester="peer_abc")
>>> inter.set_arg("mode", "fast")
>>> inter.get_arg("mode")
'fast'
Source code in unaiverse/interaction.py
get_arg
¶
Retrieve a keyword argument from action_kwargs by name.
Looks up arg_name in action_kwargs and returns the associated value.
If the key is absent, returns None rather than raising KeyError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg_name
|
str
|
The name of the argument to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
object
|
The argument value, or |
object
|
|
Examples:
>>> inter = Interaction(action_name="process", action_kwargs={"mode": "fast"},
... requester="peer_abc")
>>> inter.get_arg("mode")
'fast'
>>> inter.get_arg("missing") is None
True
Source code in unaiverse/interaction.py
was_at_least_one_step_done
¶
Return True if at least one execution step has been completed.
The internal step index starts at -1 (no steps done). After the first successful
call to inc_step_idx the index becomes 0 and this method returns True.
Use get_step_idx to retrieve the exact index of the last completed step.
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in unaiverse/interaction.py
was_last_step_done
¶
Return True if all execution steps for this interaction have been completed.
The completion criterion depends on the step model:
- For data-free interactions (
num_steps < 0): returnsTruewhen the step index reaches0, meaning a single "no-data" cycle was executed. - For data-carrying interactions (
num_steps > 0): returnsTruewhen the step index equalsnum_steps - 1, meaning every data sample has been processed.
This is the primary predicate used by action handlers to decide whether to trigger
completion via InteractionManager.complete or InteractionManager.complete_current.
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in unaiverse/interaction.py
is_delayed
¶
Return True if the action associated with this interaction is still in its mandatory delay period.
The delay is defined on the action object (action_ref.get_delay()). If the delay is
greater than zero and the elapsed time since starting_time has not yet exceeded that
delay, the interaction cannot be executed and this method returns True. When no delay
is configured (action_ref.get_delay() <= 0), this method always returns False.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
starting_time
|
float
|
The |
required |
Returns:
| Type | Description |
|---|---|
|
|
|
|
|
Note
action_ref must have been set via set_action_ref before this method is
called; calling it on an interaction without a bound action will raise
AttributeError.
Source code in unaiverse/interaction.py
is_timed_out
¶
Return True if this interaction has exceeded its configured timeout limits.
Two independent timeout checks are performed in order:
- Global timeout (
action_ref.get_total_time()): if more thantotal_timeseconds have elapsed since__starting_time, the interaction is timed out regardless of per-step progress. - Per-step timeout (
action_ref.get_timeout()): if__timeout_starting_timeis positive and more thantimeoutseconds have elapsed since that baseline, the interaction is timed out at the step level.
If __starting_time is zero or negative (execution has not started yet), this method
immediately returns False without performing any check.
Returns:
| Type | Description |
|---|---|
|
|
Note
action_ref must have been set via set_action_ref before this method is
called. Timeout events are logged at the inter level when they fire.
Source code in unaiverse/interaction.py
set_action_ref
¶
Bind the interaction to its Action object and validate/augment its argument list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action_ref
|
object
|
The Action instance that will execute this interaction. |
required |
Source code in unaiverse/interaction.py
has_stream
¶
Return True if a stream with the given user hash is already registered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_hash
|
str
|
The stream's user-level hash identifier. |
required |
Source code in unaiverse/interaction.py
add_lazy_stream
¶
add_lazy_stream(user_hash: str, stream_obj: Stream, is_owned: bool = False) -> None
Lazily attach an additional stream to this interaction after it was created.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_hash
|
str
|
The stream's user-level hash identifier. |
required |
stream_obj
|
Stream
|
The stream object to attach. |
required |
is_owned
|
bool
|
Whether the stream is owned by the current agent. |
False
|
Source code in unaiverse/interaction.py
mark_running
¶
Mark this interaction as currently running.
mark_paused
¶
mark_completed
¶
mark_completed(reason: CompletionReason, dest_state: str | None = None, target: str | None = None) -> None
Mark this interaction as completed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reason
|
CompletionReason
|
The reason for completion. |
required |
dest_state
|
str | None
|
The destination state reached by completing this action. |
None
|
target
|
str | None
|
The target agent who completed this interaction (Default: None). |
None
|
Source code in unaiverse/interaction.py
clear_from_action
¶
Deregister this interaction from its action's interaction list.
Source code in unaiverse/interaction.py
is_expired
¶
Check if this interaction has expired based on an external retry_timeout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout_secs
|
float | None
|
Maximum higher-priority retry_timeout in seconds (default: None). |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the interaction is older than timeout_secs. |
Source code in unaiverse/interaction.py
get_new_stream_data_tags
¶
Checks all streams involved in this interaction, and if they have fresh data it returns their tags.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
all_fresh_or_fail
|
bool
|
If True, return None if there is at least one stream with no fresh data (Default: False). |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, list[int]] | None
|
A dictionary "stream user hash to data tag", only involving streams with fresh data. It can return None if the all_fresh_or_fail option was turned on. |
Source code in unaiverse/interaction.py
record_data_tags
¶
Record that data with the given tag was received for this interaction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_tags
|
dict[str, list[int]] | None
|
The data tags/sequence numbers. |
None
|
target
|
str | None
|
The agent who handled the data tags (if None, then it's the current agent). |
None
|
Source code in unaiverse/interaction.py
check_if_doable
¶
Return True if the interaction can currently be executed.
Delegates to the owning InteractionManager when present; for system interactions without a manager, returns True as long as the interaction is not yet completed.
Source code in unaiverse/interaction.py
alter_arg
¶
Overwrite an existing action keyword argument, leaving the dict unchanged if the key is absent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg_name
|
str
|
The argument name to update. |
required |
arg_value
|
object
|
The new value to assign. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the argument existed and was updated; False otherwise. |
Source code in unaiverse/interaction.py
to_dict
¶
Serialize this interaction for network transmission.
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary representation of this interaction. |
Source code in unaiverse/interaction.py
from_dict
classmethod
¶
from_dict(d: dict) -> Interaction
Deserialize an Interaction from a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
dict
|
Dictionary from to_dict(). |
required |
Returns:
| Type | Description |
|---|---|
Interaction
|
A new Interaction instance. |
Source code in unaiverse/interaction.py
to_status_dict
¶
Build a minimal status dict for status update messages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
status_generated_by
|
str
|
The agent who generate this dict. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary with status_generated_by, uuid, status, completion_reason, destination_state, and data_tag. |
Source code in unaiverse/interaction.py
to_code_str
¶
Return a compact single-line representation for logs and debugging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_id
|
bool
|
Prepend the interaction UUID to the output when True. |
False
|
include_received_tags
|
bool
|
Append the received data tags when True. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
A compact string describing the interaction. |
Source code in unaiverse/interaction.py
to_str
¶
Return a JSON-encoded string with the core interaction fields for logging.
Returns:
| Type | Description |
|---|---|
str
|
A JSON string containing requester, action_kwargs, timestamp_created, and uuid. |
Source code in unaiverse/interaction.py
parse_streams
¶
Parse the list of streams provided by the user, standardizing its format and saving it.
The user can specify streams in these two ways, where "stream_hash_j" can be just the stream name, the stream group, the net hash, or the user hash. (1) [..., stream_hash_j (str), ...] (2) { "stdin": [..., stream_hash_j (str), ...], "stdtar": [..., stream_hash_k (str), ...], "stdext": [..., stream_hash_z (str), ...], "stdunk": [..., stream_hash_z (str), ...], }
The last one (2) optionally specifies if the stream is expected to become an input of the processor
('stdin'), a target ('stdtar'), and extra stream ('stdext'), or no preferences (None).
Notice that this choice could be re-arranged by the Interaction Manager, in function of the actual
capabilities of the processor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
streams
|
list | dict
|
The list or dict of streams (see the example above). |
required |
Source code in unaiverse/interaction.py
InteractionManager
¶
Manages all interactions for an agent.
Responsibilities: - Maintains lists of sent and received interactions - Sets stdin/stdout to the streams of the current interaction - Sets the recipients of the generation - Clears expired interactions at every clock cycle - Sends back interaction status - Waits for all involved streams to have sent data before marking action ready
Create an InteractionManager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent
|
object
|
Back-reference to the owning agent (AgentBasics instance). |
required |
max_interactions
|
int
|
Maximum number of simultaneously tracked interactions (sent + received + lazy). |
-1
|
Source code in unaiverse/interaction.py
max_interactions
instance-attribute
¶
max_interactions = max_interactions if max_interactions > 0 else MAX_INTERACTIONS
received_recently_completed
instance-attribute
¶
received_recently_completed: set[Interaction] = set()
room_for_registration
¶
Return True if there is capacity to register another interaction.
count_interactions
¶
Return the total number of tracked interactions, including recently completed ones.
Source code in unaiverse/interaction.py
clear_from_all_streams
¶
clear_from_all_streams(interaction: Interaction, clear_data: bool = False) -> None
Remove the given interaction from every stream that references it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interaction
|
Interaction
|
The interaction to deregister from all the known streams. |
required |
clear_data
|
bool
|
Default False. Forces the removal of the stream data associated to this interaction. |
False
|
Source code in unaiverse/interaction.py
unregister_all
¶
Deregister all current interactions
unregister
¶
unregister(interaction: Interaction) -> bool
Deregister an interaction from all tracking dicts and dissociate it from streams and actions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interaction
|
Interaction
|
The interaction to remove. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the interaction was found and removed from at least one tracking dict. |
Source code in unaiverse/interaction.py
register_sent
¶
register_sent(interaction: Interaction, public: bool) -> bool
Register an interaction that this agent has sent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interaction
|
Interaction
|
The Interaction to register. |
required |
public
|
bool
|
Whether the interaction is about a public agent or a private/world one. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if registration succeeded; False if there is no room or the streams are invalid. |
Source code in unaiverse/interaction.py
register_received
¶
register_received(interaction: Interaction, public: bool) -> bool
Register an interaction received from another agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interaction
|
Interaction
|
The Interaction to register. |
required |
public
|
bool
|
Whether the interaction is about a public agent or a private/world one. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if registration succeeded; False if there is no room, streams are invalid, or matching failed. |
Source code in unaiverse/interaction.py
register_lazy
¶
register_lazy(interaction: Interaction, public: bool) -> bool
Register an interaction that you manually generated within this agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interaction
|
Interaction
|
The Interaction to register. |
required |
public
|
bool
|
Whether the interaction is about a public agent or a private/world one. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if registration succeeded; False if there is no room or the streams are invalid. |
Source code in unaiverse/interaction.py
resolve
¶
resolve(interaction: Interaction, public: bool, resolve_target: bool = True) -> bool
Source code in unaiverse/interaction.py
expand_and_normalize_streams
¶
expand_and_normalize_streams(interaction: Interaction) -> tuple[dict[str | None, list[str]], dict[str | None, list[str]]]
Resolve all stream references in an interaction to fully-populated stream dicts.
Translates user-level and net-level hashes into detailed dicts containing user_hash,
net_hash, name, group, and the stream object itself, grouped by their suggested
redirection ('stdin', 'stdtar', 'stdext', or None).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interaction
|
Interaction
|
The interaction whose stream list should be expanded. |
required |
Returns:
| Type | Description |
|---|---|
dict[str | None, list[str]]
|
A 2-tuple |
dict[str | None, list[str]]
|
keyed by redirection hint ( |
tuple[dict[str | None, list[str]], dict[str | None, list[str]]]
|
lists of fully-populated stream dicts. Returns |
tuple[dict[str | None, list[str]], dict[str | None, list[str]]]
|
be resolved. |
Source code in unaiverse/interaction.py
match_streams
¶
Assign expanded stream dicts to stdin, stdtar, or stdext based on processor compatibility.
Attempts to match streams to the processor's input and output argument slots, following any redirection hints. Streams that do not fit a processor slot are placed in stdext.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expanded_streams
|
dict
|
The output of |
required |
Returns:
| Type | Description |
|---|---|
bool
|
A 4-tuple |
dict
|
False if required processor inputs have no matching stream and no default value, and the |
dict
|
remaining three elements are |
Source code in unaiverse/interaction.py
1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 | |
check_if_doable
¶
check_if_doable(interaction: Interaction) -> bool
Return True if the given interaction can be executed right now.
An interaction is doable when it is not yet completed, the requester is a known agent, and either all involved streams have fresh data or a deprecated completion step is pending.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interaction
|
Interaction
|
The interaction to evaluate. |
required |
Source code in unaiverse/interaction.py
check_consistency_between_action_kwargs_and_interaction_fields
staticmethod
¶
check_consistency_between_action_kwargs_and_interaction_fields(interaction: Interaction)
Source code in unaiverse/interaction.py
get_current
¶
get_current() -> Interaction | None
get_last_registered
¶
get_last_registered() -> Interaction | None
Return the most recently registered interaction, or None if none have been registered.
set_current_as_paused
¶
Set the current interaction as something that was started but now must be paused because some other interactions are handled.
set_current
¶
set_current(interaction: Interaction | None) -> None
Set the given interaction as the currently executing one.
This marks the interaction as running and configures the agent's stdin/stdout to point to the correct streams for this interaction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interaction
|
Interaction | None
|
The Interaction to set as current. |
required |
Source code in unaiverse/interaction.py
has_data
¶
has_data(interaction: Interaction) -> bool
Return True if any owned stream has data available for the given interaction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interaction
|
Interaction
|
The interaction to check data availability for. |
required |
Source code in unaiverse/interaction.py
get_recipients
¶
get_recipients(interaction: Interaction) -> list[str]
Return the list of peer IDs that should receive data generated by the interaction.
For sent interactions the recipients are the interaction targets; for received interactions it is the original requester; for lazy interactions it is the interaction targets. Unknown (unregistered) interactions fall back to the interaction's target list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interaction
|
Interaction
|
The interaction whose recipients should be determined. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
A list of peer ID strings, filtering out any |
Source code in unaiverse/interaction.py
complete
async
¶
complete(interaction: Interaction, reason: CompletionReason, dest_state: str | None = None, target: str | None = None) -> None
Mark an interaction as completed and move it to the recently-completed set, removing it from its action (async).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interaction
|
Interaction
|
The interaction to complete. |
required |
reason
|
CompletionReason
|
The reason for completion. |
required |
dest_state
|
str | None
|
The destination state reached, if any. |
None
|
target
|
str | None
|
The target agent who completed the interaction (Default: None). |
None
|
Source code in unaiverse/interaction.py
complete_current
async
¶
complete_current(dest_state: str, reason: CompletionReason) -> None
Mark the current interaction as completed (async).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dest_state
|
str
|
The destination state reached by completing this action. |
required |
reason
|
CompletionReason
|
The reason for completion. |
required |
Source code in unaiverse/interaction.py
drain_completed
¶
drain_completed() -> list[Interaction]
Return and clear the list of recently completed interactions.
Used by the agent's behave() loop to send status notifications.
Returns:
| Type | Description |
|---|---|
list[Interaction]
|
List of Interaction objects that were recently completed. |
Source code in unaiverse/interaction.py
complete_expired
async
¶
Remove expired (or no-action-based) interactions and return them for notification (async).
Checks all received and sent interactions against the retry_timeout. Expired interactions are marked as COMPLETED with TIMEOUT reason and removed from the tracking dicts.
Source code in unaiverse/interaction.py
clear_expired_stream_data
¶
Purge stale buffered data from streams whose associated interaction is done or gone.
Source code in unaiverse/interaction.py
update_sent_status
async
¶
Update a previously sent interaction's status from a received status message (async).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
status_dict
|
dict
|
Dict from Interaction.to_status_dict(). |
required |
Source code in unaiverse/interaction.py
is_received
¶
is_received(interaction: Interaction) -> bool
Return True if the interaction was received from another agent (active or recently completed).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interaction
|
Interaction
|
The interaction to check. |
required |
Source code in unaiverse/interaction.py
is_sent
¶
is_sent(interaction: Interaction) -> bool
Return True if the interaction was sent by this agent (active or recently completed).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interaction
|
Interaction
|
The interaction to check. |
required |
Source code in unaiverse/interaction.py
is_lazy
¶
is_lazy(interaction: Interaction) -> bool
Return True if the interaction was lazily generated within this agent (active or recently completed).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interaction
|
Interaction
|
The interaction to check. |
required |
Source code in unaiverse/interaction.py
is_known
¶
is_known(interaction: Interaction) -> bool
Return True if the interaction is tracked in any of sent, received, or lazy dicts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interaction
|
Interaction
|
The interaction to check. |
required |
Source code in unaiverse/interaction.py
get_interaction
¶
get_interaction(uuid: str | None, consider_completed_too: bool = False) -> Interaction | None
Look up an interaction by UUID across the active tracking dicts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid
|
str | None
|
The UUID string to look up. |
required |
consider_completed_too
|
bool
|
When True, also search the recently-completed sets and return the most recently completed match (there may be more than one with the same UUID). |
False
|
Returns:
| Type | Description |
|---|---|
Interaction | None
|
The matching Interaction, or None if not found. |
Source code in unaiverse/interaction.py
add_lazy_stream_to_interaction
¶
add_lazy_stream_to_interaction(stream_hash: str, interaction: Interaction) -> None
Attach a stream (identified by hash) to an already-registered interaction as a lazy stream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stream_hash
|
str
|
A user-level or net-level stream hash to resolve and attach. |
required |
interaction
|
Interaction
|
The interaction to attach the stream to. |
required |
Source code in unaiverse/interaction.py
remove_interactions_of_agent
async
¶
Complete and deregister all interactions that involve the given agent as requester or target (async).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent
|
str
|
Peer ID of the agent being removed. |
required |
Source code in unaiverse/interaction.py
InteractionStatus
¶
Bases: Enum
CompletionReason
¶
Bases: Enum