From 6fd65548c81d139284a508481da15e5f93c1e715 Mon Sep 17 00:00:00 2001 From: seeyangzhi Date: Tue, 19 Aug 2025 16:09:12 +0800 Subject: [PATCH 1/2] Add context parameter to run_demo_loop Introduces an optional 'context' argument to the run_demo_loop function and passes it to Runner.run and Runner.run_streamed. This allows additional context information to be provided during agent execution for enhanced flexibility. --- src/agents/repl.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/agents/repl.py b/src/agents/repl.py index f7142555f..b7afd778c 100644 --- a/src/agents/repl.py +++ b/src/agents/repl.py @@ -11,7 +11,7 @@ from .stream_events import AgentUpdatedStreamEvent, RawResponsesStreamEvent, RunItemStreamEvent -async def run_demo_loop(agent: Agent[Any], *, stream: bool = True) -> None: +async def run_demo_loop(agent: Agent[Any], *, stream: bool = True, context: Any = None) -> None: """Run a simple REPL loop with the given agent. This utility allows quick manual testing and debugging of an agent from the @@ -21,6 +21,7 @@ async def run_demo_loop(agent: Agent[Any], *, stream: bool = True) -> None: Args: agent: The starting agent to run. stream: Whether to stream the agent output. + context: Additional context information to pass to the runner. """ current_agent = agent @@ -40,7 +41,7 @@ async def run_demo_loop(agent: Agent[Any], *, stream: bool = True) -> None: result: RunResultBase if stream: - result = Runner.run_streamed(current_agent, input=input_items) + result = Runner.run_streamed(current_agent, input=input_items, context=context) async for event in result.stream_events(): if isinstance(event, RawResponsesStreamEvent): if isinstance(event.data, ResponseTextDeltaEvent): @@ -54,7 +55,7 @@ async def run_demo_loop(agent: Agent[Any], *, stream: bool = True) -> None: print(f"\n[Agent updated: {event.new_agent.name}]", flush=True) print() else: - result = await Runner.run(current_agent, input_items) + result = await Runner.run(current_agent, input_items, context=context) if result.final_output is not None: print(result.final_output) From e332645556c88e5880709796c79ff6133e3768ef Mon Sep 17 00:00:00 2001 From: seeyangzhi Date: Tue, 19 Aug 2025 17:27:23 +0800 Subject: [PATCH 2/2] Update run_demo_loop context type annotation Changed the type annotation for the context parameter in run_demo_loop from Any to TContext | None for improved type safety and clarity. --- src/agents/repl.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/agents/repl.py b/src/agents/repl.py index b7afd778c..34222870c 100644 --- a/src/agents/repl.py +++ b/src/agents/repl.py @@ -8,10 +8,13 @@ from .items import TResponseInputItem from .result import RunResultBase from .run import Runner +from .run_context import TContext from .stream_events import AgentUpdatedStreamEvent, RawResponsesStreamEvent, RunItemStreamEvent -async def run_demo_loop(agent: Agent[Any], *, stream: bool = True, context: Any = None) -> None: +async def run_demo_loop( + agent: Agent[Any], *, stream: bool = True, context: TContext | None = None +) -> None: """Run a simple REPL loop with the given agent. This utility allows quick manual testing and debugging of an agent from the