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

Function main

examples/agent_patterns/deterministic.py:42–80  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

40
41
42async def main():
43 input_prompt = input_with_fallback(
44 "What kind of story do you want? ",
45 "Write a short sci-fi story.",
46 )
47
48 # Ensure the entire workflow is a single trace
49 with trace("Deterministic story flow"):
50 # 1. Generate an outline
51 outline_result = await Runner.run(
52 story_outline_agent,
53 input_prompt,
54 )
55 print("Outline generated")
56
57 # 2. Check the outline
58 outline_checker_result = await Runner.run(
59 outline_checker_agent,
60 outline_result.final_output,
61 )
62
63 # 3. Add a gate to stop if the outline is not good quality or not a scifi story
64 assert isinstance(outline_checker_result.final_output, OutlineCheckerOutput)
65 if not outline_checker_result.final_output.good_quality:
66 print("Outline is not good quality, so we stop here.")
67 exit(0)
68
69 if not outline_checker_result.final_output.is_scifi:
70 print("Outline is not a scifi story, so we stop here.")
71 exit(0)
72
73 print("Outline is good quality and a scifi story, so we continue to write the story.")
74
75 # 4. Write the story
76 story_result = await Runner.run(
77 story_agent,
78 outline_result.final_output,
79 )
80 print(f"Story: {story_result.final_output}")
81
82
83if __name__ == "__main__":

Callers 1

deterministic.pyFile · 0.70

Calls 3

input_with_fallbackFunction · 0.90
traceFunction · 0.90
runMethod · 0.45

Tested by

no test coverage detected