From 1aff5aadcbf57c1c580977ab7af9c9e25aaddf33 Mon Sep 17 00:00:00 2001 From: jacoblee93 Date: Tue, 27 Aug 2024 09:22:59 -0700 Subject: [PATCH] Fix test --- .../src/prebuilt/chat_agent_executor.ts | 8 ++--- libs/langgraph/src/tests/prebuilt.test.ts | 35 ++++++++++++++----- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/libs/langgraph/src/prebuilt/chat_agent_executor.ts b/libs/langgraph/src/prebuilt/chat_agent_executor.ts index ac69db5e..861d7f68 100644 --- a/libs/langgraph/src/prebuilt/chat_agent_executor.ts +++ b/libs/langgraph/src/prebuilt/chat_agent_executor.ts @@ -13,12 +13,12 @@ import { StateGraph, StateGraphArgs, } from "../graph/state.js"; -import { END, START, messagesStateReducer } from "../graph/index.js"; +import { END, START } from "../graph/index.js"; -/** @ignore */ +/** @deprecated Use {@link createReactAgent} instead with tool calling. */ export type FunctionCallingExecutorState = { messages: Array }; -/** @ignore */ +/** @deprecated Use {@link createReactAgent} instead with tool calling. */ export function createFunctionCallingExecutor({ model, tools, @@ -124,7 +124,7 @@ export function createFunctionCallingExecutor({ // So we annotate the messages attribute with operator.add const schema: StateGraphArgs["channels"] = { messages: { - value: messagesStateReducer, + value: (x: BaseMessage[], y: BaseMessage[]) => x.concat(y), default: () => [], }, }; diff --git a/libs/langgraph/src/tests/prebuilt.test.ts b/libs/langgraph/src/tests/prebuilt.test.ts index c38d1309..ccfd3cd9 100644 --- a/libs/langgraph/src/tests/prebuilt.test.ts +++ b/libs/langgraph/src/tests/prebuilt.test.ts @@ -1,4 +1,5 @@ /* eslint-disable no-process-env */ +/* eslint-disable no-param-reassign */ import { beforeAll, describe, expect, it } from "@jest/globals"; import { PromptTemplate } from "@langchain/core/prompts"; import { StructuredTool, Tool } from "@langchain/core/tools"; @@ -275,7 +276,7 @@ describe("createReactAgent", () => { messages: [new HumanMessage("Hello Input!")], }); - expect(result.messages).toEqual([ + const expected = [ new HumanMessage("Hello Input!"), new AIMessage({ content: "result1", @@ -287,9 +288,14 @@ describe("createReactAgent", () => { name: "search_api", content: "result for foo", tool_call_id: "tool_abcd123", + artifact: undefined, }), new AIMessage("result2"), - ]); + ].map((message, i) => { + message.id = result.messages[i].id; + return message; + }); + expect(result.messages).toEqual(expected); }); it("Can use SystemMessage message modifier", async () => { @@ -314,7 +320,7 @@ describe("createReactAgent", () => { const result = await agent.invoke({ messages: [], }); - expect(result.messages).toEqual([ + const expected = [ new AIMessage({ content: "result1", tool_calls: [ @@ -325,9 +331,14 @@ describe("createReactAgent", () => { name: "search_api", content: "result for foo", tool_call_id: "tool_abcd123", + artifact: undefined, }), new AIMessage("result2"), - ]); + ].map((message, i) => { + message.id = result.messages[i].id; + return message; + }); + expect(result.messages).toEqual(expected); }); it("Should respect a passed signal", async () => { @@ -389,7 +400,7 @@ describe("createReactAgent", () => { messages: [new HumanMessage("Hello Input!")], }); - expect(result.messages).toEqual([ + const expected = [ new HumanMessage("Hello Input!"), new AIMessage({ content: "result1", @@ -404,7 +415,11 @@ describe("createReactAgent", () => { artifact: Buffer.from("123"), }), new AIMessage("result2"), - ]); + ].map((message, i) => { + message.id = result.messages[i].id; + return message; + }); + expect(result.messages).toEqual(expected); }); it("Can accept RunnableToolLike", async () => { @@ -442,7 +457,7 @@ describe("createReactAgent", () => { messages: [new HumanMessage("Hello Input!")], }); - expect(result.messages).toEqual([ + const expected = [ new HumanMessage("Hello Input!"), new AIMessage({ content: "result1", @@ -456,7 +471,11 @@ describe("createReactAgent", () => { tool_call_id: "tool_abcd123", }), new AIMessage("result2"), - ]); + ].map((message, i) => { + message.id = result.messages[i].id; + return message; + }); + expect(result.messages).toEqual(expected); }); });