Skip to content

Commit ca86ef6

Browse files
committed
PR feedback
1 parent c0faa1e commit ca86ef6

File tree

6 files changed

+40
-40
lines changed

6 files changed

+40
-40
lines changed

temporalio/contrib/openai_agents/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"""
1010

1111
from temporalio.contrib.openai_agents._model_parameters import ModelActivityParameters
12-
from temporalio.contrib.openai_agents._openai_runner import AgentsWorkflowFailure
12+
from temporalio.contrib.openai_agents._openai_runner import AgentsWorkflowError
1313
from temporalio.contrib.openai_agents._temporal_openai_agents import (
1414
OpenAIAgentsPlugin,
1515
TestModel,
@@ -22,7 +22,7 @@
2222
from . import workflow
2323

2424
__all__ = [
25-
"AgentsWorkflowFailure",
25+
"AgentsWorkflowError",
2626
"OpenAIAgentsPlugin",
2727
"ModelActivityParameters",
2828
"workflow",

temporalio/contrib/openai_agents/_openai_runner.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,7 @@
2222
from temporalio import workflow
2323
from temporalio.contrib.openai_agents._model_parameters import ModelActivityParameters
2424
from temporalio.contrib.openai_agents._temporal_model_stub import _TemporalModelStub
25-
from temporalio.exceptions import ApplicationError, TemporalError
26-
27-
28-
class AgentsWorkflowFailure(TemporalError):
29-
"""Error that occurs when the agents SDK raises an error which should terminate the calling workflow.
30-
31-
.. warning::
32-
This exception is experimental and may change in future versions.
33-
Use with caution in production environments.
34-
"""
25+
from temporalio.contrib.openai_agents.workflow import AgentsWorkflowError
3526

3627

3728
class TemporalOpenAIRunner(AgentRunner):
@@ -161,8 +152,8 @@ async def on_invoke(
161152
except AgentsException as e:
162153
# In order for workflow failures to properly fail the workflow, we need to rewrap them in
163154
# a Temporal error
164-
if e.__cause__ and workflow.is_workflow_failure_exception(e.__cause__):
165-
reraise = AgentsWorkflowFailure(
155+
if e.__cause__ and workflow.is_failure_exception(e.__cause__):
156+
reraise = AgentsWorkflowError(
166157
f"Workflow failure exception in Agents Framework: {e}"
167158
)
168159
reraise.__traceback__ = e.__traceback__

temporalio/contrib/openai_agents/_temporal_openai_agents.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from temporalio.contrib.openai_agents._invoke_model_activity import ModelActivity
2929
from temporalio.contrib.openai_agents._model_parameters import ModelActivityParameters
3030
from temporalio.contrib.openai_agents._openai_runner import (
31-
AgentsWorkflowFailure,
31+
AgentsWorkflowError,
3232
TemporalOpenAIRunner,
3333
)
3434
from temporalio.contrib.openai_agents._temporal_trace_provider import (
@@ -289,7 +289,7 @@ def configure_worker(self, config: WorkerConfig) -> WorkerConfig:
289289
]
290290
config["workflow_failure_exception_types"] = list(
291291
config.get("workflow_failure_exception_types") or []
292-
) + [AgentsWorkflowFailure]
292+
) + [AgentsWorkflowError]
293293
return self.next_worker_plugin.configure_worker(config)
294294

295295
async def run_worker(self, worker: Worker) -> None:

temporalio/contrib/openai_agents/workflow.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,12 @@ class ToolSerializationError(TemporalError):
263263
To fix this error, ensure your tool returns string-convertible values or
264264
modify the tool to return a string representation of the result.
265265
"""
266+
267+
268+
class AgentsWorkflowError(TemporalError):
269+
"""Error that occurs when the agents SDK raises an error which should terminate the calling workflow.
270+
271+
.. warning::
272+
This exception is experimental and may change in future versions.
273+
Use with caution in production environments.
274+
"""

