Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 committed Aug 27, 2024
1 parent 7cd01d1 commit 1aff5aa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
8 changes: 4 additions & 4 deletions libs/langgraph/src/prebuilt/chat_agent_executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<BaseMessage> };

/** @ignore */
/** @deprecated Use {@link createReactAgent} instead with tool calling. */
export function createFunctionCallingExecutor<Model extends object>({
model,
tools,
Expand Down Expand Up @@ -124,7 +124,7 @@ export function createFunctionCallingExecutor<Model extends object>({
// So we annotate the messages attribute with operator.add
const schema: StateGraphArgs<FunctionCallingExecutorState>["channels"] = {
messages: {
value: messagesStateReducer,
value: (x: BaseMessage[], y: BaseMessage[]) => x.concat(y),
default: () => [],
},
};
Expand Down
35 changes: 27 additions & 8 deletions libs/langgraph/src/tests/prebuilt.test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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",
Expand All @@ -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 () => {
Expand All @@ -314,7 +320,7 @@ describe("createReactAgent", () => {
const result = await agent.invoke({
messages: [],
});
expect(result.messages).toEqual([
const expected = [
new AIMessage({
content: "result1",
tool_calls: [
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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",
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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",
Expand All @@ -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);
});
});

Expand Down

0 comments on commit 1aff5aa

Please sign in to comment.