
    .Ui	                        d dl mZ d dlmZ d dlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ dd	lmZ dd
lmZmZmZ ddd	 	 	 	 	 	 	 ddZy)    )annotations)Any)ResponseTextDeltaEvent   )Agent)TResponseInputItem)RunResultBase)Runner)TContext)AgentUpdatedStreamEventRawResponsesStreamEventRunItemStreamEventTN)streamcontextc                 K   | }g }	 	 t        d      }|j	                         j                         dv ry|s1|j                  d|d       |r.t        j                  |||      }|j                         2 3 d{   }t        |t              r>t        |j                  t              s4t        |j                  j                  dd	       Wt        |t              rg|j                   j"                  d
k(  rt        dd       |j                   j"                  dk(  st        d|j                   j$                   dd       t        |t&              st        d|j(                  j*                   dd       t        j,                  |||       d{   }|j.                  t        |j.                         |j0                  }|j3                         }# t        t        f$ r t                Y yw xY w7 6 t                L7 qw)a  Run a simple REPL loop with the given agent.

    This utility allows quick manual testing and debugging of an agent from the
    command line. Conversation state is preserved across turns. Enter ``exit``
    or ``quit`` to stop the loop.

    Args:
        agent: The starting agent to run.
        stream: Whether to stream the agent output.
        context: Additional context information to pass to the runner.
    Tz > >   exitquituser)rolecontent)inputr   N )endflushtool_call_itemz
[tool called])r   tool_call_output_itemz
[tool output: ]z
[Agent updated: )r   )r   EOFErrorKeyboardInterruptprintstriplowerappendr
   run_streamedstream_events
isinstancer   datar   deltar   itemtypeoutputr   	new_agentnamerunfinal_output
last_agentto_input_list)agentr   r   current_agentinput_items
user_inputresultevents           g/home/jay/workspace/tools/ai-image-gen/jaaz-app/server/venv/lib/python3.12/site-packages/agents/repl.pyrun_demo_loopr9      s     M,.K
	uJ ##%)99FzBC ((kSZ[F%335 
T 
Tee%<=!%**.DEejj..BdC'9:zz*::/t<,CC 01B1B0C1ETR'>?.u/C/C.DAFdS "::m['RRF"".f))*))**,E  +, 	G	
T5 GRsm   HG A#H7G>;G;<G>?+H+A3H6HAHH
AHG85H7G88H;G>>H)r2   z
Agent[Any]r   boolr   zTContext | NonereturnNone)
__future__r   typingr   0openai.types.responses.response_text_delta_eventr   r2   r   itemsr   r6   r	   r.   r
   run_contextr   r%   r   r   r   r9        r8   <module>rD      sO    "  S  % !  ! _ _ *.$3-3-"&3-8G3-	3-rC   