o
    h	                     @  s   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dZdS )    )annotations)Any)ResponseTextDeltaEvent   )Agent)TResponseInputItem)RunResultBase)Runner)TContext)AgentUpdatedStreamEventRawResponsesStreamEventRunItemStreamEventTN)streamcontextagent
Agent[Any]r   boolr   TContext | NonereturnNonec             	     sf  | }g }	 zt d}W n ttfy   t  Y dS w |  dv r&dS |s)q|d|d |rtj|||d}|	 2 zQ3 dH W }t
|trZt
|jtrYt|jjddd	 q?t
|tr|jjd
krltddd q?|jjdkr~td|jj ddd q?t
|trtd|jj ddd q?6 t  ntj|||dI dH }|jdurt|j |j}| }q)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)r   r   r   current_agentinput_items
user_inputresultevent r;   L/var/www/html/openai_agents/venv/lib/python3.10/site-packages/agents/repl.pyrun_demo_loop   sN   




r=   )r   r   r   r   r   r   r   r   )
__future__r   typingr   0openai.types.responses.response_text_delta_eventr   r   r   itemsr   r9   r   r2   r	   run_contextr
   r)   r   r   r   r=   r;   r;   r;   r<   <module>   s    