diff --git a/agentloop/__init__.py b/agentloop/__init__.py index f5c5c14..307f11e 100644 --- a/agentloop/__init__.py +++ b/agentloop/__init__.py @@ -1,6 +1,6 @@ from .loop import start, step, stop, loop from .input import step_with_input_key -from .context import create_default_context, create_context_builders +from .context import create_context_builders __all__ = [ "start", @@ -8,6 +8,5 @@ "step", "loop", "step_with_input_key", - "create_default_context", "create_context_builders", ] diff --git a/agentloop/context.py b/agentloop/context.py index 208bea4..ec3b249 100644 --- a/agentloop/context.py +++ b/agentloop/context.py @@ -35,22 +35,3 @@ def build_context(context={}): return context return build_context - - -def create_default_context(context={}): - """ - Create a default context object - - Args: - context: the last context made by the loop. Defaults to None. - - Returns: - context: a dictionary containing the current context - """ - if context is None: - context = {} - context["current_time"] = datetime.now().strftime("%H:%M") - context["current_date"] = datetime.now().strftime("%Y-%m-%d") - context["platform"] = sys.platform - context["cwd"] = os.getcwd() - return context diff --git a/agentloop/input.py b/agentloop/input.py index 8f8c05b..8c27375 100644 --- a/agentloop/input.py +++ b/agentloop/input.py @@ -1,4 +1,6 @@ -def step_with_input_key(loop_data, input_key=None): +from .loop import stop + +def step_with_input_key(loop_data): """ Listen for a specified key press, and when detected, step the loop @@ -19,11 +21,17 @@ def step_with_input_key(loop_data, input_key=None): "pynput not installed. Please install it with `pip install pynput`" ) - if input_key is None: - input_key = keyboard.Key.space + input_key = keyboard.Key.space + + quit_key = "q" def on_press(key): - if key == input_key: + # check if key includes the quit key + if hasattr(key, "char") and key.char == quit_key: + print("Quitting...") + stop(loop_data) + elif key == input_key: + print("Stepping...") loop_data["step_event"].set() listener = None