The platform for continuously improving AI agents.
from datetime import timedelta
from temporalio import workflow
from temporalio.common import RetryPolicy
from temporalio.exceptions import ActivityError
TASK_QUEUE = "overmind-workshop-agent"
@workflow.defn
class WorkshopTaskWorkflow:
"""One run of a Workshop task's loop, until the task settles or is paused. A message, a
resume or a cancellation that needs the loop again starts another run."""
@workflow.run
async def run(self, task: str) -> dict:
while True:
try:
result = await workflow.execute_activity(
"supervise_run",
task,
start_to_close_timeout=timedelta(days=1),
heartbeat_timeout=timedelta(seconds=30),
retry_policy=RetryPolicy(
initial_interval=timedelta(seconds=5), maximum_attempts=3
),
)
except ActivityError:
result = await workflow.execute_activity(
"fence_run", task, start_to_close_timeout=timedelta(seconds=30)
)
if not result.get("settlement_pending"):
return result
await workflow.sleep(timedelta(seconds=30))
if workflow.info().is_continue_as_new_suggested():
workflow.continue_as_new(task)