()
| 35 | |
| 36 | |
| 37 | async def main(): |
| 38 | # We'll create an ID for this conversation, so we can link each trace |
| 39 | conversation_id = str(uuid.uuid4().hex[:16]) |
| 40 | |
| 41 | msg = input_with_fallback( |
| 42 | "Hi! We speak French, Spanish and English. How can I help? ", |
| 43 | "Hello, how do I say good evening in French?", |
| 44 | ) |
| 45 | agent = triage_agent |
| 46 | inputs: list[TResponseInputItem] = [{"content": msg, "role": "user"}] |
| 47 | auto_mode = is_auto_mode() |
| 48 | |
| 49 | while True: |
| 50 | # Each conversation turn is a single trace. Normally, each input from the user would be an |
| 51 | # API request to your app, and you can wrap the request in a trace() |
| 52 | with trace("Routing example", group_id=conversation_id): |
| 53 | result = Runner.run_streamed( |
| 54 | agent, |
| 55 | input=inputs, |
| 56 | ) |
| 57 | async for event in result.stream_events(): |
| 58 | if not isinstance(event, RawResponsesStreamEvent): |
| 59 | continue |
| 60 | data = event.data |
| 61 | if isinstance(data, ResponseTextDeltaEvent): |
| 62 | print(data.delta, end="", flush=True) |
| 63 | elif isinstance(data, ResponseContentPartDoneEvent): |
| 64 | print("\n") |
| 65 | |
| 66 | inputs = result.to_input_list() |
| 67 | print("\n") |
| 68 | |
| 69 | if auto_mode: |
| 70 | break |
| 71 | user_msg = input_with_fallback("Enter a message: ", "Thanks!") |
| 72 | inputs.append({"content": user_msg, "role": "user"}) |
| 73 | agent = result.current_agent |
| 74 | |
| 75 | |
| 76 | if __name__ == "__main__": |
no test coverage detected