Skip to content

Commit a972cf6

Browse files
desertaxleDouweM
andauthored
Correct Prefect .serve example (#3192)
Co-authored-by: Douwe Maan <[email protected]>
1 parent d8265a0 commit a972cf6

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

docs/durable_execution/prefect.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,20 +255,23 @@ from prefect import flow
255255
from pydantic_ai import Agent
256256
from pydantic_ai.durable_exec.prefect import PrefectAgent
257257

258-
agent = Agent(
259-
'openai:gpt-4o',
260-
name='daily_report_agent',
261-
instructions='Generate a daily summary report.',
262-
)
263-
264-
prefect_agent = PrefectAgent(agent)
265258

266259
@flow
267260
async def daily_report_flow(user_prompt: str):
268261
"""Generate a daily report using the agent."""
262+
agent = Agent( # (1)!
263+
'openai:gpt-4o',
264+
name='daily_report_agent',
265+
instructions='Generate a daily summary report.',
266+
)
267+
268+
prefect_agent = PrefectAgent(agent)
269+
269270
result = await prefect_agent.run(user_prompt)
270271
return result.output
271272

273+
274+
272275
# Serve the flow with a daily schedule
273276
if __name__ == '__main__':
274277
daily_report_flow.serve(
@@ -279,6 +282,8 @@ if __name__ == '__main__':
279282
)
280283
```
281284

285+
1. Each flow run executes in an isolated process, and all inputs and dependencies must be serializable. Because Agent instances cannot be serialized, instantiate the agent inside the flow rather than at the module level.
286+
282287
The `serve()` method accepts scheduling options:
283288

284289
- **`cron`**: Cron schedule string (e.g., `'0 9 * * *'` for daily at 9am)

0 commit comments

Comments
 (0)