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
Add migration guide for adapting LangGraph Functional API to Temporal
Documents key changes required:
- Use await instead of .result() for task calls
- Entrypoints must be async functions
- Tasks must be at module level (importable)
- Complete before/after migration example
- Summary table of changes
### Adapting LangGraph Functional API for Temporal
223
+
224
+
When adapting a standard LangGraph functional API graph to run with Temporal, there are a few key changes required:
225
+
226
+
#### 1. Use `await` When Calling Tasks
227
+
228
+
In standard LangGraph, you can call tasks with `.result()`:
229
+
230
+
```python
231
+
# Standard LangGraph (won't work with Temporal)
232
+
@entrypoint()
233
+
defmy_workflow(input: str) -> dict:
234
+
result = my_task(input).result() # ❌ Blocks - not allowed in Temporal
235
+
return {"output": result}
236
+
```
237
+
238
+
With Temporal, you must use `await` because blocking is not allowed in workflows:
239
+
240
+
```python
241
+
# Temporal-compatible
242
+
@entrypoint()
243
+
asyncdefmy_workflow(input: str) -> dict:
244
+
result =await my_task(input) # ✅ Async await
245
+
return {"output": result}
246
+
```
247
+
248
+
#### 2. Entrypoints Must Be Async
249
+
250
+
Since tasks require `await`, your entrypoint function must be `async`:
251
+
252
+
```python
253
+
# Standard LangGraph
254
+
@entrypoint()
255
+
defprocess(data: str) -> dict: # sync function
256
+
...
257
+
258
+
# Temporal-compatible
259
+
@entrypoint()
260
+
asyncdefprocess(data: str) -> dict: # async function
261
+
...
262
+
```
263
+
264
+
#### 3. Tasks Must Be Importable
265
+
266
+
Tasks run as Temporal activities in a separate context. They must be defined at module level (not inside functions or classes) so they can be imported by the worker:
267
+
268
+
```python
269
+
# ✅ Correct - module level
270
+
@task
271
+
defanalyze(text: str) -> str:
272
+
return llm.invoke(text)
273
+
274
+
# ❌ Wrong - can't be imported
275
+
defmake_workflow():
276
+
@task
277
+
defanalyze(text: str) -> str: # Closure - not importable
278
+
return llm.invoke(text)
279
+
```
280
+
281
+
#### 4. Parallel Task Execution
282
+
283
+
Standard LangGraph parallel execution works the same way, just use `await`:
0 commit comments