You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] openai_agents: a RunState rebuilt with RunState.from_string and resumed in a workflow hangs (approvals after continue-as-new) #53
What are you really trying to do?
Human-in-the-loop with @function_tool(needs_approval=True): persist the paused RunState as a
string (for example to pass through continue_as_new when history gets long), approve later, resume.
Describe the bug
Resuming works in memory, but after state.to_string() / RunState.from_string(agent, s) the run
uses the original (unconverted) agent objects, so the real OpenAI model provider runs inside the
workflow and raises RestrictedWorkflowAccessError (platform.system). That fails the workflow task, and the workflow hangs until its timeout. The openai-agents SDK matches approvals by agent object
identity, so just swapping _current_agent / _starting_agent in the runner stops the network access
but the approval is then not honored (the state's items still hold the original agent objects).
mode="direct" completes. Any other mode times out with RestrictedWorkflowAccessError in the worker
log. (Test model: a TestModel that returns a tool call to dangerous, then a message.)
Building the state with the private _convert_agent(...) result instead works.
Additional context
I put a proposed fix on a branch and will open it as a draft PR so it is easy to react to. It adds temporalio.openai_agents.workflow.run_state_from_string(agent, state_string, ...), which builds the
state against Temporal-converted agents, plus a guard that makes Runner.run/run_streamed raise a
clear ValueError (pointing at the helper) for a state whose current agent is not converted. I'm
happy to change the shape (public helper vs. making the runner rebind agents inside the state) if you
prefer a different approach; I chose the helper because rebinding would mean rewriting several private
structures of RunState.
Activity