88from .items import TResponseInputItem
99from .result import RunResultBase
1010from .run import Runner
11+ from .run_context import TContext
1112from .stream_events import AgentUpdatedStreamEvent , RawResponsesStreamEvent , RunItemStreamEvent
1213
1314
14- async def run_demo_loop (agent : Agent [Any ], * , stream : bool = True ) -> None :
15+ async def run_demo_loop (
16+ agent : Agent [Any ], * , stream : bool = True , context : TContext | None = None
17+ ) -> None :
1518 """Run a simple REPL loop with the given agent.
1619
1720 This utility allows quick manual testing and debugging of an agent from the
@@ -21,6 +24,7 @@ async def run_demo_loop(agent: Agent[Any], *, stream: bool = True) -> None:
2124 Args:
2225 agent: The starting agent to run.
2326 stream: Whether to stream the agent output.
27+ context: Additional context information to pass to the runner.
2428 """
2529
2630 current_agent = agent
@@ -40,7 +44,7 @@ async def run_demo_loop(agent: Agent[Any], *, stream: bool = True) -> None:
4044
4145 result : RunResultBase
4246 if stream :
43- result = Runner .run_streamed (current_agent , input = input_items )
47+ result = Runner .run_streamed (current_agent , input = input_items , context = context )
4448 async for event in result .stream_events ():
4549 if isinstance (event , RawResponsesStreamEvent ):
4650 if isinstance (event .data , ResponseTextDeltaEvent ):
@@ -54,7 +58,7 @@ async def run_demo_loop(agent: Agent[Any], *, stream: bool = True) -> None:
5458 print (f"\n [Agent updated: { event .new_agent .name } ]" , flush = True )
5559 print ()
5660 else :
57- result = await Runner .run (current_agent , input_items )
61+ result = await Runner .run (current_agent , input_items , context = context )
5862 if result .final_output is not None :
5963 print (result .final_output )
6064
0 commit comments