MCPcopy
hub / github.com/openai/openai-agents-python / main

Function main

examples/agent_patterns/routing.py:37–73  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

35
36
37async 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
76if __name__ == "__main__":

Callers 1

routing.pyFile · 0.70

Calls 7

input_with_fallbackFunction · 0.90
is_auto_modeFunction · 0.90
traceFunction · 0.90
appendMethod · 0.80
run_streamedMethod · 0.45
stream_eventsMethod · 0.45
to_input_listMethod · 0.45

Tested by

no test coverage detected