Movatterモバイル変換


[0]ホーム

URL:


Skip to content

repl

run_demo_loopasync

run_demo_loop(agent:Agent[Any],*,stream:bool=True,context:TContext|None=None,max_turns:int=DEFAULT_MAX_TURNS,)->None

Run a simple REPL loop with the given agent.

This utility allows quick manual testing and debugging of an agent from thecommand line. Conversation state is preserved across turns. Enterexitorquit to stop the loop.

Parameters:

NameTypeDescriptionDefault
agentAgent[Any]

The starting agent to run.

required
streambool

Whether to stream the agent output.

True
contextTContext | None

Additional context information to pass to the runner.

None
max_turnsint

Maximum number of turns for the runner to iterate.

DEFAULT_MAX_TURNS
Source code insrc/agents/repl.py
asyncdefrun_demo_loop(agent:Agent[Any],*,stream:bool=True,context:TContext|None=None,max_turns:int=DEFAULT_MAX_TURNS,)->None:"""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.        max_turns: Maximum number of turns for the runner to iterate.    """current_agent=agentinput_items:list[TResponseInputItem]=[]whileTrue:try:user_input=input(" > ")except(EOFError,KeyboardInterrupt):print()breakifuser_input.strip().lower()in{"exit","quit"}:breakifnotuser_input:continueinput_items.append({"role":"user","content":user_input})result:RunResultBaseifstream:result=Runner.run_streamed(current_agent,input=input_items,context=context,max_turns=max_turns)asyncforeventinresult.stream_events():ifisinstance(event,RawResponsesStreamEvent):ifisinstance(event.data,ResponseTextDeltaEvent):print(event.data.delta,end="",flush=True)elifisinstance(event,RunItemStreamEvent):ifevent.item.type=="tool_call_item":print("\n[tool called]",flush=True)elifevent.item.type=="tool_call_output_item":print(f"\n[tool output:{event.item.output}]",flush=True)elifisinstance(event,AgentUpdatedStreamEvent):print(f"\n[Agent updated:{event.new_agent.name}]",flush=True)print()else:result=awaitRunner.run(current_agent,input_items,context=context,max_turns=max_turns)ifresult.final_outputisnotNone:print(result.final_output)current_agent=result.last_agentinput_items=result.to_input_list()

[8]ページ先頭

©2009-2026 Movatter.jp