From 536d7826d550ed1e295ebeca45386c6f6fd00420 Mon Sep 17 00:00:00 2001 From: Dmitry Pimenov Date: Wed, 12 Mar 2025 17:24:35 -0700 Subject: [PATCH] added a Jupyter example to clarify how to use the SDK with an existing event loop --- README.md | 4 +++- examples/basic/hello_world_jupyter.py | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 examples/basic/hello_world_jupyter.py diff --git a/README.md b/README.md index d3f25fa..32984bc 100644 --- a/README.md +++ b/README.md @@ -47,9 +47,11 @@ print(result.final_output) (_If running this, ensure you set the `OPENAI_API_KEY` environment variable_) +(_For Jupyter notebook users, see [hello_world_jupyter.py](examples/basic/hello_world_jupyter.py)_) + ## Handoffs example -```py +```python from agents import Agent, Runner import asyncio diff --git a/examples/basic/hello_world_jupyter.py b/examples/basic/hello_world_jupyter.py new file mode 100644 index 0000000..6b0f275 --- /dev/null +++ b/examples/basic/hello_world_jupyter.py @@ -0,0 +1,11 @@ +from agents import Agent, Runner + +agent = Agent(name="Assistant", instructions="You are a helpful assistant") + +# Intended for Jupyter notebooks where there's an existing event loop +result = await Runner.run(agent, "Write a haiku about recursion in programming.") +print(result.final_output) + +# Code within code loops, +# Infinite mirrors reflect— +# Logic folds on self.