implement components

This commit is contained in:
bracesproul
2025-03-07 10:47:08 -08:00
parent 066b219107
commit 7ebcbb3a28
19 changed files with 472 additions and 37 deletions

View File

@@ -6,9 +6,11 @@ import { stockbrokerGraph } from "./stockbroker";
import { ChatOpenAI } from "@langchain/openai";
import { tripPlannerGraph } from "./trip-planner";
import { formatMessages } from "./utils/format-messages";
import { graph as openCodeGraph } from "./open-code";
const allToolDescriptions = `- stockbroker: can fetch the price of a ticker, purchase/sell a ticker, or get the user's portfolio
- tripPlanner: helps the user plan their trip. it can suggest restaurants, and places to stay in any given location.`;
- tripPlanner: helps the user plan their trip. it can suggest restaurants, and places to stay in any given location.
- openCode: can write code for the user. call this tool when the user asks you to write code`;
async function router(
state: GenerativeUIState,
@@ -19,7 +21,7 @@ ${allToolDescriptions}
`;
const routerSchema = z.object({
route: z
.enum(["stockbroker", "tripPlanner", "generalInput"])
.enum(["stockbroker", "tripPlanner", "openCode", "generalInput"])
.describe(routerDescription),
});
const routerTool = {
@@ -73,7 +75,7 @@ Please pick the proper route based on the most recent message, in the context of
function handleRoute(
state: GenerativeUIState,
): "stockbroker" | "tripPlanner" | "generalInput" {
): "stockbroker" | "tripPlanner" | "openCode" | "generalInput" {
return state.next;
}
@@ -104,16 +106,19 @@ const builder = new StateGraph(GenerativeUIAnnotation)
.addNode("router", router)
.addNode("stockbroker", stockbrokerGraph)
.addNode("tripPlanner", tripPlannerGraph)
.addNode("openCode", openCodeGraph)
.addNode("generalInput", handleGeneralInput)
.addConditionalEdges("router", handleRoute, [
"stockbroker",
"tripPlanner",
"openCode",
"generalInput",
])
.addEdge(START, "router")
.addEdge("stockbroker", END)
.addEdge("tripPlanner", END)
.addEdge("openCode", END)
.addEdge("generalInput", END);
export const graph = builder.compile();