
    RX9i%                     f   S SK r S SKrS SKrS SKrS SKJr  S SKrS SKJr  SSK	J
r
Jr  SSKJr  SSKJr  \R                   " SS	S
9r\R                   " SSSS9r\R'                  \SS9  S\\   SS4S jr\R-                  5       \R.                  " SSSS94S\\   4S jj5       r\S:X  a  \" 5         gg)    N)Optional)print   )_async_prompt_patch_anyio_open_process)Agent)_load_agent_configrichziA squad of lightweight composable AI applications built on Hugging Face's Inference Client and MCP stack.)rich_markup_modehelprunzRun the Agent in the CLIT)namer   invoke_without_command)r   
agent_pathreturnc                   ^^ ^!^"#    [        5         [        U 5      u  pUR                  S/ 5      nUR                  S/ 5      n[        R                  " 5       m [        R                  " 5       m!Sm"[        R
                  " 5       n[        R                  " [        R                  5      nS9U U!U"4S jjm Sn UR                  [        R                  T5        Sn0 n[        U5      S:  Gai  [        S	5        U GHM  n	U	S
   n
U	S   nSU
 S3n[        5       nU Hc  nUS   S:X  a  UR                  S0 5      OUR                  S0 5      nUR                  5        H  u  nnUU;   d  M  UR!                  U5        M!     Me     UR                  S5      n[#        U[$        5      (       a  UU;   a  UR!                  S5        U(       d  [        SU
 S35        M  U
R'                  SS5      R)                  5       n[        SU
 SU SU S3SS9  [+        T!S9I Sh  vN R-                  5       nT!R/                  5       (       aO    U(       a!   UR1                  [        R                  5        g[        R                  " [        R                  U5        gUnU(       d=  [2        R4                  " US5      nU(       a  [        SU S 35        O[        S!U S"35        UX'   U Hj  nUS   S:X  a  UR                  S0 5      OUR                  S0 5      nUR                  5        H&  u  nnUU;   d  M  UU   R'                  UU5      UU'   M(     Ml     GMP     [        5         UR                  S5      n[#        U[$        5      (       a7  UnUR                  5        H  u  n
nUR'                  SU
 S3U5      nM     UUS'   [7        UR                  S#5      UR                  S$5      UR                  S%5      UR                  S5      UUS&9 ISh  vN nUR9                  5       I Sh  vN   [        S'[        UR:                  5       S(35        UR:                   H&  n[        SUR<                  R>                   S)35        M(      T RA                  5         T!R/                  5       (       a_   SSS5      ISh  vN   U(       a!   UR1                  [        R                  5        g[        R                  " [        R                  U5        g [+        T!S9I Sh  vN nSm" URG                  UT S-9  Sh  vN nT R/                  5       (       a
  T"(       d    GOT!R/                  5       (       a_    SSS5      ISh  vN   U(       a!   UR1                  [        R                  5        g[        R                  " [        R                  U5        g[I        US.5      (       Ga  URJ                  S   RL                  nURN                  (       a  [        URN                  SSS/9  URP                  (       a  URP                   H  nURR                  (       a  [        S0URR                   S13SS9  UR<                  R>                  (       a  [        UR<                  R>                   SS9  UR<                  RT                  (       d  M  [        UR<                  RT                   SS9  M     GM  GM  [        S2UR>                   S3URV                   S4URN                   S53SS+9  GM  [        5         GM  ! [        [        4 a-    [        R                  " [        R                  U4S j5         GNyf = f GNB! [        [        4 a     gf = f GNp GN[ GN! [        [        4 a     gf = f GN! [B         a    [        S*SS+9   O[D         a-    T"(       d  T R/                  5       (       a   GM\  [        S,SS+9   Obf = f GN GN|! [        [        4 a     gf = f
 N! [X         a3  n[Z        R\                  " 5       n[        S6U S4U S73SS+9  Sm" SnAGN#SnAff = fSSS5      ISh  vN    OT! , ISh  vN  (       d  f       O== f! [X         a-  n[Z        R\                  " 5       n[        S8U S4U S73SS+9  UeSnAff = fU(       a7   UR1                  [        R                  5        g! [        [        4 a     gf = f[        R                  " [        R                  U5        g! W(       a7   UR1                  [        R                  5        f ! [        [        4 a     f f = f[        R                  " [        R                  U5        f = f7f):z
Tiny Agent loop.

Args:
    agent_path (`str`, *optional*):
        Path to a local folder containing an `agent.json` and optionally a custom `PROMPT.md` or `AGENTS.md` file or a built-in agent stored in a Hugging Face dataset.

inputsserversTNc                     > T(       a  SmT R                  5         [        SSS9  g [        SSS9  TR                  5         g )NFz4
[red]Interrupted. Press Ctrl+C again to quit.[/red]Tflushz
[red]Exiting...[/red])setr   )abort_event
exit_eventfirst_sigints   b/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/huggingface_hub/inference/_mcp/cli.py_sigint_handler"run_agent.<locals>._sigint_handler5   s9     LOOIQUV't4    Fc                     > T" 5       $ )N )_r   s    r   <lambda>run_agent.<locals>.<lambda>G   s    O4Er   r   z}[bold blue]Some initial inputs are required by the agent. Please provide a value or leave empty to load from env.[/bold blue]iddescriptionz${input:}typestdioenvheadersapiKeyz[yellow]Input 'zS' defined in config but not used by any server or as an API key. Skipping.[/yellow]-r"   u   [blue] • z	[/blue]: z. (default: load from z). )end)r    z'[green]Value successfully loaded from 'z	'[/green]z[yellow]No value found for 'z0' in environment variables. Continuing.[/yellow]providermodelendpointUrl)r1   r2   base_urlapi_keyr   promptz[bold blue]Agent loaded with z tools:[/bold blue]z[/blue]z"
[red]EOF received, exiting.[/red]r   z7
[red]Keyboard interrupt during input processing.[/red])r   choices)r/   r   z<Tool >z

[green]Tool[z] 
z	[/green]
z#
[bold red]Error during agent run: [/bold red])
[bold red]An unexpected error occurred: )r   N)/r   r	   getasyncioEventget_running_loopsignal	getsignalSIGINTadd_signal_handlerAttributeErrorNotImplementedErrorlenr   r   itemsadd
isinstancestrreplaceupperr   stripis_setremove_signal_handlerosgetenvr   
load_toolsavailable_toolsfunctionr   clearEOFErrorKeyboardInterruptr   hasattrr7   deltacontent
tool_callsr%   	argumentstool_call_id	Exception	traceback
format_exc)#r   configr6   r   r   looporiginal_sigint_handlersigint_registered_in_loopresolved_inputs
input_iteminput_idr&   env_special_valueinput_usagesserverenv_or_headerskeyvalueraw_api_keyenv_variable_key
user_inputfinal_valuesubstituted_api_keyvalagenttchunkrY   calletb_strr   r   r   r   s#                                  @@@@r   	run_agentrz      sd     '
3NFZZ"%FjjB'G--/KJL##%D$..v}}=	 	]B$)!	G##FMM?C(,% +-v;?V %
%d+(7&/z$<!  #u%F>DVnPW>WVZZr%:]c]g]ghqsu]vN&4&:&:&<
U,5(,,S1 '= & %jj2k3//4E4T $$X.#)( 4. .  $,#3#3C#=#C#C#E !(9[MAWXhWiikl %2Z$HHOOQ
$$&&J %**6==9 MM&--)@AQ )""$)),<b"AK" GHXGYYbcd:;K:LL|} -8) &F>DVnPW>WVZZr%:]c]g]ghqsu]vN&4&:&:&<
U,52@2E2M2MN_al2mN3/ '= &a %l Gjj*k3''"-!0!6!6!8#&9&A&AIhZWYBZ\_&`# "92F8ZZ
+**W%ZZ.JJx(
 
 ""$$$1#e6K6K2L1MM`ab**AJJOO#4G<= + !!# $$&&%
 
N %**6==9 MM&--)@As'4
'K!KJ#'L(',yyy'U e&--//!%,,.."M
 
N %**6==9 MM&--)@AK #5)44$)MM!$4$:$:E$}} %emm4 H$//,1,<,<D'+ww(-twwiq.Ar(J'+}}'9'9(-1C1C0D3(O'+}}'>'>'>(-1H1H0IPR(S -=  0 ""25::,bASAS@TTVW\WdWdVeeo p&*
 G[ q  34 	GMM&--)EF	GV IT #$78 U
 %
T #$78 k "L ?tL( 'K,>,>,@,@ X`deE
T #$78 Q (V4 ! (&113F@2fX[Yaef#'L(y
 
 
 
 
 
B  %%':1#Rx{S[_` %**6==9"$78  MM&--)@A %**6==9"$78  MM&--)@As}  B+e.2a( 5"\ B	a( $B.a( ](a( ;e.] "'e.	Ba( #Ca( =]->a( a]0Baa( $]3%a( )e.1]6 'e.8^^^_<_: _!_:$6_<a( %_!&a( *e.2_$ 'e.8C-_<)A(_<a9]a( ]a( ]*'e.)]**e.-a( 0a3a( 6^	e.^		e.^_#a%%_
a
_a_a_:!a( $_74e.6_77e.:_<<
`9(`4.a4`99a<a( a
a( d a%aa%!a( $d %a( (
b2(bbd "e.*c
 	e.
ce.c)e.e+d/.e+/e?e+e)e++e.zPath to a local folder containing an agent.json file or a built-in agent stored in the 'tiny-agents/tiny-agents' Hugging Face dataset (https://huggingface.co/datasets/tiny-agents/tiny-agents)F)r   show_defaultpathc                      [         R                  " [        U 5      5        g ! [         a    [	        SSS9  [
        R                  " SS9e[         a  n[	        SU S3SS9  UeS nAff = f)Nz8
[red]Application terminated by KeyboardInterrupt.[/red]Tr      )coder;   r:   )r=   r   rz   rW   r   typerExitr^   )r|   rx   s     r   r   r      sd    IdO$ #IQUVjjc"" :1#[IQUVs   " 1A(A##A(__main__)r=   rP   r@   r_   typingr   r   r
   r   
_cli_hacksr   r   rt   r   utilsr	   Typerapprun_cli	add_typerrJ   rz   callbackArgumentr   __name__r!   r   r   <module>r      s     	      @  % kk	t
 ++		#
 gE "ABAB	ABH 	..H 
3- * zE r   