fix ctrl+c

This commit is contained in:
Mery-Sanz 2025-04-25 12:41:54 +02:00
parent 53f433f7d3
commit 791fbc5e96
1 changed files with 11 additions and 9 deletions

View File

@ -209,7 +209,9 @@ def run_cai_cli(starting_agent, context_variables=None, stream=False, max_turns=
get_toolbar_with_refresh,
current_text
)
except KeyboardInterrupt:
break
try:
# Handle special commands
if user_input.startswith('/') or user_input.startswith('$'):
parts = user_input.strip().split()
@ -358,14 +360,14 @@ def run_cai_cli(starting_agent, context_variables=None, stream=False, max_turns=
#console.print(f"Agent: {response.final_output}") # NOTE: this line is commented to avoid duplicate output
turn_count += 1
except KeyboardInterrupt:
# Ensure streaming context is cleaned up on keyboard interrupt
if current_streaming_context is not None:
try:
current_streaming_context["live"].stop()
except Exception:
pass
current_streaming_context = None
break
if stream:
# Ensure streaming context is cleaned up on keyboard interrupt
if current_streaming_context is not None:
try:
current_streaming_context["live"].stop()
except Exception:
pass
current_streaming_context = None
except Exception as e:
# Ensure streaming context is cleaned up on any exception
if current_streaming_context is not None: