Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions dapr_agents/workflow/runners/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,9 @@ def _mount_service_routes(
if entry_path not in self._default_http_paths:
self._default_http_paths.add(entry_path)

async def _start_workflow(body: dict = Body(default_factory=dict)) -> dict:
async def _start_workflow(
body: dict[str, str] = Body(default_factory=dict),
) -> dict[str, str]:
payload = body or None
instance_id = await self.run(
agent,
Expand All @@ -536,17 +538,46 @@ async def _start_workflow(body: dict = Body(default_factory=dict)) -> dict:
log=True,
)
return {
"instance_id": instance_id,
"status_url": f"/v1.0/workflows/{workflow_component}/{instance_id}",
"instance_id": instance_id if instance_id else "",
"status_url": f"/run/{instance_id if instance_id else ''}",
}

async def _terminate_workflow(instance_id: str) -> dict[str, str]:
await asyncio.to_thread(
self._wf_client.terminate_workflow,
instance_id,
output="Terminated by user request",
)
return {"instance_id": instance_id, "status": "terminated"}

async def _purge_workflow(instance_id: str) -> dict[str, str]:
self._wf_client.purge_workflow(
instance_id=instance_id,
)
return {"instance_id": instance_id, "status": "purged"}

fastapi_app.add_api_route(
entry_path,
_start_workflow,
methods=["POST"],
summary="Schedule workflow entry",
tags=["workflow"],
)
fastapi_app.add_api_route(
entry_path + "/{instance_id}/terminate",
_terminate_workflow,
methods=["POST"],
summary="Terminate workflow instance",
tags=["workflow"],
)
fastapi_app.add_api_route(
entry_path + "/{instance_id}/purge",
_purge_workflow,
methods=["POST"],
summary="Purge workflow instance",
tags=["workflow"],
)

logger.info("Mounted default workflow entry endpoint at %s", entry_path)
else:
logger.debug("Workflow entry endpoint already mounted at %s", entry_path)
Expand Down