Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ jobs:
- "3.11"
- "3.12"
- "3.13"
# TODO: enable this https://github.com/openai/openai-agents-python/pull/1961/
# - "3.14"
- "3.14"
env:
OPENAI_API_KEY: fake-for-tests
steps:
Expand Down
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ requires-python = ">=3.9"
license = "MIT"
authors = [{ name = "OpenAI", email = "[email protected]" }]
dependencies = [
"openai>=2.2,<3",
"pydantic>=2.10, <3",
"openai>=2.6,<3",
"tiktoken>=0.12,<0.13",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these version upgrades are required to install deps

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need tiktoken?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tiktoken==0.11.0 coming from somewhere blocks pip install w/ python 3.14. need to check more deeply.

"pydantic>=2.12.3, <3",
"griffe>=1.5.6, <2",
"typing-extensions>=4.12.2, <5",
"requests>=2.0, <3",
Expand All @@ -24,6 +25,7 @@ classifiers = [
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Operating System :: OS Independent",
"Topic :: Software Development :: Libraries :: Python Modules",
"License :: OSI Approved :: MIT License",
Expand Down
14 changes: 13 additions & 1 deletion src/agents/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,19 @@ def run_sync(
conversation_id = kwargs.get("conversation_id")
session = kwargs.get("session")

return asyncio.get_event_loop().run_until_complete(
# Python 3.14 no longer creates a default loop implicitly, so we inspect the running loop.
try:
loop = asyncio.get_running_loop()
except RuntimeError:
loop = None

if loop is not None:
# This method is only expected to run when no loop is already active.
raise RuntimeError(
"AgentRunner.run_sync() cannot be called when an event loop is already running."
)

return asyncio.run(
self.run(
starting_agent,
input,
Comment on lines +723 to 738

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reusing sessions fails after switching run_sync to asyncio.run

The new implementation of AgentRunner.run_sync (lines 723‑740) always spins up a brand‑new event loop via asyncio.run. Many of the session implementations that users are expected to instantiate in synchronous code create loop‑bound primitives up front. For example, RedisSession and SQLAlchemySession both allocate an asyncio.Lock() in their constructors (src/agents/extensions/memory/redis_session.py:67, src/agents/extensions/memory/sqlalchemy_session.py:83). Those locks are bound to the thread’s default loop at construction time. Because asyncio.run now uses a different loop for the actual run, the first async with self._lock in get_items/add_items raises RuntimeError: <Lock> is bound to a different event loop, making Runner.run_sync(..., session=RedisSession(...)) or SQLAlchemySession unusable even on CPython 3.12/3.13. The previous get_event_loop().run_until_complete reused the same loop, so these sessions worked. To avoid regressing synchronous session support you need to keep using the thread’s default loop (e.g. reuse/initialize it once) or ensure these components are instantiated after the loop is created.

Useful? React with 👍 / 👎.

Expand Down
Loading