Interruption UX.
This commit is contained in:
parent
1d8b44e1a6
commit
8ffcac867b
|
|
@ -228,8 +228,10 @@ def main():
|
|||
)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print_interrupt(f"Operation cancelled: {CANCELLED_BY_USER_REASON}")
|
||||
sys.exit(1)
|
||||
print()
|
||||
print(" 👋 Bye!")
|
||||
print()
|
||||
sys.exit(0)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
"""Utility functions for working with agents."""
|
||||
|
||||
import sys
|
||||
import time
|
||||
import uuid
|
||||
from typing import Optional, Any, List
|
||||
|
|
@ -278,11 +279,16 @@ def run_task_implementation_agent(
|
|||
|
||||
_CONTEXT_STACK = []
|
||||
_INTERRUPT_CONTEXT = None
|
||||
_FEEDBACK_MODE = False
|
||||
|
||||
def _request_interrupt(signum, frame):
|
||||
global _INTERRUPT_CONTEXT
|
||||
if _CONTEXT_STACK:
|
||||
_INTERRUPT_CONTEXT = _CONTEXT_STACK[-1]
|
||||
|
||||
if _FEEDBACK_MODE:
|
||||
print(" 👋 Bye!")
|
||||
sys.exit(0)
|
||||
|
||||
class InterruptibleSection:
|
||||
def __enter__(self):
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import sys
|
||||
from langchain_core.tools import tool
|
||||
from prompt_toolkit import PromptSession
|
||||
from prompt_toolkit.key_binding import KeyBindings
|
||||
|
|
@ -17,13 +16,6 @@ def create_keybindings():
|
|||
"""Trigger submission when Ctrl+D is pressed."""
|
||||
event.current_buffer.validate_and_handle()
|
||||
|
||||
@bindings.add('c-c')
|
||||
def exit(event):
|
||||
"""Trigger exit when Ctrl+C is pressed."""
|
||||
print()
|
||||
print(" 👋 Bye!")
|
||||
sys.exit(0)
|
||||
|
||||
return bindings
|
||||
|
||||
@tool
|
||||
|
|
@ -45,7 +37,7 @@ def ask_human(question: str) -> str:
|
|||
session = PromptSession(
|
||||
multiline=True,
|
||||
key_bindings=create_keybindings(),
|
||||
prompt_continuation='. ',
|
||||
prompt_continuation='.',
|
||||
)
|
||||
|
||||
print()
|
||||
|
|
|
|||
Loading…
Reference in New Issue