Skip to content

Conversation

@seratch
Copy link
Member

@seratch seratch commented Oct 21, 2025

Update the package metadata and CI builds

Copy link
Member Author

@seratch seratch left a comment

Choose a reason for hiding this comment

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

While the installation now passes, some of tests are still failing

pyproject.toml Outdated
"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.

@seratch seratch marked this pull request as draft October 21, 2025 09:48
@seratch
Copy link
Member Author

seratch commented Oct 21, 2025

=================================== FAILURES ===================================
________________________ test_sync_agent_hook_with_llm _________________________

    def test_sync_agent_hook_with_llm():
        hooks = AgentHooksForTests()
        model = FakeModel()
        agent = Agent(
            name="A", model=model, tools=[get_function_tool("f", "res")], handoffs=[], hooks=hooks
        )
        # Simulate a single LLM call producing an output:
        model.set_next_output([get_text_message("hello")])
>       Runner.run_sync(agent, input="hello")

tests/test_agent_llm_hooks.py:97: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/agents/run.py:416: in run_sync
    return runner.run_sync(
src/agents/run.py:723: in run_sync
    return asyncio.get_event_loop().run_until_complete(
           ^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <asyncio.unix_events._UnixDefaultEventLoopPolicy object at 0x7fb9d9b4cd70>

    def get_event_loop(self):
        """Get the event loop for the current context.
    
        Returns an instance of EventLoop or raises an exception.
        """
        if self._local._loop is None:
>           raise RuntimeError('There is no current event loop in thread %r.'
                               % threading.current_thread().name)
E           RuntimeError: There is no current event loop in thread 'MainThread'.

../../../.local/share/uv/python/cpython-3.14.0-linux-x86_64-gnu/lib/python3.14/asyncio/events.py:715: RuntimeError
_________________________ test_sync_run_hook_with_llm __________________________

    def test_sync_run_hook_with_llm():
        hooks = RunHooksForTests()
        model = FakeModel()
        agent = Agent(name="A", model=model, tools=[get_function_tool("f", "res")], handoffs=[])
        # Simulate a single LLM call producing an output:
        model.set_next_output([get_text_message("hello")])
>       Runner.run_sync(agent, input="hello", hooks=hooks)

tests/test_run_hooks.py:105: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/agents/run.py:416: in run_sync
    return runner.run_sync(
src/agents/run.py:723: in run_sync
    return asyncio.get_event_loop().run_until_complete(
           ^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <asyncio.unix_events._UnixDefaultEventLoopPolicy object at 0x7fb9d9b4cd70>

    def get_event_loop(self):
        """Get the event loop for the current context.
    
        Returns an instance of EventLoop or raises an exception.
        """
        if self._local._loop is None:
>           raise RuntimeError('There is no current event loop in thread %r.'
                               % threading.current_thread().name)
E           RuntimeError: There is no current event loop in thread 'MainThread'.

../../../.local/share/uv/python/cpython-3.14.0-linux-x86_64-gnu/lib/python3.14/asyncio/events.py:715: RuntimeError
=============================== warnings summary ===============================
.venv/lib/python3.14/site-packages/fastapi/routing.py:234
  /home/runner/work/openai-agents-python/openai-agents-python/.venv/lib/python3.14/site-packages/fastapi/routing.py:234: DeprecationWarning: 'asyncio.iscoroutinefunction' is deprecated and slated for removal in Python 3.16; use inspect.iscoroutinefunction() instead
    is_coroutine = asyncio.iscoroutinefunction(dependant.call)

.venv/lib/python3.14/site-packages/litellm/litellm_core_utils/logging_utils.py:160: 17 warnings
  /home/runner/work/openai-agents-python/openai-agents-python/.venv/lib/python3.14/site-packages/litellm/litellm_core_utils/logging_utils.py:160: DeprecationWarning: 'asyncio.iscoroutinefunction' is deprecated and slated for removal in Python 3.16; use inspect.iscoroutinefunction() instead
    if asyncio.iscoroutinefunction(func):

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ============================
FAILED tests/test_agent_llm_hooks.py::test_sync_agent_hook_with_llm - RuntimeError: There is no current event loop in thread 'MainThread'.
FAILED tests/test_run_hooks.py::test_sync_run_hook_with_llm - RuntimeError: There is no current event loop in thread 'MainThread'.
============ 2 failed, 918 passed, 3 skipped, 18 warnings in 30.69s ============
make: *** [Makefile:29: coverage] Error 1

https://github.com/openai/openai-agents-python/actions/runs/18679862649/job/53258264262?pr=1961

pyproject.toml Outdated
"openai>=2.2,<3",
"pydantic>=2.10, <3",
"openai>=2.6,<3",
"tiktoken>=0.12,<0.13",
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?

@ProCityHub

This comment was marked as off-topic.

@Xahid88

This comment was marked as off-topic.

@seratch seratch marked this pull request as ready for review October 29, 2025 02:04
@seratch
Copy link
Member Author

seratch commented Oct 29, 2025

I've removed tiktoken as it's no longer necessary to explicitly have

@seratch seratch merged commit 1466ddb into main Oct 29, 2025
9 checks passed
@seratch seratch deleted the python-3.14 branch October 29, 2025 02:09
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +723 to 738
# 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,

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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants