Standard Environment¶
Core utilities and timing functions for OWA agents.
Components¶
Component | Type | Description |
---|---|---|
std/time_ns |
Callable | Get current time in nanoseconds |
std/tick |
Listener | Periodic callback execution |
Usage Examples¶
API Reference¶
std plugin 0.5.3 ¶
Standard system components for OWA
Author: OWA Development Team
Callables ¶
Usage: To use callable components, import CALLABLES
from owa.core
and access them by their component name:
from owa.core import CALLABLES
# Access a callable component (replace 'component_name' with actual name)
callable_func = CALLABLES["std/component_name"]
result = callable_func(your_arguments)
time_ns ¶
time_ns() -> int
Return the current time in nanoseconds since the Unix epoch.
This function provides high-precision timing for OWA components, useful for performance measurement and precise scheduling.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Current time in nanoseconds since Unix epoch (January 1, 1970) |
Examples:
Get current timestamp:
Measure execution time:
>>> start = time_ns()
>>> # ... some operation ...
>>> duration = time_ns() - start
>>> print(f"Operation took {duration} nanoseconds")
Source code in projects/owa-core/owa/env/std/clock.py
Listeners ¶
Usage: To use listener components, import LISTENERS
from owa.core
and call the configure()
method with a callback
function:
from owa.core import LISTENERS
# Configure a listener component (replace 'component_name' with actual name)
listener = LISTENERS["std/component_name"]
listener.configure(callback=my_callback, your_other_arguments)
# Use the listener in a context manager
with listener.session as active_listener:
# The listener is now running and will call my_callback when events occur
pass # Your main code here
Note: The callback
argument is required. The on_configure()
method shown in the documentation is an internal method called by configure()
.
tick ¶
Bases: Listener
A listener that triggers callbacks at regular intervals.
This listener provides precise timing for periodic tasks in OWA, supporting configurable intervals and automatic callback execution.
Examples:
Basic usage with 1-second interval:
>>> def on_tick():
... print(f"Tick at {time_ns()}")
>>>
>>> listener = ClockTickListener()
>>> listener.configure(callback=on_tick, interval=1)
>>> listener.start()
>>> # ... listener runs in background ...
>>> listener.stop()
>>> listener.join()
Custom interval timing:
>>> listener = ClockTickListener()
>>> listener.configure(callback=my_callback, interval=0.5) # 500ms
>>> listener.start()
on_configure ¶
on_configure(*, interval: float = 1)
Configure the tick interval for the listener.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
interval
|
float
|
Time between ticks in seconds. Defaults to 1.0. |
1
|
Examples:
Configure for 100ms intervals:
Source code in projects/owa-core/owa/env/std/clock.py
loop ¶
Main loop that executes callbacks at configured intervals.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stop_event
|
Threading event to signal when to stop |
required | |
callback
|
Function to call at each tick |
required |
Note
This method runs in a separate thread and maintains precise timing by accounting for callback execution time.