Agents cannot resume workflows
Title says it all: here is a failing test I would expect to work:
I know this may be a feature for later, but it would be really nice if agents could do this.
...
const inputSchema = z.object({
text: z.string().describe('Just put in some random text to process.'),
});
const outputSchema = z.object({
text: z.string(),
});
const resumeSchema = z.object({
userAnswer: z.string(),
});
const exampleStep = createStep({
id: 'exampleStep',
description: 'Example step',
inputSchema,
outputSchema,
resumeSchema,
execute: async ({ suspend, resumeData }) => {
console.log('exampleStep called');
if (!resumeData) {
return await suspend({
question: 'What is your name?',
});
}
console.log('exampleStep resumed');
return {
text: `Tell the user: "Hi ${resumeData.userAnswer}", the test was succesful!`,
};
},
});
const exampleWorkflow = createWorkflow({
id: 'exampleWorkflow',
description: 'Example workflow',
inputSchema,
outputSchema,
})
.then(exampleStep)
.commit();
describe('resume', () => {
it('should be able to resume a workflow', { timeout: 10_000 }, async () => {
const myAgent = new Agent({
name: 'myAgent',
description: 'My agent',
instructions: 'Follow and do whatever the user says. You can also ask the user for information if needed.',
model: openai('gpt-4o'),
workflows: {
[exampleWorkflow.id]: exampleWorkflow,
},
memory: new Memory({
storage: new LibSQLStore({
url: ':memory:',
}),
}),
});
const result1 = await myAgent.generate('Start or resume the workflow.', {
memory: {
thread: 'user-123',
resource: 'test-123',
},
});
const result2 = await myAgent.generate('My name is John Doe!', {
memory: {
thread: 'user-123',
resource: 'test-123',
},
});
expect(result2.text).toContain('Hi John Doe');
});
});...
const inputSchema = z.object({
text: z.string().describe('Just put in some random text to process.'),
});
const outputSchema = z.object({
text: z.string(),
});
const resumeSchema = z.object({
userAnswer: z.string(),
});
const exampleStep = createStep({
id: 'exampleStep',
description: 'Example step',
inputSchema,
outputSchema,
resumeSchema,
execute: async ({ suspend, resumeData }) => {
console.log('exampleStep called');
if (!resumeData) {
return await suspend({
question: 'What is your name?',
});
}
console.log('exampleStep resumed');
return {
text: `Tell the user: "Hi ${resumeData.userAnswer}", the test was succesful!`,
};
},
});
const exampleWorkflow = createWorkflow({
id: 'exampleWorkflow',
description: 'Example workflow',
inputSchema,
outputSchema,
})
.then(exampleStep)
.commit();
describe('resume', () => {
it('should be able to resume a workflow', { timeout: 10_000 }, async () => {
const myAgent = new Agent({
name: 'myAgent',
description: 'My agent',
instructions: 'Follow and do whatever the user says. You can also ask the user for information if needed.',
model: openai('gpt-4o'),
workflows: {
[exampleWorkflow.id]: exampleWorkflow,
},
memory: new Memory({
storage: new LibSQLStore({
url: ':memory:',
}),
}),
});
const result1 = await myAgent.generate('Start or resume the workflow.', {
memory: {
thread: 'user-123',
resource: 'test-123',
},
});
const result2 = await myAgent.generate('My name is John Doe!', {
memory: {
thread: 'user-123',
resource: 'test-123',
},
});
expect(result2.text).toContain('Hi John Doe');
});
});I know this may be a feature for later, but it would be really nice if agents could do this.