From 53db70fc292572d48cb89699aac14c5d113cdbe8 Mon Sep 17 00:00:00 2001 From: Paul Walko Date: Sun, 7 Dec 2025 09:20:51 -0700 Subject: [PATCH] ui starting point --- web/agent/main.py | 17 +---- web/src/app/page.tsx | 163 +++++-------------------------------------- 2 files changed, 19 insertions(+), 161 deletions(-) diff --git a/web/agent/main.py b/web/agent/main.py index 88ad8ea..f26f514 100644 --- a/web/agent/main.py +++ b/web/agent/main.py @@ -18,24 +18,14 @@ class AgentState(MessagesState): """ Here we define the state of the agent - In this instance, we're inheriting from CopilotKitState, which will bring in - the CopilotKitState fields. We're also adding a custom field, `language`, - which will be used to set the language of the agent. + In this instance, we're inheriting from MessagesState, which will bring in + the messages field for conversation history. """ - proverbs: List[str] tools: List[Any] # your_custom_agent_state: str = "" -@tool -def get_weather(location: str): - """ - Get the weather for a given location. - """ - return f"The weather for {location} is 70 degrees." - - # @tool # def your_tool_here(your_arg: str): # """Your tool description here.""" @@ -43,7 +33,6 @@ def get_weather(location: str): # return "Your tool response here." backend_tools = [ - get_weather # your_tool_here ] @@ -81,7 +70,7 @@ async def chat_node(state: AgentState, config: RunnableConfig) -> Command[str]: # 3. Define the system message by which the chat model will be run system_message = SystemMessage( - content=f"You are a helpful assistant. The current proverbs are {state.get('proverbs', [])}." + content="You are a helpful assistant." ) # 4. Run the model to generate a response diff --git a/web/src/app/page.tsx b/web/src/app/page.tsx index 434751f..93b77ea 100644 --- a/web/src/app/page.tsx +++ b/web/src/app/page.tsx @@ -1,19 +1,18 @@ "use client"; -import { useCoAgent, useCopilotAction } from "@copilotkit/react-core"; +import { useCopilotAction } from "@copilotkit/react-core"; import { CopilotKitCSSProperties, CopilotChat } from "@copilotkit/react-ui"; import { useState } from "react"; export default function CopilotKitPage() { const [themeColor, setThemeColor] = useState("#6366f1"); - // 🪁 Frontend Actions: https://docs.copilotkit.ai/guides/frontend-actions useCopilotAction({ name: "setThemeColor", parameters: [{ name: "themeColor", description: "The theme color to set. Make sure to pick nice colors.", - required: true, + required: true, }], handler({ themeColor }) { setThemeColor(themeColor); @@ -21,150 +20,20 @@ export default function CopilotKitPage() { }); return ( -
- - +
+
+ +
); } - -// State of the agent, make sure this aligns with your agent's state. -type AgentState = { - proverbs: string[]; -} - -function YourMainContent({ themeColor }: { themeColor: string }) { - // 🪁 Shared State: https://docs.copilotkit.ai/coagents/shared-state - const { state, setState } = useCoAgent({ - name: "sample_agent", - initialState: { - proverbs: [ - "CopilotKit may be new, but its the best thing since sliced bread.", - ], - }, - }) - - // 🪁 Frontend Actions: https://docs.copilotkit.ai/coagents/frontend-actions - useCopilotAction({ - name: "addProverb", - parameters: [{ - name: "proverb", - description: "The proverb to add. Make it witty, short and concise.", - required: true, - }], - handler: ({ proverb }) => { - setState({ - ...state, - proverbs: [...(state.proverbs || []), proverb], - }); - }, - }); - - //🪁 Generative UI: https://docs.copilotkit.ai/coagents/generative-ui - useCopilotAction({ - name: "get_weather", - description: "Get the weather for a given location.", - available: "disabled", - parameters: [ - { name: "location", type: "string", required: true }, - ], - render: ({ args }) => { - return - }, - }); - - return ( -
-
-

Proverbs

-

This is a demonstrative page, but it could be anything you want! 🪁

-
-
- {state.proverbs?.map((proverb, index) => ( -
-

{proverb}

- -
- ))} -
- {state.proverbs?.length === 0 &&

- No proverbs yet. Ask the assistant to add some! -

} -
-
- ); -} - -// Simple sun icon for the weather card -function SunIcon() { - return ( - - - - - ); -} - -// Weather card component where the location and themeColor are based on what the agent -// sets via tool calls. -function WeatherCard({ location, themeColor }: { location?: string, themeColor: string }) { - return ( -
-
-
-
-

{location}

-

Current Weather

-
- -
- -
-
70°
-
Clear skies
-
- -
-
-
-

Humidity

-

45%

-
-
-

Wind

-

5 mph

-
-
-

Feels Like

-

72°

-
-
-
-
-
- ); -}