Skip to content

Update routing.py #1102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
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
14 changes: 11 additions & 3 deletions examples/agent_patterns/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import uuid

from openai.types.responses import ResponseContentPartDoneEvent, ResponseTextDeltaEvent

from agents import Agent, RawResponsesStreamEvent, Runner, TResponseInputItem, trace

"""
Expand Down Expand Up @@ -33,7 +32,7 @@
)


async def main():
async def main():
# We'll create an ID for this conversation, so we can link each trace
conversation_id = str(uuid.uuid4().hex[:16])

Expand All @@ -52,6 +51,7 @@ async def main():
async for event in result.stream_events():
if not isinstance(event, RawResponsesStreamEvent):
continue

data = event.data
if isinstance(data, ResponseTextDeltaEvent):
print(data.delta, end="", flush=True)
Expand All @@ -60,11 +60,19 @@ async def main():

inputs = result.to_input_list()
print("\n")

# inform user how to exit
print("To end the conversation, type 'exit' (English), 'sortie' (French), or 'salida' (Spanish).")

user_msg = input("Enter a message: ")
inputs.append({"content": user_msg, "role": "user"})

# define valid exit commands
exit_commands = ["exit" , "sortie" , "salida"]
if user_msg.lower().strip() in exit_commands:
break
agent = result.current_agent



if __name__ == "__main__":
asyncio.run(main())