|
3 | 3 | from temporalio.client import Client, Plugin as ClientPlugin |
4 | 4 | from temporalio.runtime import Runtime, TelemetryConfig, OpenTelemetryConfig |
5 | 5 | from temporalio.contrib.pydantic import pydantic_data_converter |
| 6 | +from temporalio.contrib.openai_agents import OpenAIAgentsPlugin |
6 | 7 |
|
7 | 8 | # class DateTimeJSONEncoder(AdvancedJSONEncoder): |
8 | 9 | # def default(self, o: Any) -> Any: |
@@ -74,20 +75,24 @@ async def get_temporal_client(temporal_address: str, metrics_url: str | None = N |
74 | 75 | if plugins: |
75 | 76 | validate_client_plugins(plugins) |
76 | 77 |
|
| 78 | + # Check if OpenAI plugin is present - it needs to configure its own data converter |
| 79 | + has_openai_plugin = any( |
| 80 | + isinstance(p, OpenAIAgentsPlugin) for p in (plugins or []) |
| 81 | + ) |
| 82 | + |
| 83 | + # Only set data_converter if OpenAI plugin is not present |
| 84 | + connect_kwargs = { |
| 85 | + "target_host": temporal_address, |
| 86 | + "plugins": plugins, |
| 87 | + } |
| 88 | + |
| 89 | + if not has_openai_plugin: |
| 90 | + connect_kwargs["data_converter"] = pydantic_data_converter |
| 91 | + |
77 | 92 | if not metrics_url: |
78 | | - client = await Client.connect( |
79 | | - target_host=temporal_address, |
80 | | - # data_converter=custom_data_converter, |
81 | | - data_converter=pydantic_data_converter, |
82 | | - plugins=plugins, |
83 | | - ) |
| 93 | + client = await Client.connect(**connect_kwargs) |
84 | 94 | else: |
85 | 95 | runtime = Runtime(telemetry=TelemetryConfig(metrics=OpenTelemetryConfig(url=metrics_url))) |
86 | | - client = await Client.connect( |
87 | | - target_host=temporal_address, |
88 | | - # data_converter=custom_data_converter, |
89 | | - data_converter=pydantic_data_converter, |
90 | | - runtime=runtime, |
91 | | - plugins=plugins, |
92 | | - ) |
| 96 | + connect_kwargs["runtime"] = runtime |
| 97 | + client = await Client.connect(**connect_kwargs) |
93 | 98 | return client |
0 commit comments