#Machine that invokes a machine which invokes an agent breaks
1 messages · Page 1 of 1 (latest)
import { openai } from "@ai-sdk/openai";
import { fromDecision, createAgent } from "@statelyai/agent";
import { createActor, log, setup } from "xstate";
import { z } from "zod";
const techSupportAgent = createAgent({
name: "tech support agent",
model: openai("gpt-4o-mini"),
events: {
response: z.object({
response: z.string().describe("The response to the customer."),
}),
},
});
const techSupportMachine = setup({
actors: {
techSupportAgent: fromDecision(techSupportAgent),
},
}).createMachine({
initial: "agent",
states: {
agent: {
// after: {
// 2000: "end",
// },
invoke: {
src: "techSupportAgent",
input: {
context: "I need to know store locations",
},
},
on: {
response: {
actions: log((x) => \n-AI: \n${x.event.response}),
target: "end",
},
},
},
end: {
type: "final",
},
},
});
const helpDeskAgent = createAgent({
name: "sales agent",
model: openai("gpt-4o-mini"),
events: {
response: z.object({
response: z.string().describe("The response to the customer."),
}),
},
});
const helpDeskMachine = setup({
actors: {
helpDeskAgent: fromDecision(helpDeskAgent),
techSupportMachine,
},
}).createMachine({
initial: "agent",
states: {
agent: {
invoke: {
src: "helpDeskAgent",
input: {
context: "I need to know store locations",
},
},
on: {
response: {
actions: log((x) => \n-AI: \n${x.event.response}),
target: "anotherAgent",
},
},
},
anotherAgent: {
invoke: {
src: "techSupportMachine",
onDone: {
target: "end",
},
},
},
end: {
type: "final",
},
},
});
createActor(helpDeskMachine).start();
Can you report this in https://github.com/statelyai/agent/issues/new?
I'll check locally
Btw, this should be goal not context:
input: {
goal: "I need to know store locations",
},
Made a fix here: https://github.com/statelyai/agent/pull/45