Merge pull request #113 from openai/examples/jupyter

Adding Jupyter notebook example
This commit is contained in:
Rohan Mehta 2025-03-12 17:43:25 -07:00 committed by GitHub
commit 7b8122686f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View file

@ -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

View file

@ -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.") # type: ignore[top-level-await] # noqa: F704
print(result.final_output)
# Code within code loops,
# Infinite mirrors reflect—
# Logic folds on self.