From 7bdd999214bf4c517628d2b6c46e7cfc95918b65 Mon Sep 17 00:00:00 2001 From: John Smith Date: Mon, 16 Dec 2024 08:02:49 +1030 Subject: [PATCH] chore: Add agent result test --- .../modules/workflows/agent/agent.ai.test.ts | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/control-plane/src/modules/workflows/agent/agent.ai.test.ts b/control-plane/src/modules/workflows/agent/agent.ai.test.ts index 01c70920..5cac8d2b 100644 --- a/control-plane/src/modules/workflows/agent/agent.ai.test.ts +++ b/control-plane/src/modules/workflows/agent/agent.ai.test.ts @@ -190,6 +190,56 @@ describe("Agent", () => { }); }); + describe("result schema", () => { + jest.setTimeout(120000); + + it("should result result schema", async () => { + + const app = await createWorkflowAgent({ + workflow: { + ...workflow, + resultSchema: { + type: "object", + properties: { + word: { + type: "string" + } + } + } + }, + findRelevantTools: async () => tools, + getTool: async () => tools[0], + postStepSave: async () => {}, + }); + + const messages = [ + { + type: "human", + data: { + message: "Return the word 'hello'", + }, + }, + ]; + + const outputState = await app.invoke({ + workflow, + messages, + }); + + expect(outputState.messages).toHaveLength(2); + expect(outputState.messages[0]).toHaveProperty("type", "human"); + expect(outputState.messages[1]).toHaveProperty("type", "agent"); + expect(outputState.messages[1].data.result).toHaveProperty( + "word", + "hello", + ); + + expect(outputState.result).toEqual({ + word: "hello" + }); + }); + }); + describe("early exit", () => { jest.setTimeout(120000);