-
Notifications
You must be signed in to change notification settings - Fork 753
Improve Dojo examples #197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 10 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
801bd53
Optimize Dojo example code to simple and "idiomatic"
mme 61054a7
use CPK branch that fixes tool results
mme 5f7815a
update example to use ToolNode
mme a808639
send tool result
mme 6e152d6
add mastra local tool based gen UI
mme 058b8b3
add mastra tool based gen ui
mme 127866f
add agno support
mme c8ca26e
update agno example
mme c28021b
remove console.logs
mme d645235
add reasoning example
mme a7cc4f7
Merge remote-tracking branch 'origin/main' into mme/dojo-samples
mme 8336f1e
fix missing quotes
mme 1142149
upgrade to the latest agno
mme 4f451cb
regenerate json
mme 040371e
fix compile error
mme a8acac2
Merge branch 'main' into mme/dojo-samples
ranst91 711026f
align with main
ranst91 9dccb82
Merge branch 'main' into mme/dojo-samples
maxkorp 4cc9377
Merge remote-tracking branch 'origin/main' into mme/dojo-samples
maxkorp e1cbaf2
Combine agno examples
maxkorp a32dc7f
Fix agentic chat reasoning example won't start
maxkorp 9f80eaf
regenerate files.json
maxkorp 4740add
Merge remote-tracking branch 'origin/main' into mme/dojo-samples
maxkorp bd07917
Merge remote-tracking branch 'origin/main' into mme/dojo-samples
maxkorp cc1de05
regen again
maxkorp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...sdk/apps/dojo/src/app/[integrationId]/feature/agentic_chat_reasoning/README.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# 🤖 Agentic Chat with Reasoning | ||
|
||
## What This Demo Shows | ||
|
||
This demo showcases CopilotKit's **agentic chat** capabilities with **frontend | ||
tool integration**: | ||
|
||
1. **Natural Conversation**: Chat with your Copilot in a familiar chat interface | ||
2. **Frontend Tool Execution**: The Copilot can directly interacts with your UI | ||
by calling frontend functions | ||
3. **Seamless Integration**: Tools defined in the frontend and automatically | ||
discovered and made available to the agent | ||
|
||
## How to Interact | ||
|
||
Try asking your Copilot to: | ||
|
||
- "Can you change the background color to something more vibrant?" | ||
- "Make the background a blue to purple gradient" | ||
- "Set the background to a sunset-themed gradient" | ||
- "Change it back to a simple light color" | ||
|
||
You can also chat about other topics - the agent will respond conversationally | ||
while having the ability to use your UI tools when appropriate. | ||
|
||
## ✨ Frontend Tool Integration in Action | ||
|
||
**What's happening technically:** | ||
|
||
- The React component defines a frontend function using `useCopilotAction` | ||
- CopilotKit automatically exposes this function to the agent | ||
- When you make a request, the agent determines whether to use the tool | ||
- The agent calls the function with the appropriate parameters | ||
- The UI immediately updates in response | ||
|
||
**What you'll see in this demo:** | ||
|
||
- The Copilot understands requests to change the background | ||
- It generates CSS values for colors and gradients | ||
- When it calls the tool, the background changes instantly | ||
- The agent provides a conversational response about the changes it made | ||
|
||
This technique of exposing frontend functions to your Copilot can be extended to | ||
any UI manipulation you want to enable, from theme changes to data filtering, | ||
navigation, or complex UI state management! |
122 changes: 122 additions & 0 deletions
122
typescript-sdk/apps/dojo/src/app/[integrationId]/feature/agentic_chat_reasoning/page.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
"use client"; | ||
import React, { useState } from "react"; | ||
import "@copilotkit/react-ui/styles.css"; | ||
import "./style.css"; | ||
import { CopilotKit, useCoAgent, useCopilotAction, useCopilotChat } from "@copilotkit/react-core"; | ||
import { CopilotChat } from "@copilotkit/react-ui"; | ||
import { ChevronDown } from "lucide-react"; | ||
import { Button } from "@/components/ui/button"; | ||
import { | ||
DropdownMenu, | ||
DropdownMenuContent, | ||
DropdownMenuItem, | ||
DropdownMenuLabel, | ||
DropdownMenuSeparator, | ||
DropdownMenuTrigger, | ||
} from "@/components/ui/dropdown-menu"; | ||
|
||
interface AgenticChatProps { | ||
params: Promise<{ | ||
integrationId: string; | ||
}>; | ||
} | ||
|
||
const AgenticChat: React.FC<AgenticChatProps> = ({ params }) => { | ||
const { integrationId } = React.use(params); | ||
|
||
return ( | ||
<CopilotKit | ||
runtimeUrl={`/api/copilotkit/${integrationId}`} | ||
showDevConsole={false} | ||
// agent lock to the relevant agent | ||
agent="agentic_chat_reasoning" | ||
> | ||
<Chat /> | ||
</CopilotKit> | ||
); | ||
}; | ||
|
||
interface AgentState { | ||
model: string; | ||
} | ||
|
||
const Chat = () => { | ||
const [background, setBackground] = useState<string>("--copilot-kit-background-color"); | ||
const { state: agentState, setState: setAgentState } = useCoAgent<AgentState>({ | ||
name: "agentic_chat_reasoning", | ||
initialState: { | ||
model: "OpenAI", | ||
}, | ||
}); | ||
|
||
// Initialize model if not set | ||
const selectedModel = agentState?.model || "OpenAI"; | ||
|
||
const handleModelChange = (model: string) => { | ||
setAgentState({ model }); | ||
}; | ||
|
||
useCopilotAction({ | ||
name: "change_background", | ||
description: | ||
"Change the background color of the chat. Can be anything that the CSS background attribute accepts. Regular colors, linear of radial gradients etc.", | ||
parameters: [ | ||
{ | ||
name: "background", | ||
type: "string", | ||
description: "The background. Prefer gradients.", | ||
}, | ||
], | ||
handler: ({ background }) => { | ||
setBackground(background); | ||
}, | ||
}); | ||
|
||
return ( | ||
<div className="flex flex-col h-full w-full" style={{ background }}> | ||
{/* Reasoning Model Dropdown */} | ||
<div className="h-[65px] border-b border-gray-200 dark:border-gray-700"> | ||
<div className="h-full flex items-center justify-center"> | ||
<div className="flex items-center gap-2"> | ||
<span className="text-sm font-medium text-gray-700 dark:text-gray-300"> | ||
Reasoning Model: | ||
</span> | ||
<DropdownMenu> | ||
<DropdownMenuTrigger asChild> | ||
<Button variant="outline" className="w-[140px] justify-between"> | ||
{selectedModel} | ||
<ChevronDown className="h-4 w-4 opacity-50" /> | ||
</Button> | ||
</DropdownMenuTrigger> | ||
<DropdownMenuContent className="w-[140px]"> | ||
<DropdownMenuLabel>Select Model</DropdownMenuLabel> | ||
<DropdownMenuSeparator /> | ||
<DropdownMenuItem onClick={() => handleModelChange("OpenAI")}> | ||
OpenAI | ||
</DropdownMenuItem> | ||
<DropdownMenuItem onClick={() => handleModelChange("Anthropic")}> | ||
Anthropic | ||
</DropdownMenuItem> | ||
<DropdownMenuItem onClick={() => handleModelChange("Gemini")}> | ||
Gemini | ||
</DropdownMenuItem> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
{/* Chat Container */} | ||
<div className="flex-1 flex justify-center items-center p-4"> | ||
<div className="w-8/10 h-full rounded-lg"> | ||
<CopilotChat | ||
className="h-full rounded-2xl" | ||
labels={{ initial: "Hi, I'm an agent. Want to chat?" }} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default AgenticChat; |
12 changes: 12 additions & 0 deletions
12
typescript-sdk/apps/dojo/src/app/[integrationId]/feature/agentic_chat_reasoning/style.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.copilotKitInput { | ||
border-bottom-left-radius: 0.75rem; | ||
border-bottom-right-radius: 0.75rem; | ||
border-top-left-radius: 0.75rem; | ||
border-top-right-radius: 0.75rem; | ||
border: 1px solid var(--copilot-kit-separator-color) !important; | ||
} | ||
|
||
.copilotKitChat { | ||
background-color: #fff !important; | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1.9.3 should have the changes in this custom release. Could you check?