Skip to content

Commit 6335294

Browse files
committed
Use a simpler pattern.
1 parent ce995d6 commit 6335294

File tree

20 files changed

+94
-278
lines changed

20 files changed

+94
-278
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,3 @@ __pypackages__/
107107
# Keep lockfiles tracked in this repo (uv.lock is committed), so do NOT ignore them.
108108
# uv: no special ignores required beyond virtualenvs above
109109

110-
config.toml

agents/openai_agents_sdk_python/README.md

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ We configure the Temporal client with the `OpenAIAgentsPlugin` to enable OpenAI
9696
```python
9797
import asyncio
9898
from datetime import timedelta
99-
from pathlib import Path
10099

101100
from temporalio.client import Client
102101
from temporalio.worker import Worker
@@ -108,15 +107,10 @@ from activities.tools import get_weather, calculate_circle_area
108107

109108
async def worker_main():
110109
# Use the plugin to configure Temporal for use with OpenAI Agents SDK
111-
config_dir = Path(__file__).parent.parent.parent
112-
config_file = config_dir / "config.toml"
113-
if not config_file.exists():
114-
config_file = config_dir / "config.toml.example"
115-
connect_config = ClientConfig.load_client_connect_config(
116-
config_file=str(config_file)
117-
)
110+
config = ClientConfig.load_client_connect_config()
111+
config.setdefault("target_host", "localhost:7233")
118112
client = await Client.connect(
119-
**connect_config,
113+
**config,
120114
plugins=[
121115
OpenAIAgentsPlugin(
122116
model_params=ModelActivityParameters(
@@ -147,7 +141,6 @@ It uses the `OpenAIAgentsPlugin` to match the Worker configuration.
147141

148142
```python
149143
import asyncio
150-
from pathlib import Path
151144

152145
from temporalio.client import Client
153146
from temporalio.envconfig import ClientConfig
@@ -156,15 +149,10 @@ from temporalio.contrib.openai_agents import OpenAIAgentsPlugin
156149
from workflows.hello_world_workflow import HelloWorldAgent
157150

158151
async def main():
159-
config_dir = Path(__file__).parent.parent.parent
160-
config_file = config_dir / "config.toml"
161-
if not config_file.exists():
162-
config_file = config_dir / "config.toml.example"
163-
connect_config = ClientConfig.load_client_connect_config(
164-
config_file=str(config_file)
165-
)
152+
config = ClientConfig.load_client_connect_config()
153+
config.setdefault("target_host", "localhost:7233")
166154
client = await Client.connect(
167-
**connect_config,
155+
**config,
168156
# Use the plugin to configure Temporal for use with OpenAI Agents SDK
169157
plugins=[OpenAIAgentsPlugin()],
170158
)
@@ -197,24 +185,19 @@ if __name__ == "__main__":
197185

198186
This recipe uses Temporal's environment configuration system to connect to Temporal. By default, it connects to a local Temporal server. To use Temporal Cloud:
199187

200-
1. Copy the example configuration file from the ai-cookbook root:
188+
1. Set the `TEMPORAL_PROFILE` environment variable to use the cloud profile:
201189
```bash
202-
cp ../../config.toml.example ../../config.toml
190+
export TEMPORAL_PROFILE=cloud
203191
```
204192

205-
2. Edit `config.toml` in the ai-cookbook root and update the `[profile.cloud]` section with your Temporal Cloud credentials:
206-
- Set `address` to your Temporal Cloud namespace address
207-
- Set `namespace` to your namespace name
208-
- For authentication, choose one of:
209-
- Set `api_key` to your Temporal Cloud API key, or
210-
- Set `client_cert_path` and `client_key_path` in the `[profile.cloud.tls]` section to use TLS certificates
211-
212-
3. Set the `TEMPORAL_PROFILE` environment variable to use the cloud profile:
193+
2. Configure the cloud profile using the Temporal CLI:
213194
```bash
214-
export TEMPORAL_PROFILE=cloud
195+
temporal config set --profile cloud --prop address --value "CLOUD_REMOTE_ADDRESS"
196+
temporal config set --profile cloud --prop namespace --value "CLOUD_NAMESPACE"
197+
temporal config set --profile cloud --prop api_key --value "CLOUD_API_KEY"
215198
```
216199

