Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/agents/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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) -> 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
Expand All @@ -21,6 +24,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
Expand All @@ -40,7 +44,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):
Expand All @@ -54,7 +58,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)

Expand Down