Skip to content

Commit

Permalink
Merge pull request #1 from langchain-ai/brace/fix-tests
Browse files Browse the repository at this point in the history
Bump deps and fix tests
  • Loading branch information
bracesproul authored Aug 29, 2024
2 parents 93e441c + aa3e7a8 commit 0f55080
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 273 deletions.
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@
"dependencies": {
"@langchain/anthropic": "^0.2.15",
"@langchain/community": "^0.2.31",
"@langchain/core": "^0.2.30",
"@langchain/langgraph": ">=0.1.4-rc2,<0.2.0",
"@langchain/core": "^0.2.31",
"@langchain/langgraph": "^0.1.8",
"langchain": "^0.2.17",
"langsmith": "^0.1.42",
"ts-node": "^10.9.2",
"langsmith": "^0.1.48",
"zod": "^3.23.8"
},
"devDependencies": {
Expand Down
18 changes: 9 additions & 9 deletions src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
ToolMessage,
} from "@langchain/core/messages";
import { StructuredTool, tool } from "@langchain/core/tools";
import { StateGraph } from "@langchain/langgraph";
import { StateGraph, START, END } from "@langchain/langgraph";
import { z } from "zod";
import { State, StateAnnotation } from "./utils/state.js";
import { curry, getTextContent } from "./utils/utils.js";
Expand All @@ -27,7 +27,7 @@ const DEFAULT_CONFIG = {
MODEL_NAME: "claude-3-5-sonnet-20240620",
/** Maximum number of search results to return */
MAX_SEARCH_RESULTS: 10,
/** Maximum number of times the Info tool can be called before "__end__"ing the workflow */
/** Maximum number of times the Info tool can be called before "END"ing the workflow */
MAX_INFO_TOOL_CALLS: 3,
};

Expand Down Expand Up @@ -278,7 +278,7 @@ const badAgent = (state: State): { messages: BaseMessage[] } => {
*/
const route_after_agent = (
state: State,
): "badAgent" | "callChecker" | "toolNode" | "__end__" => {
): "badAgent" | "callChecker" | "toolNode" | typeof END => {
const lastMessage = state.messages[state.messages.length - 1] as AIMessage;
const numRounds = state.messages.filter(
(m) => ((m._getType() as string) === "tool" && m.name === "Info") || false,
Expand All @@ -288,7 +288,7 @@ const route_after_agent = (
return "badAgent";
} else if (lastMessage.tool_calls[0].name === "Info") {
if (numRounds > 2) {
return "__end__";
return END;
}
return "callChecker";
} else {
Expand All @@ -297,15 +297,15 @@ const route_after_agent = (
};

/**
* Routing function: Determines whether to continue research or "__end__" the workflow.
* Routing function: Determines whether to continue research or "END" the workflow.
* This function decides if the gathered information is satisfactory or if more research is needed.
*
* @param state - The current state of the research workflow
* @returns Either "callModel" to continue research or "__end__" to finish the workflow
* @returns Either "callModel" to continue research or "END" to finish the workflow
*/
const route_after_checker = (state: State): "__end__" | "callModel" => {
const route_after_checker = (state: State): typeof END | "callModel" => {
if (state.info) {
return "__end__";
return END;
}
return "callModel";
};
Expand Down Expand Up @@ -360,7 +360,7 @@ const workflow = new StateGraph(StateAnnotation)
.addNode("callChecker", callChecker)
.addNode("badAgent", badAgent)
.addNode("toolNode", createToolNode([searchTool, scrapeWebsiteToolFull]))
.addEdge("__start__", "callModel")
.addEdge(START, "callModel")
.addConditionalEdges("callModel", route_after_agent)
.addEdge("toolNode", "callModel")
.addConditionalEdges("callChecker", route_after_checker)
Expand Down
Empty file removed src/utils/configuration.ts
Empty file.
6 changes: 3 additions & 3 deletions src/utils/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ export const StateAnnotation = Annotation.Root({
reducer: messagesStateReducer,
default: () => [],
}),
topic: Annotation<string>(),
topic: Annotation<string>,
/**
* The info state trackes the current extracted data for the given topic,
* conforming to the provided schema.
*/
info: Annotation<z.infer<z.ZodObject<z.ZodRawShape>>>(),
info: Annotation<z.infer<z.ZodObject<z.ZodRawShape>>>,
/**
* The schema defines the information the agent is tasked with filling out.
*/
schema: Annotation<z.ZodObject<z.ZodRawShape>>(),
schema: Annotation<z.ZodObject<z.ZodRawShape>>,
// Feel free to add additional attributes to your state as needed.
// Common examples include retrieved documents, extracted entities, API connections, etc.
});
Expand Down
5 changes: 5 additions & 0 deletions tests/agent.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { describe, it, expect } from "@jest/globals";
import { graph } from "../src/agent.js";
import { z } from "zod";
describe("Researcher", () => {
it("should initialize and compile the graph", () => {
expect(graph).toBeDefined();
expect(graph.name).toBe("ResearchTopic");
});

it("Simple runthrough", async () => {
const enrichmentSchema = z.object({
founder: z.string().describe("The name of the company founder."),
Expand Down
7 changes: 2 additions & 5 deletions tests/agent.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { describe, it, expect } from "@jest/globals";
import { graph } from "../src/agent.js";

describe("Web Research Agent", () => {
it("should initialize and compile the graph", () => {
expect(graph).toBeDefined();
expect(graph.name).toBe("ResearchTopic");
it("todo", async () => {
expect(true).toBe(true);
});

// TODO: Add more test cases for individual nodes, routing logic, tool integration, and output validation
});
Loading

0 comments on commit 0f55080

Please sign in to comment.