()
| 40 | |
| 41 | |
| 42 | async 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 | |
| 83 | if __name__ == "__main__": |
no test coverage detected