You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
dapr run --app-id myapp --dapr-http-port 3500 --dapr-grpc-port 50001 --resources-path ./components
166
+
167
+
# Terminal 2: Run your application (in a separate terminal)
168
+
python example.py
140
169
```
141
170
142
171
**What's happening here?**
@@ -145,6 +174,12 @@ await session.close()
145
174
3. The agent can retrieve previous messages across multiple turns
146
175
4. When you scale to multiple instances, all instances share the same session state
147
176
177
+
**Want a more complete example?** See [`examples/memory/dapr_session_example.py`](https://github.com/openai/openai-agents-python/blob/main/examples/memory/dapr_session_example.py) which demonstrates:
178
+
- Multi-turn conversations with context
179
+
- Session isolation and multi-tenancy
180
+
- TTL and consistency levels
181
+
- All with detailed output and comments
182
+
148
183
## Usage patterns
149
184
150
185
### Dapr ports
@@ -155,17 +190,20 @@ The `DaprSession` communicates with the Dapr sidecar using network ports. Dapr e
155
190
- **HTTP port: 3500** - For REST API and health checks
156
191
- **Metrics port: 9090** - For Prometheus metrics (monitoring)
157
192
158
-
When starting the Dapr sidecar, you can specify custom ports if needed:
193
+
When starting the Dapr sidecar, explicitly specify both ports to avoid connection issues:
159
194
160
195
```bash
161
196
# Using default ports (recommended)
162
-
dapr run --app-id myapp --components-path ./components
197
+
dapr run --app-id myapp \
198
+
--dapr-http-port 3500 \
199
+
--dapr-grpc-port 50001 \
200
+
--resources-path ./components
163
201
164
-
# Using custom ports
202
+
# Using custom ports (in case of conflicts with other services)
165
203
dapr run --app-id myapp \
166
-
--dapr-grpc-port 50002 \
167
204
--dapr-http-port 3501 \
168
-
--components-path ./components
205
+
--dapr-grpc-port 50002 \
206
+
--resources-path ./components
169
207
```
170
208
171
209
If using custom ports, specify them in your session connection:
@@ -556,9 +594,27 @@ else:
556
594
```
557
595
558
596
Common issues:
597
+
598
+
**Health check connection refused (port 3500)**:
599
+
- **Cause**: The `--dapr-http-port` was not specified, so Dapr used a random port
600
+
- **Solution 1**: Always explicitly set `--dapr-http-port 3500` when starting Dapr (recommended)
601
+
- **Solution 2**: Set the HTTP endpoint via environment variable before creating the session:
# Option B: Set just the port (SDK will construct http://localhost:PORT)
608
+
os.environ["DAPR_HTTP_PORT"] = "3500"
609
+
610
+
# Then create your session
611
+
session = DaprSession.from_address(...)
612
+
```
613
+
614
+
**Other issues**:
559
615
- Check that `dapr run` is active (use `dapr list` to see running sidecars)
560
616
- Verify the gRPC port matches (default: 50001)
561
-
- Ensure no firewall blocking the port
617
+
- Ensure no firewall blocking the ports
562
618
- Check that the Dapr sidecar finished initializing (check logs with `dapr logs --app-id myapp`)
563
619
564
620
### Configuration error: State store not found
@@ -570,13 +626,38 @@ Common issues:
570
626
**Solution**: Ensure your component YAML file is in the components directory specified when starting Dapr:
571
627
572
628
```bash
573
-
dapr run --app-id myapp --dapr-grpc-port 50001 --components-path ./components
629
+
dapr run --app-id myapp \
630
+
--dapr-http-port 3500 \
631
+
--dapr-grpc-port 50001 \
632
+
--resources-path ./components
574
633
```
575
634
576
635
### TTL not working
577
636
578
637
Verify your state store [supports TTL](https://docs.dapr.io/reference/components-reference/supported-state-stores/) and is properly configured.
579
638
639
+
### gRPC fork warnings on first API call
640
+
641
+
**Symptom**: You see informational messages like `This process is fork-safe due to gRPC...` on the first OpenAI API call.
642
+
643
+
**Cause**: When `DaprSession` initializes, it creates gRPC background threads. The first OpenAI API call then initializes HTTP worker threads, and gRPC detects this concurrent thread creation and logs safety information.
644
+
645
+
**Impact**: These are informational messages, not errors. They only appear once and don't affect functionality.
646
+
647
+
**Solution** (optional): If you want to suppress these messages, set the gRPC verbosity level before creating the session:
648
+
649
+
```python
650
+
import os
651
+
652
+
# Suppress gRPC informational messages
653
+
os.environ["GRPC_VERBOSITY"] = "ERROR"
654
+
655
+
# Now create your session
656
+
session = DaprSession.from_address(...)
657
+
```
658
+
659
+
**Note**: These warnings are expected when using gRPC-based libraries (like Dapr) alongside other async HTTP libraries. They indicate that gRPC's fork handlers are working correctly to ensure thread safety.
0 commit comments