Definition
Every InputDevice has to implement a name, an on_open and on_close methods. The on_open is called when a behavior is started with this device, and when stopped, on_close is called.
Template
This template, once activated, sends data every 1 second to the agent as if the user was talking.
import threading
from brain_client.input_types import InputDevice
class MyInput(InputDevice):
def __init__(self):
self._stop_evt = threading.Event()
@property
def name(self) -> str:
return "my_input" # used by behaviors/directives
def on_open(self):
self._stop_evt.clear()
def timer_loop():
while not self._stop_evt.is_set():
self.send_data("tick!", data_type="chat_in")
self._stop_evt.wait(timeout=1.0)
threading.Thread(target=timer_loop, daemon=True).start()
def on_close(self):
self._stop_evt.set()Data types
The BASIC agent performs better with properly formatted inputs, so we provide the data_type parameter to send data on the right channels.
Currently, data_type can either be chat_in or custom.
If you set data_type="custom"when sending feedback, format your message preferably as a stringified json object.
Last updated
Was this helpful?

