|
14 | 14 | UnsandboxedWorkflowRunner, |
15 | 15 | ) |
16 | 16 | from temporalio.runtime import Runtime, TelemetryConfig, OpenTelemetryConfig |
| 17 | +from temporalio.contrib.openai_agents import OpenAIAgentsPlugin |
17 | 18 | from temporalio.converter import ( |
18 | 19 | DataConverter, |
19 | 20 | JSONTypeConverter, |
@@ -81,18 +82,27 @@ async def get_temporal_client(temporal_address: str, metrics_url: str | None = N |
81 | 82 | if plugins != []: # We don't need to validate the plugins if they are empty |
82 | 83 | _validate_plugins(plugins) |
83 | 84 |
|
| 85 | + # Check if OpenAI plugin is present - it needs to configure its own data converter |
| 86 | + has_openai_plugin = any( |
| 87 | + isinstance(p, OpenAIAgentsPlugin) for p in (plugins or []) |
| 88 | + ) |
| 89 | + |
| 90 | + # Build connection kwargs |
| 91 | + connect_kwargs = { |
| 92 | + "target_host": temporal_address, |
| 93 | + "plugins": plugins, |
| 94 | + } |
| 95 | + |
| 96 | + # Only set data_converter if OpenAI plugin is not present |
| 97 | + if not has_openai_plugin: |
| 98 | + connect_kwargs["data_converter"] = custom_data_converter |
| 99 | + |
84 | 100 | if not metrics_url: |
85 | | - client = await Client.connect( |
86 | | - target_host=temporal_address, data_converter=custom_data_converter, plugins=plugins |
87 | | - ) |
| 101 | + client = await Client.connect(**connect_kwargs) |
88 | 102 | else: |
89 | 103 | runtime = Runtime(telemetry=TelemetryConfig(metrics=OpenTelemetryConfig(url=metrics_url))) |
90 | | - client = await Client.connect( |
91 | | - target_host=temporal_address, |
92 | | - data_converter=custom_data_converter, |
93 | | - runtime=runtime, |
94 | | - plugins=plugins, |
95 | | - ) |
| 104 | + connect_kwargs["runtime"] = runtime |
| 105 | + client = await Client.connect(**connect_kwargs) |
96 | 106 | return client |
97 | 107 |
|
98 | 108 |
|
|
0 commit comments