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