The state schema type OR a type bag
The runtime context type available to node logic
Union of valid node names that can be routed to
type MyContext = { userId: string };
const router: ConditionalEdgeRouter<typeof AgentState, MyContext, "agent" | "tool"> =
(state, config) => {
const userId = config.context?.userId;
if (state.done) return END;
return state.needsTool ? "tool" : "agent";
};
graph.addConditionalEdges("router", router, ["agent", "tool"]);
Type for conditional edge routing functions.
Use this to type functions passed to
addConditionalEdgesfor full type safety on state, runtime context, and return values.Supports two patterns:
Single schema pattern - Single schema:
ConditionalEdgeRouter<Schema, Context, Nodes>Type bag pattern - Separate schemas for state, context:
ConditionalEdgeRouter<{ Schema; ContextSchema; Nodes }>