temporalio/worker/_workflow_instance.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ def activate(
414414
# We want some errors during activation, like those that can happen
415415
# during payload conversion, to be able to fail the workflow not the
416416
# task
417-
if self.is_workflow_failure_exception(err):
417+
if self.workflow_is_failure_exception(err):
418418
try:
419419
self._set_workflow_failure(err)
420420
except Exception as inner_err:
@@ -629,7 +629,7 @@ async def run_update() -> None:
629629
# Validation failures are always update failures. We reuse
630630
# workflow failure logic to decide task failure vs update
631631
# failure after validation.
632-
if not past_validation or self.is_workflow_failure_exception(err):
632+
if not past_validation or self.workflow_is_failure_exception(err):
633633
if command is None:
634634
command = self._add_command()
635635
command.update_response.protocol_instance_id = (
@@ -1686,6 +1686,23 @@ def workflow_set_current_details(self, details: str):
16861686
self._assert_not_read_only("set current details")
16871687
self._current_details = details
16881688

1689+
def workflow_is_failure_exception(self, err: BaseException) -> bool:
1690+
# An exception is a failure instead of a task fail if it's already a
1691+
# failure error or if it is a timeout error or if it is an instance of
1692+
# any of the failure types in the worker or workflow-level setting
1693+
wf_failure_exception_types = self._defn.failure_exception_types
1694+
if self._dynamic_failure_exception_types is not None:
1695+
wf_failure_exception_types = self._dynamic_failure_exception_types
1696+
return (
1697+
isinstance(err, temporalio.exceptions.FailureError)
1698+
or isinstance(err, asyncio.TimeoutError)
1699+
or any(isinstance(err, typ) for typ in wf_failure_exception_types)
1700+
or any(
1701+
isinstance(err, typ)
1702+
for typ in self._worker_level_failure_exception_types
1703+
)
1704+
)
1705+
16891706
#### Calls from outbound impl ####
16901707
# These are in alphabetical order and all start with "_outbound_".
16911708

@@ -1939,7 +1956,7 @@ def _convert_payloads(
19391956
# Don't wrap payload conversion errors that would fail the workflow
19401957
raise
19411958
except Exception as err:
1942-
if self.is_workflow_failure_exception(err):
1959+
if self.workflow_is_failure_exception(err):
19431960
raise
19441961
raise RuntimeError("Failed decoding arguments") from err
19451962

@@ -1982,23 +1999,6 @@ def _instantiate_workflow_object(self) -> Any:
19821999

19832000
return workflow_instance
19842001

1985-
def is_workflow_failure_exception(self, err: BaseException) -> bool:
1986-
# An exception is a failure instead of a task fail if it's already a
1987-
# failure error or if it is a timeout error or if it is an instance of
1988-
# any of the failure types in the worker or workflow-level setting
1989-
wf_failure_exception_types = self._defn.failure_exception_types
1990-
if self._dynamic_failure_exception_types is not None:
1991-
wf_failure_exception_types = self._dynamic_failure_exception_types
1992-
return (
1993-
isinstance(err, temporalio.exceptions.FailureError)
1994-
or isinstance(err, asyncio.TimeoutError)
1995-
or any(isinstance(err, typ) for typ in wf_failure_exception_types)
1996-
or any(
1997-
isinstance(err, typ)
1998-
for typ in self._worker_level_failure_exception_types
1999-
)
2000-
)
2001-
20022002
def _warn_if_unfinished_handlers(self) -> None:
20032003
def warnable(handler_executions: Iterable[HandlerExecution]):
20042004
return [
@@ -2192,7 +2192,7 @@ async def _run_top_level_workflow_function(self, coro: Awaitable[None]) -> None:
21922192
err
21932193
):
21942194
self._add_command().cancel_workflow_execution.SetInParent()
2195-
elif self.is_workflow_failure_exception(err):
2195+
elif self.workflow_is_failure_exception(err):
21962196
# All other failure errors fail the workflow
21972197
self._set_workflow_failure(err)
21982198
else:

temporalio/workflow.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ def workflow_get_current_details(self) -> str: ...
898898
def workflow_set_current_details(self, details: str): ...
899899

900900
@abstractmethod
901-
def is_workflow_failure_exception(self, err: BaseException) -> bool: ...
901+
def workflow_is_failure_exception(self, err: BaseException) -> bool: ...
902902

903903

904904
_current_update_info: contextvars.ContextVar[UpdateInfo] = contextvars.ContextVar(
@@ -984,13 +984,13 @@ def memo() -> Mapping[str, Any]:
984984
return _Runtime.current().workflow_memo()
985985

986986

987-
def is_workflow_failure_exception(err: BaseException) -> bool:
987+
def is_failure_exception(err: BaseException) -> bool:
988988
"""Checks if the given exception is a workflow failure in the current workflow.
989989
990990
Returns:
991991
True if the given exception is a workflow failure in the current workflow.
992992
"""
993-
return _Runtime.current().is_workflow_failure_exception(err)
993+
return _Runtime.current().workflow_is_failure_exception(err)
994994

995995

996996
@overload

0 commit comments

Comments
 (0)