Skip to content
Merged
Changes from 1 commit
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
7 changes: 4 additions & 3 deletions src/agents/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having this additional argument is fine, but we would like to avoid Any type here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay thanks, I have updated it to be TContext | 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 +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
Expand All @@ -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):
Expand All @@ -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)

Expand Down