MCPcopy Index your code
hub / github.com/openai/openai-agents-python / main

Function main

examples/agent_patterns/parallelization.py:22–61  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20
21
22async def main():
23 msg = input_with_fallback(
24 "Hi! Enter a message, and we'll translate it to Spanish.\n\n",
25 "Good morning!",
26 )
27
28 # Ensure the entire workflow is a single trace
29 with trace("Parallel translation"):
30 res_1, res_2, res_3 = await asyncio.gather(
31 Runner.run(
32 spanish_agent,
33 msg,
34 ),
35 Runner.run(
36 spanish_agent,
37 msg,
38 ),
39 Runner.run(
40 spanish_agent,
41 msg,
42 ),
43 )
44
45 outputs = [
46 ItemHelpers.text_message_outputs(res_1.new_items),
47 ItemHelpers.text_message_outputs(res_2.new_items),
48 ItemHelpers.text_message_outputs(res_3.new_items),
49 ]
50
51 translations = "\n\n".join(outputs)
52 print(f"\n\nTranslations:\n\n{translations}")
53
54 best_translation = await Runner.run(
55 translation_picker,
56 f"Input: {msg}\n\nTranslations:\n{translations}",
57 )
58
59 print("\n\n-----")
60
61 print(f"Best translation: {best_translation.final_output}")
62
63
64if __name__ == "__main__":

Callers 1

parallelization.pyFile · 0.70

Calls 4

input_with_fallbackFunction · 0.90
traceFunction · 0.90
text_message_outputsMethod · 0.80
runMethod · 0.45

Tested by

no test coverage detected