217-
The code will automatically use `config.toml` if it exists, otherwise it falls back to `config.toml.example`.
200+
For TLS certificate authentication instead of API key, refer to the [Temporal environment configuration documentation](https://docs.temporal.io/develop/environment-configuration) for details.
218201

219202
## Running
220203

agents/openai_agents_sdk_python/start_workflow.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import asyncio
2-
from pathlib import Path
32

43
from temporalio.client import Client
54
from temporalio.envconfig import ClientConfig
@@ -9,15 +8,10 @@
98
from workflows.hello_world_workflow import HelloWorldAgent
109

1110
async def main():
12-
config_dir = Path(__file__).parent.parent.parent
13-
config_file = config_dir / "config.toml"
14-
if not config_file.exists():
15-
config_file = config_dir / "config.toml.example"
16-
connect_config = ClientConfig.load_client_connect_config(
17-
config_file=str(config_file)
18-
)
11+
config = ClientConfig.load_client_connect_config()
12+
config.setdefault("target_host", "localhost:7233")
1913
client = await Client.connect(
20-
**connect_config,
14+
**config,
2115
# Use the plugin to configure Temporal for use with OpenAI Agents SDK
2216
plugins=[OpenAIAgentsPlugin()],
2317
)

agents/openai_agents_sdk_python/worker.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import asyncio
22
from datetime import timedelta
3-
from pathlib import Path
43

54
from temporalio.client import Client
65
from temporalio.worker import Worker
@@ -14,15 +13,10 @@
1413

1514
async def worker_main():
1615
# Use the plugin to configure Temporal for use with OpenAI Agents SDK
17-
config_dir = Path(__file__).parent.parent.parent
18-
config_file = config_dir / "config.toml"
19-
if not config_file.exists():
20-
config_file = config_dir / "config.toml.example"
21-
connect_config = ClientConfig.load_client_connect_config(
22-
config_file=str(config_file)
23-
)
16+
config = ClientConfig.load_client_connect_config()
17+
config.setdefault("target_host", "localhost:7233")
2418
client = await Client.connect(
25-
**connect_config,
19+
**config,
2620
plugins=[
2721
OpenAIAgentsPlugin(
2822
model_params=ModelActivityParameters(

agents/tool_call_openai_python/README.md

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ The worker is the process that dispatches work to the various parts of the agent
243243

244244
```python
245245
import asyncio
246-
from pathlib import Path
247246

248247
from temporalio.client import Client
249248
from temporalio.worker import Worker
@@ -255,17 +254,10 @@ from temporalio.contrib.pydantic import pydantic_data_converter
255254

256255

257256
async def main():
258-
config_dir = Path(__file__).parent.parent.parent
259-
config_file = config_dir / "config.toml"
260-
if not config_file.exists():
261-
config_file = config_dir / "config.toml.example"
262-
profile = os.environ.get("TEMPORAL_PROFILE", "default")
263-
connect_config = ClientConfig.load_client_connect_config(
264-
profile=profile,
265-
config_file=str(config_file)
266-
)
257+
config = ClientConfig.load_client_connect_config()
258+
config.setdefault("target_host", "localhost:7233")
267259
client = await Client.connect(
268-
**connect_config,
260+
**config,
269261
data_converter=pydantic_data_converter,
270262
)
271263

@@ -295,7 +287,6 @@ In order to interact with this simple AI agent, we create a Temporal client and
295287
```python
296288
import asyncio
297289
import sys
298-
from pathlib import Path
299290

300291
from temporalio.client import Client
301292
from temporalio.envconfig import ClientConfig
@@ -305,17 +296,10 @@ from temporalio.contrib.pydantic import pydantic_data_converter
305296

306297

307298
async def main():
308-
config_dir = Path(__file__).parent.parent.parent
309-
config_file = config_dir / "config.toml"
310-
if not config_file.exists():
311-
config_file = config_dir / "config.toml.example"
312-
profile = os.environ.get("TEMPORAL_PROFILE", "default")
313-
connect_config = ClientConfig.load_client_connect_config(
314-
profile=profile,
315-
config_file=str(config_file)
316-
)
299+
config = ClientConfig.load_client_connect_config()
300+
config.setdefault("target_host", "localhost:7233")
317301
client = await Client.connect(
318-
**connect_config,
302+
**config,
319303
data_converter=pydantic_data_converter,
320304
)
321305

@@ -339,24 +323,19 @@ if __name__ == "__main__":
339323

340324
This recipe uses Temporal's environment configuration system to connect to Temporal. By default, it connects to a local Temporal server. To use Temporal Cloud:
341325

342-
1. Copy the example configuration file from the ai-cookbook root:
326+
1. Set the `TEMPORAL_PROFILE` environment variable to use the cloud profile:
343327
```bash
344-
cp ../../config.toml.example ../../config.toml
328+
export TEMPORAL_PROFILE=cloud
345329
```
346330

347-
2. Edit `config.toml` in the ai-cookbook root and update the `[profile.cloud]` section with your Temporal Cloud credentials:
348-
- Set `address` to your Temporal Cloud namespace address
349-
- Set `namespace` to your namespace name
350-
- For authentication, choose one of:
351-
- Set `api_key` to your Temporal Cloud API key, or
352-
- Set `client_cert_path` and `client_key_path` in the `[profile.cloud.tls]` section to use TLS certificates
353-
354-
3. Set the `TEMPORAL_PROFILE` environment variable to use the cloud profile:
331+
2. Configure the cloud profile using the Temporal CLI:
355332
```bash
356-
export TEMPORAL_PROFILE=cloud
333+
temporal config set --profile cloud --prop address --value "CLOUD_REMOTE_ADDRESS"
334+
temporal config set --profile cloud --prop namespace --value "CLOUD_NAMESPACE"
335+
temporal config set --profile cloud --prop api_key --value "CLOUD_API_KEY"
357336
```
358337

359-
The code will automatically use `config.toml` if it exists, otherwise it falls back to `config.toml.example`.
338+
For TLS certificate authentication instead of API key, refer to the [Temporal environment configuration documentation](https://docs.temporal.io/develop/environment-configuration) for details.
360339

361340
## Running
362341

agents/tool_call_openai_python/start_workflow.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import asyncio
22
import sys
3-
from pathlib import Path
43

54
from temporalio.client import Client
65
from temporalio.envconfig import ClientConfig
@@ -10,15 +9,10 @@
109

1110

1211
async def main():
13-
config_dir = Path(__file__).parent.parent.parent
14-
config_file = config_dir / "config.toml"
15-
if not config_file.exists():
16-
config_file = config_dir / "config.toml.example"
17-
connect_config = ClientConfig.load_client_connect_config(
18-
config_file=str(config_file)
19-
)
12+
config = ClientConfig.load_client_connect_config()
13+
config.setdefault("target_host", "localhost:7233")
2014
client = await Client.connect(
21-
**connect_config,
15+
**config,
2216
data_converter=pydantic_data_converter,
2317
)
2418

agents/tool_call_openai_python/worker.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import asyncio
2-
from pathlib import Path
32

43
from temporalio.client import Client
54
from temporalio.worker import Worker
@@ -11,15 +10,10 @@
1110

1211

1312
async def main():
14-
config_dir = Path(__file__).parent.parent.parent
15-
config_file = config_dir / "config.toml"
16-
if not config_file.exists():
17-
config_file = config_dir / "config.toml.example"
18-
connect_config = ClientConfig.load_client_connect_config(
19-
config_file=str(config_file)
20-
)
13+
config = ClientConfig.load_client_connect_config()
14+
config.setdefault("target_host", "localhost:7233")
2115
client = await Client.connect(
22-
**connect_config,
16+
**config,
2317
data_converter=pydantic_data_converter,
2418
)
2519

config.toml.example

Lines changed: 0 additions & 26 deletions
This file was deleted.

deep_research/basic_openai_python/start_workflow.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import uuid
44
import os
55
from datetime import datetime
6-
from pathlib import Path
76

87
from temporalio.client import Client
98
from temporalio.envconfig import ClientConfig
@@ -14,17 +13,10 @@
1413

1514
async def main():
1615
# Connect to Temporal server with matching data converter
17-
config_dir = Path(__file__).parent.parent.parent
18-
config_file = config_dir / "config.toml"
19-
if not config_file.exists():
20-
config_file = config_dir / "config.toml.example"
21-
profile = os.environ.get("TEMPORAL_PROFILE", "default")
22-
connect_config = ClientConfig.load_client_connect_config(
23-
profile=profile,
24-
config_file=str(config_file)
25-
)
16+
config = ClientConfig.load_client_connect_config()
17+
config.setdefault("target_host", "localhost:7233")
2618
client = await Client.connect(
27-
**connect_config,
19+
**config,
2820
data_converter=pydantic_data_converter,
2921
)
3022

deep_research/basic_openai_python/worker.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import asyncio
2-
from pathlib import Path
32

43
from temporalio.client import Client
54
from temporalio.worker import Worker
@@ -12,15 +11,10 @@
1211

1312
async def main():
1413
# Connect to Temporal server with pydantic data converter for our data classes
15-
config_dir = Path(__file__).parent.parent.parent
16-
config_file = config_dir / "config.toml"
17-
if not config_file.exists():
18-
config_file = config_dir / "config.toml.example"
19-
connect_config = ClientConfig.load_client_connect_config(
20-
config_file=str(config_file)
21-
)
14+
config = ClientConfig.load_client_connect_config()
15+
config.setdefault("target_host", "localhost:7233")
2216
client = await Client.connect(
23-
**connect_config,
17+
**config,
2418
data_converter=pydantic_data_converter,
2519
)
2620

0 commit comments

Comments
 (0)