Skip to content

Commit

Permalink
Fix typing for conditional edge array route maps
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 committed Aug 28, 2024
1 parent 4298a20 commit 645e5b2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion libs/langgraph/src/graph/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const END = "__end__";
export interface BranchOptions<IO, N extends string> {
source: N;
path: Branch<IO, N>["condition"];
pathMap?: Record<string, N | typeof END> | N[];
pathMap?: Record<string, N | typeof END> | (N | typeof END)[];
}

export class Branch<IO, N extends string> {
Expand Down
14 changes: 5 additions & 9 deletions libs/langgraph/src/prebuilt/react_agent_executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ import {
import { ChatPromptTemplate } from "@langchain/core/prompts";
import { BaseCheckpointSaver } from "@langchain/langgraph-checkpoint";
import {
END,
messagesStateReducer,
START,
type START,
StateGraph,
} from "../graph/index.js";
import { MessagesAnnotation } from "../graph/messages_annotation.js";
Expand Down Expand Up @@ -110,9 +109,9 @@ export function createReactAgent(
isAIMessage(lastMessage) &&
(!lastMessage.tool_calls || lastMessage.tool_calls.length === 0)
) {
return END;
return "__end__";
} else {
return "continue";
return "tools";
}
};

Expand All @@ -130,11 +129,8 @@ export function createReactAgent(
RunnableLambda.from(callModel).withConfig({ runName: "agent" })
)
.addNode("tools", new ToolNode<AgentState>(toolClasses))
.addEdge(START, "agent")
.addConditionalEdges("agent", shouldContinue, {
continue: "tools",
[END]: END,
})
.addEdge("__start__", "agent")
.addConditionalEdges("agent", shouldContinue, ["tools", "__end__"])
.addEdge("tools", "agent");

return workflow.compile({
Expand Down

0 comments on commit 645e5b2

Please sign in to comment.