Environment GuideΒΆ
Component TypesΒΆ
OWA's Environment provides three types of components for building real-time agents:
Component Overview
Direct function calls - Invoke immediately for actions or state
Event monitoring - Respond to events with callbacks
Component Relationships
Who initiates the action:
- Callable: You actively call the function
- Listener: The system calls your callback when events occur (inherits from Runnable)
- Runnable: Base class for background processes
Traditional frameworks like gymnasium.Env only provide Callable-style interfaces.
Registry SystemΒΆ
Components are automatically discovered and registered when plugins are installed:
from owa.core import CALLABLES, LISTENERS, RUNNABLES
# All installed plugins automatically available
Key Features:
- Zero Configuration: Automatic discovery via Python Entry Points
- Unified Naming: All components use
namespace/name
pattern - Immediate Availability: Components ready after
pip install
Usage ExamplesΒΆ
Basic UsageΒΆ
from owa.core import CALLABLES, LISTENERS
import time
# Get current time
current_time = CALLABLES["std/time_ns"]()
print(f"Current time: {current_time}")
# Periodic callback using context manager
def on_tick():
print(f"Tick: {CALLABLES['std/time_ns']()}")
tick = LISTENERS["std/tick"]().configure(callback=on_tick, interval=1)
with tick.session:
time.sleep(3) # Prints time every second for 3 seconds
from owa.core import CALLABLES, LISTENERS
from owa.msgs.desktop.keyboard import KeyboardEvent
# Screen capture and window management
screen = CALLABLES['desktop/screen.capture']()
print(f"Screen size: {screen.shape}")
active_window = CALLABLES['desktop/window.get_active_window']()
print(f"Active window: {active_window}")
# Mouse control
CALLABLES["desktop/mouse.click"]("left", 2) # Double-click
# Keyboard monitoring
def on_key(event: KeyboardEvent):
print(f"Key {event.event_type}: {event.vk}")
with LISTENERS["desktop/keyboard"]().configure(callback=on_key).session:
input("Press Enter to stop monitoring...")
from owa.core import RUNNABLES
import cv2
# Real-time screen capture with GStreamer
def process_frame(frame):
cv2.imshow("Screen", frame.frame_arr)
cv2.waitKey(1)
screen = LISTENERS["gst/screen"]().configure(
callback=process_frame,
fps=60,
show_cursor=True
)
with screen.session:
input("Press Enter to stop capture...")
Custom Plugin DevelopmentΒΆ
Create your own plugins for automatic discovery:
# pyproject.toml
[project.entry-points."owa.env.plugins"]
myplugin = "owa.env.myplugin:plugin_spec"
# Plugin specification
from owa.core.plugin_spec import PluginSpec
plugin_spec = PluginSpec(
namespace="myplugin",
version="0.1.0",
description="My custom plugin",
components={
"callables": {"add": "owa.env.myplugin:add_function"},
"listeners": {"events": "owa.env.myplugin:EventListener"}
}
)
# Usage (automatically available after pip install)
result = CALLABLES["myplugin/add"](5, 3) # Returns 8
Plugin Development
See Custom Plugins Guide for detailed plugin creation instructions.
Architecture OverviewΒΆ
graph TB
subgraph "Plugin Installation"
PI[pip install owa-env-*]
EP[Python Entry Points]
end
subgraph "Plugin Discovery"
STD[owa.env.std]
DESK[owa.env.desktop]
GST[owa.env.gst]
MSGS[owa-msgs]
end
subgraph "Component Registry"
CMPTS[CALLABLES, LISTENERS, RUNNABLES]
MSG[MESSAGES]
end
subgraph "User Application"
APP[Your Agent Code]
end
PI --> EP
EP --> STD
EP --> DESK
EP --> GST
EP --> MSGS
STD --> CMPTS
DESK --> CMPTS
GST --> CMPTS
MSGS --> MSG
CMPTS --> APP
MSG --> APP
CLI ToolsΒΆ
Explore and manage plugins with the owl env
command:
Essential Commands
$ owl env list
π¦ Discovered Plugins (4)
βββ desktop (25 components)
βββ gst (4 components)
βββ std (2 components)
βββ example (6 components)
$ owl env search mouse --table
βββββββββββββββββββββββββββ³ββββββββββββ
β Component β Type β
β‘ββββββββββββββββββββββββββββββββββββββ©
β desktop/mouse β listeners β
β desktop/mouse.click β callables β
β desktop/mouse.move β callables β
βββββββββββββββββββββββββββ΄ββββββββββββ
Complete CLI Reference
For detailed command options and examples, see CLI Environment Commands
Message RegistryΒΆ
OWA provides centralized message definitions with automatic discovery:
from owa.core import MESSAGES
# Access message classes
KeyboardEvent = MESSAGES['desktop/KeyboardEvent']
MouseEvent = MESSAGES['desktop/MouseEvent']
# Create instances
event = KeyboardEvent(event_type="press", vk=65, timestamp=1234567890)
Message Naming: domain/MessageType
(e.g., desktop/KeyboardEvent
)
Core Message Types:
Type | Description |
---|---|
desktop/KeyboardEvent |
Keyboard press/release events |
desktop/MouseEvent |
Mouse movement, clicks, scrolls |
desktop/ScreenCaptured |
Screen capture frames |
desktop/WindowInfo |
Window information |
Custom Messages: Register via entry points in pyproject.toml
:
[project.entry-points."owa.msgs"]
"sensors/TemperatureReading" = "custom_sensors.messages:TemperatureReading"
Message Tools & Development
- CLI Tools: Use
owl messages
commands for message management. See CLI Reference - Custom Messages: For detailed guidance on creating custom message types, see Custom Messages Guide
Next StepsΒΆ
Topic | Description |
---|---|
Plugin Development | Create your own environment extensions |
Built-in Plugins | Explore standard, desktop, and GStreamer plugins |
CLI Tools | Complete command reference |