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
content=f"Hello! I've received your task. Normally you can do some state initialization here, or just pass and do nothing until you get your first event. For now I'm just acknowledging that I've received a task with the following params:\n\n{json.dumps(params.params, indent=2)}.\n\nYou should only see this message once, when the task is created. All subsequent events will be handled by the `on_task_event_send` handler.",
62
-
),
63
-
)
56
+
# 1. Acknowledge that the task has been created. Gate this one-time prologue
57
+
# on is_continued_run(): run_until_complete below recycles the workflow via
58
+
# continue-as-new, which re-enters on_task_create from the top — without this
59
+
# guard the "you should only see this once" welcome would re-fire on every
60
+
# recycle. Original run -> emit; continued (recycled) run -> skip.
61
+
ifnotself.is_continued_run():
62
+
awaitadk.messages.create(
63
+
task_id=params.task.id,
64
+
content=TextContent(
65
+
author="agent",
66
+
content=f"Hello! I've received your task. Normally you can do some state initialization here, or just pass and do nothing until you get your first event. For now I'm just acknowledging that I've received a task with the following params:\n\n{json.dumps(params.params, indent=2)}.\n\nYou should only see this message once, when the task is created. All subsequent events will be handled by the `on_task_event_send` handler.",
67
+
),
68
+
)
64
69
65
-
# 2. Wait for the task to be completed indefinitely. If we don't do this the workflow will close as soon as this function returns. Temporal can run hundreds of millions of workflows in parallel, so you don't need to worry about too many workflows running at once.
66
-
67
-
# Thus, if you want this agent to field events indefinitely (or for a long time) you need to wait for a condition to be met.
68
-
awaitworkflow.wait_condition(
69
-
lambda: self._complete_task,
70
-
timeout=None, # Set a timeout if you want to prevent the task from running indefinitely. Generally this is not needed. Temporal can run hundreds of millions of workflows in parallel and more. Only do this if you have a specific reason to do so.
71
-
)
70
+
# 2. Keep the workflow open to field events. We use run_until_complete
71
+
# instead of a bare wait_condition: it still waits indefinitely, but also
72
+
# recycles the Temporal event history via continue-as-new before it hits the
73
+
# ~50k-event / 50MB limit, so this chat can stay open forever. Adopting
74
+
# run_until_complete IS the opt-in — agents that keep the old wait_condition
75
+
# never recycle. This agent keeps no cross-turn state, so nothing needs
76
+
# restoring across a recycle and `params` is the only carry-forward. (Agents
77
+
# that DO keep state restore it at the top of @workflow.run on a recycled
78
+
# run — framework-specific, landing per-integration in follow-up PRs.)
0 commit comments