55from typing import Optional
66
77import typer
8- from rich import print
98
9+ from ...utils import ANSI
1010from ._cli_hacks import _async_prompt , _patch_anyio_open_process
1111from .agent import Agent
1212from .utils import _load_agent_config
@@ -55,10 +55,10 @@ def _sigint_handler() -> None:
5555 if first_sigint :
5656 first_sigint = False
5757 abort_event .set ()
58- print (" \n [red]Interrupted . Press Ctrl+C again to quit.[/red]" , flush = True )
58+ print (ANSI . red ( " \n Interrupted . Press Ctrl+C again to quit." ) , flush = True )
5959 return
6060
61- print (" \n [red]Exiting ...[/red]" , flush = True )
61+ print (ANSI . red ( " \n Exiting ..." ) , flush = True )
6262 exit_event .set ()
6363
6464 try :
@@ -75,8 +75,12 @@ def _sigint_handler() -> None:
7575
7676 if len (inputs ) > 0 :
7777 print (
78- "[bold blue]Some initial inputs are required by the agent. "
79- "Please provide a value or leave empty to load from env.[/bold blue]"
78+ ANSI .bold (
79+ ANSI .blue (
80+ "Some initial inputs are required by the agent. "
81+ "Please provide a value or leave empty to load from env."
82+ )
83+ )
8084 )
8185 for input_item in inputs :
8286 input_id = input_item ["id" ]
@@ -98,15 +102,17 @@ def _sigint_handler() -> None:
98102
99103 if not input_usages :
100104 print (
101- f"[yellow]Input '{ input_id } ' defined in config but not used by any server or as an API key."
102- " Skipping.[/yellow]"
105+ ANSI .yellow (
106+ f"Input '{ input_id } ' defined in config but not used by any server or as an API key."
107+ " Skipping."
108+ )
103109 )
104110 continue
105111
106112 # Prompt user for input
107113 env_variable_key = input_id .replace ("-" , "_" ).upper ()
108114 print (
109- f"[blue] • { input_id } [/blue] : { description } . (default: load from { env_variable_key } )." ,
115+ ANSI . blue ( f" • { input_id } " ) + f" : { description } . (default: load from { env_variable_key } )." ,
110116 end = " " ,
111117 )
112118 user_input = (await _async_prompt (exit_event = exit_event )).strip ()
@@ -118,10 +124,12 @@ def _sigint_handler() -> None:
118124 if not final_value :
119125 final_value = os .getenv (env_variable_key , "" )
120126 if final_value :
121- print (f"[green] Value successfully loaded from '{ env_variable_key } '[/green]" )
127+ print (ANSI . green ( f" Value successfully loaded from '{ env_variable_key } '" ) )
122128 else :
123129 print (
124- f"[yellow]No value found for '{ env_variable_key } ' in environment variables. Continuing.[/yellow]"
130+ ANSI .yellow (
131+ f"No value found for '{ env_variable_key } ' in environment variables. Continuing."
132+ )
125133 )
126134 resolved_inputs [input_id ] = final_value
127135
@@ -150,9 +158,9 @@ def _sigint_handler() -> None:
150158 prompt = prompt ,
151159 ) as agent :
152160 await agent .load_tools ()
153- print (f"[ bold blue] Agent loaded with { len (agent .available_tools )} tools:[/bold blue]" )
161+ print (ANSI . bold ( ANSI . blue ( " Agent loaded with {} tools:" . format ( len (agent .available_tools )))) )
154162 for t in agent .available_tools :
155- print (f"[blue] • { t .function .name } [/blue]" )
163+ print (ANSI . blue ( f" • { t .function .name } " ) )
156164
157165 while True :
158166 abort_event .clear ()
@@ -165,13 +173,13 @@ def _sigint_handler() -> None:
165173 user_input = await _async_prompt (exit_event = exit_event )
166174 first_sigint = True
167175 except EOFError :
168- print (" \n [red]EOF received, exiting.[/red]" , flush = True )
176+ print (ANSI . red ( " \n EOF received, exiting." ) , flush = True )
169177 break
170178 except KeyboardInterrupt :
171179 if not first_sigint and abort_event .is_set ():
172180 continue
173181 else :
174- print (" \n [red]Keyboard interrupt during input processing.[/red]" , flush = True )
182+ print (ANSI . red ( " \n Keyboard interrupt during input processing." ) , flush = True )
175183 break
176184
177185 try :
@@ -195,20 +203,20 @@ def _sigint_handler() -> None:
195203 print (f"{ call .function .arguments } " , end = "" )
196204 else :
197205 print (
198- f"\n \n [green]Tool[ { chunk .name } ] { chunk .tool_call_id } \n { chunk .content } [/green] \n " ,
206+ ANSI . green ( f"\n \n Tool[ { chunk .name } ] { chunk .tool_call_id } \n { chunk .content } \n " ) ,
199207 flush = True ,
200208 )
201209
202210 print ()
203211
204212 except Exception as e :
205213 tb_str = traceback .format_exc ()
206- print (f"\n [bold red]Error during agent run: { e } \n { tb_str } [/bold red]" , flush = True )
214+ print (ANSI . red ( f"\n Error during agent run: { e } \n { tb_str } " ) , flush = True )
207215 first_sigint = True # Allow graceful interrupt for the next command
208216
209217 except Exception as e :
210218 tb_str = traceback .format_exc ()
211- print (f"\n [bold red]An unexpected error occurred: { e } \n { tb_str } [/bold red]" , flush = True )
219+ print (ANSI . red ( f"\n An unexpected error occurred: { e } \n { tb_str } " ) , flush = True )
212220 raise e
213221
214222 finally :
@@ -236,10 +244,10 @@ def run(
236244 try :
237245 asyncio .run (run_agent (path ))
238246 except KeyboardInterrupt :
239- print (" \n [red]Application terminated by KeyboardInterrupt.[/red]" , flush = True )
247+ print (ANSI . red ( " \n Application terminated by KeyboardInterrupt." ) , flush = True )
240248 raise typer .Exit (code = 130 )
241249 except Exception as e :
242- print (f"\n [bold red]An unexpected error occurred: { e } [/bold red]" , flush = True )
250+ print (ANSI . red ( f"\n An unexpected error occurred: { e } " ) , flush = True )
243251 raise e
244252
245253
0 commit comments