From e9e737f5f3a688a4679c60a026eca5d26baecb20 Mon Sep 17 00:00:00 2001 From: bracesproul Date: Mon, 3 Mar 2025 18:09:49 -0800 Subject: [PATCH] fix: Add missing style imports --- agent/agent.tsx | 23 +++++++++++++------ .../uis/stockbroker/portfolio-view/index.tsx | 1 + agent/uis/stockbroker/stock-price/index.tsx | 1 + .../accommodations-list/index.tsx | 2 +- .../trip-planner/book-accommodation/index.tsx | 1 + .../trip-planner/book-restaurant/index.tsx | 1 + .../trip-planner/restaurants-list/index.tsx | 1 + 7 files changed, 22 insertions(+), 8 deletions(-) diff --git a/agent/agent.tsx b/agent/agent.tsx index 1d00cad..4e8718c 100644 --- a/agent/agent.tsx +++ b/agent/agent.tsx @@ -5,6 +5,7 @@ import { GenerativeUIAnnotation, GenerativeUIState } from "./types"; import { stockbrokerGraph } from "./stockbroker"; import { ChatOpenAI } from "@langchain/openai"; import { tripPlannerGraph } from "./trip-planner"; +import { formatMessages } from "./utils/format-messages"; 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.`; @@ -37,17 +38,25 @@ ${allToolDescriptions} const prompt = `You're a highly helpful AI assistant, tasked with routing the user's query to the appropriate tool. You should analyze the user's input, and choose the appropriate tool to use.`; - const recentHumanMessage = state.messages.findLast( - (m) => m.getType() === "human", - ); + const allMessagesButLast = state.messages.slice(0, -1); + const lastMessage = state.messages.at(-1); - if (!recentHumanMessage) { - throw new Error("No human message found in state"); - } + const formattedPreviousMessages = formatMessages(allMessagesButLast); + const formattedLastMessage = lastMessage ? formatMessages([lastMessage]) : ""; + + const humanMessage = `Here is the full conversation, excluding the most recent message: + +${formattedPreviousMessages} + +Here is the most recent message: + +${formattedLastMessage} + +Please pick the proper route based on the most recent message, in the context of the entire conversation.`; const response = await llm.invoke([ { role: "system", content: prompt }, - recentHumanMessage, + { role: "user", content: humanMessage }, ]); const toolCall = response.tool_calls?.[0]?.args as diff --git a/agent/uis/stockbroker/portfolio-view/index.tsx b/agent/uis/stockbroker/portfolio-view/index.tsx index 7dcb698..42bb140 100644 --- a/agent/uis/stockbroker/portfolio-view/index.tsx +++ b/agent/uis/stockbroker/portfolio-view/index.tsx @@ -1,3 +1,4 @@ +import "./index.css"; import { useState } from "react"; export default function PortfolioView() { diff --git a/agent/uis/stockbroker/stock-price/index.tsx b/agent/uis/stockbroker/stock-price/index.tsx index 78b3ff3..f279781 100644 --- a/agent/uis/stockbroker/stock-price/index.tsx +++ b/agent/uis/stockbroker/stock-price/index.tsx @@ -1,3 +1,4 @@ +import "./index.css"; import { useStream } from "@langchain/langgraph-sdk/react"; import type { AIMessage, Message } from "@langchain/langgraph-sdk"; import { useState, useEffect, useCallback } from "react"; diff --git a/agent/uis/trip-planner/accommodations-list/index.tsx b/agent/uis/trip-planner/accommodations-list/index.tsx index 2368c49..e671e5e 100644 --- a/agent/uis/trip-planner/accommodations-list/index.tsx +++ b/agent/uis/trip-planner/accommodations-list/index.tsx @@ -1,3 +1,4 @@ +import "./index.css"; import { TripDetails } from "../../../trip-planner/types"; import { useState } from "react"; @@ -6,7 +7,6 @@ export default function AccommodationsList({ }: { tripDetails: TripDetails; }) { - console.log("tripDetails", tripDetails); // Placeholder data - ideally would come from props const [accommodations] = useState([ { diff --git a/agent/uis/trip-planner/book-accommodation/index.tsx b/agent/uis/trip-planner/book-accommodation/index.tsx index 0e749bc..68d6d7e 100644 --- a/agent/uis/trip-planner/book-accommodation/index.tsx +++ b/agent/uis/trip-planner/book-accommodation/index.tsx @@ -1,3 +1,4 @@ +import "./index.css"; import { TripDetails } from "../../../trip-planner/types"; import { useState } from "react"; diff --git a/agent/uis/trip-planner/book-restaurant/index.tsx b/agent/uis/trip-planner/book-restaurant/index.tsx index cb1323a..e1e7a6b 100644 --- a/agent/uis/trip-planner/book-restaurant/index.tsx +++ b/agent/uis/trip-planner/book-restaurant/index.tsx @@ -1,3 +1,4 @@ +import "./index.css"; import { TripDetails } from "../../../trip-planner/types"; import { useState } from "react"; diff --git a/agent/uis/trip-planner/restaurants-list/index.tsx b/agent/uis/trip-planner/restaurants-list/index.tsx index d80aa7f..af6bc16 100644 --- a/agent/uis/trip-planner/restaurants-list/index.tsx +++ b/agent/uis/trip-planner/restaurants-list/index.tsx @@ -1,3 +1,4 @@ +import "./index.css"; import { TripDetails } from "../../../trip-planner/types"; import { useState } from "react";