From 926e3f7c7ecd1501f1b42a9f0faa5db9a5631b04 Mon Sep 17 00:00:00 2001 From: Tim Conley Date: Thu, 21 Aug 2025 09:03:26 -0700 Subject: [PATCH 1/3] Remove 'activity' from the model activity name --- temporalio/contrib/openai_agents/_invoke_model_activity.py | 5 +++++ temporalio/contrib/openai_agents/_temporal_model_stub.py | 2 +- temporalio/contrib/openai_agents/_temporal_openai_agents.py | 4 +++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/temporalio/contrib/openai_agents/_invoke_model_activity.py b/temporalio/contrib/openai_agents/_invoke_model_activity.py index ed4313537..b81c2e1fd 100644 --- a/temporalio/contrib/openai_agents/_invoke_model_activity.py +++ b/temporalio/contrib/openai_agents/_invoke_model_activity.py @@ -158,6 +158,11 @@ def __init__(self, model_provider: Optional[ModelProvider] = None): openai_client=AsyncOpenAI(max_retries=0) ) + @activity.defn + async def invoke_model(self, input: ActivityModelInput) -> ModelResponse: + """Activity that invokes a model with the given input.""" + return await self.invoke_model_activity(input) + @activity.defn @_auto_heartbeater async def invoke_model_activity(self, input: ActivityModelInput) -> ModelResponse: diff --git a/temporalio/contrib/openai_agents/_temporal_model_stub.py b/temporalio/contrib/openai_agents/_temporal_model_stub.py index 11f1ddc5e..986efc0e5 100644 --- a/temporalio/contrib/openai_agents/_temporal_model_stub.py +++ b/temporalio/contrib/openai_agents/_temporal_model_stub.py @@ -153,7 +153,7 @@ def make_tool_info(tool: Tool) -> ToolInput: summary = None return await workflow.execute_activity_method( - ModelActivity.invoke_model_activity, + ModelActivity.invoke_model, activity_input, summary=summary, task_queue=self.model_params.task_queue, diff --git a/temporalio/contrib/openai_agents/_temporal_openai_agents.py b/temporalio/contrib/openai_agents/_temporal_openai_agents.py index 73b9723d0..419339455 100644 --- a/temporalio/contrib/openai_agents/_temporal_openai_agents.py +++ b/temporalio/contrib/openai_agents/_temporal_openai_agents.py @@ -281,8 +281,10 @@ def configure_worker(self, config: WorkerConfig) -> WorkerConfig: config["interceptors"] = list(config.get("interceptors") or []) + [ OpenAIAgentsTracingInterceptor() ] + model_activity = ModelActivity(self._model_provider) config["activities"] = list(config.get("activities") or []) + [ - ModelActivity(self._model_provider).invoke_model_activity + model_activity.invoke_model_activity, + model_activity.invoke_model, ] return self.next_worker_plugin.configure_worker(config) From 935232111a082ce34f353f4a43fd17a756000a6a Mon Sep 17 00:00:00 2001 From: Tim Conley Date: Thu, 21 Aug 2025 09:19:33 -0700 Subject: [PATCH 2/3] Don't try to have both --- temporalio/contrib/openai_agents/_invoke_model_activity.py | 7 +------ .../contrib/openai_agents/_temporal_openai_agents.py | 4 +--- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/temporalio/contrib/openai_agents/_invoke_model_activity.py b/temporalio/contrib/openai_agents/_invoke_model_activity.py index b81c2e1fd..5fa31f472 100644 --- a/temporalio/contrib/openai_agents/_invoke_model_activity.py +++ b/temporalio/contrib/openai_agents/_invoke_model_activity.py @@ -158,14 +158,9 @@ def __init__(self, model_provider: Optional[ModelProvider] = None): openai_client=AsyncOpenAI(max_retries=0) ) - @activity.defn - async def invoke_model(self, input: ActivityModelInput) -> ModelResponse: - """Activity that invokes a model with the given input.""" - return await self.invoke_model_activity(input) - @activity.defn @_auto_heartbeater - async def invoke_model_activity(self, input: ActivityModelInput) -> ModelResponse: + async def invoke_model(self, input: ActivityModelInput) -> ModelResponse: """Activity that invokes a model with the given input.""" model = self._model_provider.get_model(input.get("model_name")) diff --git a/temporalio/contrib/openai_agents/_temporal_openai_agents.py b/temporalio/contrib/openai_agents/_temporal_openai_agents.py index 419339455..d407a8f94 100644 --- a/temporalio/contrib/openai_agents/_temporal_openai_agents.py +++ b/temporalio/contrib/openai_agents/_temporal_openai_agents.py @@ -281,10 +281,8 @@ def configure_worker(self, config: WorkerConfig) -> WorkerConfig: config["interceptors"] = list(config.get("interceptors") or []) + [ OpenAIAgentsTracingInterceptor() ] - model_activity = ModelActivity(self._model_provider) config["activities"] = list(config.get("activities") or []) + [ - model_activity.invoke_model_activity, - model_activity.invoke_model, + ModelActivity(self._model_provider).invoke_model, ] return self.next_worker_plugin.configure_worker(config) From b8020515592d60922388c75c5f1204febc520758 Mon Sep 17 00:00:00 2001 From: Tim Conley Date: Thu, 21 Aug 2025 09:21:57 -0700 Subject: [PATCH 3/3] Rename in histories --- .../agents-as-tools-workflow-history.json | 8 +++---- .../customer-service-workflow-history.json | 12 +++++----- .../histories/hello-workflow-history.json | 2 +- .../input-guardrail-workflow-history.json | 8 +++---- .../output-guardrail-workflow-history.json | 2 +- .../histories/research-workflow-history.json | 24 +++++++++---------- .../histories/tools-workflow-history.json | 4 ++-- 7 files changed, 30 insertions(+), 30 deletions(-) diff --git a/tests/contrib/openai_agents/histories/agents-as-tools-workflow-history.json b/tests/contrib/openai_agents/histories/agents-as-tools-workflow-history.json index 21090cbdd..84953a3a6 100644 --- a/tests/contrib/openai_agents/histories/agents-as-tools-workflow-history.json +++ b/tests/contrib/openai_agents/histories/agents-as-tools-workflow-history.json @@ -96,7 +96,7 @@ "activityTaskScheduledEventAttributes": { "activityId": "1", "activityType": { - "name": "invoke_model_activity" + "name": "invoke_model" }, "taskQueue": { "name": "1e8fa3c8-41b4-4ea7-907b-63088b63e36f", @@ -233,7 +233,7 @@ "activityTaskScheduledEventAttributes": { "activityId": "2", "activityType": { - "name": "invoke_model_activity" + "name": "invoke_model" }, "taskQueue": { "name": "1e8fa3c8-41b4-4ea7-907b-63088b63e36f", @@ -370,7 +370,7 @@ "activityTaskScheduledEventAttributes": { "activityId": "3", "activityType": { - "name": "invoke_model_activity" + "name": "invoke_model" }, "taskQueue": { "name": "1e8fa3c8-41b4-4ea7-907b-63088b63e36f", @@ -499,7 +499,7 @@ "activityTaskScheduledEventAttributes": { "activityId": "4", "activityType": { - "name": "invoke_model_activity" + "name": "invoke_model" }, "taskQueue": { "name": "1e8fa3c8-41b4-4ea7-907b-63088b63e36f", diff --git a/tests/contrib/openai_agents/histories/customer-service-workflow-history.json b/tests/contrib/openai_agents/histories/customer-service-workflow-history.json index d5c878c4b..91080ac01 100644 --- a/tests/contrib/openai_agents/histories/customer-service-workflow-history.json +++ b/tests/contrib/openai_agents/histories/customer-service-workflow-history.json @@ -162,7 +162,7 @@ "activityTaskScheduledEventAttributes": { "activityId": "1", "activityType": { - "name": "invoke_model_activity" + "name": "invoke_model" }, "taskQueue": { "name": "be82986c-9ddc-441b-9833-c3fce7c79df1", @@ -400,7 +400,7 @@ "activityTaskScheduledEventAttributes": { "activityId": "2", "activityType": { - "name": "invoke_model_activity" + "name": "invoke_model" }, "taskQueue": { "name": "be82986c-9ddc-441b-9833-c3fce7c79df1", @@ -537,7 +537,7 @@ "activityTaskScheduledEventAttributes": { "activityId": "3", "activityType": { - "name": "invoke_model_activity" + "name": "invoke_model" }, "taskQueue": { "name": "be82986c-9ddc-441b-9833-c3fce7c79df1", @@ -767,7 +767,7 @@ "activityTaskScheduledEventAttributes": { "activityId": "4", "activityType": { - "name": "invoke_model_activity" + "name": "invoke_model" }, "taskQueue": { "name": "be82986c-9ddc-441b-9833-c3fce7c79df1", @@ -1005,7 +1005,7 @@ "activityTaskScheduledEventAttributes": { "activityId": "5", "activityType": { - "name": "invoke_model_activity" + "name": "invoke_model" }, "taskQueue": { "name": "be82986c-9ddc-441b-9833-c3fce7c79df1", @@ -1142,7 +1142,7 @@ "activityTaskScheduledEventAttributes": { "activityId": "6", "activityType": { - "name": "invoke_model_activity" + "name": "invoke_model" }, "taskQueue": { "name": "be82986c-9ddc-441b-9833-c3fce7c79df1", diff --git a/tests/contrib/openai_agents/histories/hello-workflow-history.json b/tests/contrib/openai_agents/histories/hello-workflow-history.json index 9532fc831..c15905ec8 100644 --- a/tests/contrib/openai_agents/histories/hello-workflow-history.json +++ b/tests/contrib/openai_agents/histories/hello-workflow-history.json @@ -96,7 +96,7 @@ "activityTaskScheduledEventAttributes": { "activityId": "1", "activityType": { - "name": "invoke_model_activity" + "name": "invoke_model" }, "taskQueue": { "name": "5dd7a6ba-834c-4206-bcbc-a02599f1b54c", diff --git a/tests/contrib/openai_agents/histories/input-guardrail-workflow-history.json b/tests/contrib/openai_agents/histories/input-guardrail-workflow-history.json index 2054b1750..73094f666 100644 --- a/tests/contrib/openai_agents/histories/input-guardrail-workflow-history.json +++ b/tests/contrib/openai_agents/histories/input-guardrail-workflow-history.json @@ -96,7 +96,7 @@ "activityTaskScheduledEventAttributes": { "activityId": "1", "activityType": { - "name": "invoke_model_activity" + "name": "invoke_model" }, "taskQueue": { "name": "e488932b-c66d-48b6-97cb-7b8feaa1c41c", @@ -151,7 +151,7 @@ "activityTaskScheduledEventAttributes": { "activityId": "2", "activityType": { - "name": "invoke_model_activity" + "name": "invoke_model" }, "taskQueue": { "name": "e488932b-c66d-48b6-97cb-7b8feaa1c41c", @@ -370,7 +370,7 @@ "activityTaskScheduledEventAttributes": { "activityId": "3", "activityType": { - "name": "invoke_model_activity" + "name": "invoke_model" }, "taskQueue": { "name": "e488932b-c66d-48b6-97cb-7b8feaa1c41c", @@ -425,7 +425,7 @@ "activityTaskScheduledEventAttributes": { "activityId": "4", "activityType": { - "name": "invoke_model_activity" + "name": "invoke_model" }, "taskQueue": { "name": "e488932b-c66d-48b6-97cb-7b8feaa1c41c", diff --git a/tests/contrib/openai_agents/histories/output-guardrail-workflow-history.json b/tests/contrib/openai_agents/histories/output-guardrail-workflow-history.json index a7a62944c..0cec5809f 100644 --- a/tests/contrib/openai_agents/histories/output-guardrail-workflow-history.json +++ b/tests/contrib/openai_agents/histories/output-guardrail-workflow-history.json @@ -86,7 +86,7 @@ "activityTaskScheduledEventAttributes": { "activityId": "1", "activityType": { - "name": "invoke_model_activity" + "name": "invoke_model" }, "taskQueue": { "name": "2227feb4-0f1d-4092-9653-308e9366edb0", diff --git a/tests/contrib/openai_agents/histories/research-workflow-history.json b/tests/contrib/openai_agents/histories/research-workflow-history.json index be38a0be0..99b02cdf6 100644 --- a/tests/contrib/openai_agents/histories/research-workflow-history.json +++ b/tests/contrib/openai_agents/histories/research-workflow-history.json @@ -96,7 +96,7 @@ "activityTaskScheduledEventAttributes": { "activityId": "1", "activityType": { - "name": "invoke_model_activity" + "name": "invoke_model" }, "taskQueue": { "name": "fc97ba3c-6c32-4f4c-a986-8d7f4f5c7f80", @@ -233,7 +233,7 @@ "activityTaskScheduledEventAttributes": { "activityId": "2", "activityType": { - "name": "invoke_model_activity" + "name": "invoke_model" }, "taskQueue": { "name": "fc97ba3c-6c32-4f4c-a986-8d7f4f5c7f80", @@ -288,7 +288,7 @@ "activityTaskScheduledEventAttributes": { "activityId": "3", "activityType": { - "name": "invoke_model_activity" + "name": "invoke_model" }, "taskQueue": { "name": "fc97ba3c-6c32-4f4c-a986-8d7f4f5c7f80", @@ -343,7 +343,7 @@ "activityTaskScheduledEventAttributes": { "activityId": "4", "activityType": { - "name": "invoke_model_activity" + "name": "invoke_model" }, "taskQueue": { "name": "fc97ba3c-6c32-4f4c-a986-8d7f4f5c7f80", @@ -398,7 +398,7 @@ "activityTaskScheduledEventAttributes": { "activityId": "5", "activityType": { - "name": "invoke_model_activity" + "name": "invoke_model" }, "taskQueue": { "name": "fc97ba3c-6c32-4f4c-a986-8d7f4f5c7f80", @@ -453,7 +453,7 @@ "activityTaskScheduledEventAttributes": { "activityId": "6", "activityType": { - "name": "invoke_model_activity" + "name": "invoke_model" }, "taskQueue": { "name": "fc97ba3c-6c32-4f4c-a986-8d7f4f5c7f80", @@ -508,7 +508,7 @@ "activityTaskScheduledEventAttributes": { "activityId": "7", "activityType": { - "name": "invoke_model_activity" + "name": "invoke_model" }, "taskQueue": { "name": "fc97ba3c-6c32-4f4c-a986-8d7f4f5c7f80", @@ -563,7 +563,7 @@ "activityTaskScheduledEventAttributes": { "activityId": "8", "activityType": { - "name": "invoke_model_activity" + "name": "invoke_model" }, "taskQueue": { "name": "fc97ba3c-6c32-4f4c-a986-8d7f4f5c7f80", @@ -618,7 +618,7 @@ "activityTaskScheduledEventAttributes": { "activityId": "9", "activityType": { - "name": "invoke_model_activity" + "name": "invoke_model" }, "taskQueue": { "name": "fc97ba3c-6c32-4f4c-a986-8d7f4f5c7f80", @@ -673,7 +673,7 @@ "activityTaskScheduledEventAttributes": { "activityId": "10", "activityType": { - "name": "invoke_model_activity" + "name": "invoke_model" }, "taskQueue": { "name": "fc97ba3c-6c32-4f4c-a986-8d7f4f5c7f80", @@ -728,7 +728,7 @@ "activityTaskScheduledEventAttributes": { "activityId": "11", "activityType": { - "name": "invoke_model_activity" + "name": "invoke_model" }, "taskQueue": { "name": "fc97ba3c-6c32-4f4c-a986-8d7f4f5c7f80", @@ -1603,7 +1603,7 @@ "activityTaskScheduledEventAttributes": { "activityId": "12", "activityType": { - "name": "invoke_model_activity" + "name": "invoke_model" }, "taskQueue": { "name": "fc97ba3c-6c32-4f4c-a986-8d7f4f5c7f80", diff --git a/tests/contrib/openai_agents/histories/tools-workflow-history.json b/tests/contrib/openai_agents/histories/tools-workflow-history.json index 66304d61e..d7b925857 100644 --- a/tests/contrib/openai_agents/histories/tools-workflow-history.json +++ b/tests/contrib/openai_agents/histories/tools-workflow-history.json @@ -96,7 +96,7 @@ "activityTaskScheduledEventAttributes": { "activityId": "1", "activityType": { - "name": "invoke_model_activity" + "name": "invoke_model" }, "taskQueue": { "name": "98bba13c-e75a-446d-a2f8-077680fb23af", @@ -362,7 +362,7 @@ "activityTaskScheduledEventAttributes": { "activityId": "3", "activityType": { - "name": "invoke_model_activity" + "name": "invoke_model" }, "taskQueue": { "name": "98bba13c-e75a-446d-a2f8-077680fb23af",