M
Mastraโ€ข2mo ago
ewald

Resume to a suspended Workflow run

I am trying to return to a suspended workflow run using workflow.createRunAsync({runId: ... }) and I see in the method that it is looking inside the run-map if the run already exists and than looks it up in the snapshot storage but never returns this data, but instead the one in the process run-map. Why is that? I want to resume to my workflow but this way it always creates a new pending one if i am not in the same instance of this workflow class. Like if I have two different requests. How would i approach this? โ€“ Like have a first API call that is starting the workflow and is causing a suspend and second request is continuing the same workflow using the latest workflow run with the specific runId. Help is appreciated ๐Ÿ™‚ thank u!
GitHub
mastra/packages/core/src/workflows/workflow.ts at c710c1652dccfdc41...
The TypeScript AI agent framework. โšก Assistants, RAG, observability. Supports any LLM: GPT-4, Claude, Gemini, Llama. - mastra-ai/mastra
4 Replies
Mastra Triager
Mastra Triagerโ€ข2mo ago
๐Ÿ“ Created GitHub issue: https://github.com/mastra-ai/mastra/issues/9441
GitHub
[DISCORD:1432982149681778698] Resume to a suspended Workflow run ยท...
This issue was created from Discord post: https://discord.com/channels/1309558646228779139/1432982149681778698 I am trying to return to a suspended workflow run using workflow.createRunAsync({runId...
_roamin_
_roamin_โ€ข2mo ago
Hi @ewald ! Could you share the code you're using to first start the workflow, and then resume it? Thanks
ewald
ewaldOPโ€ข2mo ago
Sure it is smth like this, I never had a a working state but thats my idea of it:
const run = await workflow.createRunAsync({
runId: chatSessionId,
resourceId: user.id
})

if (run.workflowRunStatus === 'suspended') {
const resume = await run.resume({
step: workflow.name,
resumeData: {
answer: message
}
})

if (resume.status === 'suspended') {
// ... return suspend response payload
} else if (resume.status === 'success') {
return {
isBot: true,
text: resume.result.answer,
createdAt: new Date().toISOString()
}
} else {
// ... handle other statuses
}
}

const runWorkflow = await run.start({
inputData: { topic: message },
runtimeContext
})

if (runWorkflow.status === 'success') {
return {
isBot: true,
text: runWorkflow.result.answer,
createdAt: new Date().toISOString()
}
} else {
// ... handle other statuses
}
const run = await workflow.createRunAsync({
runId: chatSessionId,
resourceId: user.id
})

if (run.workflowRunStatus === 'suspended') {
const resume = await run.resume({
step: workflow.name,
resumeData: {
answer: message
}
})

if (resume.status === 'suspended') {
// ... return suspend response payload
} else if (resume.status === 'success') {
return {
isBot: true,
text: resume.result.answer,
createdAt: new Date().toISOString()
}
} else {
// ... handle other statuses
}
}

const runWorkflow = await run.start({
inputData: { topic: message },
runtimeContext
})

if (runWorkflow.status === 'success') {
return {
isBot: true,
text: runWorkflow.result.answer,
createdAt: new Date().toISOString()
}
} else {
// ... handle other statuses
}
So this happens on an API endpoint which calls a workflow. But run.workflowRunStatus might be stale when I call it in the next request.
_roamin_
_roamin_โ€ข2mo ago
I see, try removing the step option when you call resume
const resume = await run.resume({
resumeData: {
answer: message
}
})
const resume = await run.resume({
resumeData: {
answer: message
}
})

Did you find this page helpful?