Repository navigation
Cpk 2442 hitl option 2 add new items - #1934
Conversation
…Implemented a new input field in both demo viewers to allow users to add steps dynamically during the execution phase. Added functionality to handle step addition via keyboard input, enhancing user interaction.
…oop demo viewers. Updated the input field styles in both demo viewers to enhance visual consistency.
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
## Walkthrough
The changes introduce the ability for users to dynamically add new steps during task execution in multiple human-in-the-loop demo pages by adding new state variables and handlers for step input. The no-chat demo is enhanced with a stepwise wizard UI showing progress, and agent flow delays are reduced. The prompt instructions are updated to include user-added steps in summaries. The langgraph server code is simplified by removing an indirection function and directly instantiating agents.
## Changes
| File(s) | Change Summary |
|--------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------|
| `examples/demo-viewer/agent/demo/crewai_human_in_the_loop/page.tsx`<br>`.../standard_human_in_the_loop/page.tsx`<br>`.../langgraph_human_in_the_loop/page.tsx` | Added state and handlers for user to input and add new steps during execution; updated UI to show input field. |
| `examples/demo-viewer/src/files.json` | Added stepwise wizard UI with progress indicators in no-chat demo; reduced sleep durations in agent flow nodes. |
| `examples/demo-viewer/src/lib/prompts.ts` | Updated instruction string to require summaries to include user-added steps. |
| `examples/demo-viewer/agent/demo/langgraph_server.py` | Removed `create_agents` function; instantiated agents inline when creating `CopilotKitSDK` instance. |
## Sequence Diagram(s)
```mermaid
sequenceDiagram
participant User
participant UI
participant StepsState
User->>UI: Enter new step in input field
UI->>StepsState: handleAddStep(newStep)
StepsState->>StepsState: Add new step to localSteps
StepsState->>UI: Update steps displaySuggested reviewers
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
examples/demo-viewer/agent/demo/standard_human_in_the_loop/page.tsx (1)
73-73: Remove debugger statement.The
debuggerstatement should be removed before merging to production.- debugger🧰 Tools
🪛 Biome (1.9.4)
[error] 73-73: This is an unexpected use of the debugger statement.
Unsafe fix: Remove debugger statement
(lint/suspicious/noDebugger)
examples/demo-viewer/src/files.json (2)
482-489: Use forward slashes for file paths
The current path uses Windows-style separators which may not resolve correctly on Unix-based environments or in the demo viewer.
Apply this diff to update the path:- "path": "langgraph_no_chat\\agent.py", + "path": "langgraph_no_chat/agent.py",
490-495: Normalize path separator and verify language tag
Similarly, update the path forpage.tsxand ensure the syntax highlighting language matches.tsxcontent:- "path": "langgraph_no_chat\\page.tsx", + "path": "langgraph_no_chat/page.tsx",If your viewer supports React/TSX highlighting, consider changing
"language": "typescript"to"language": "tsx"or"typescriptreact".
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
examples/demo-viewer/agent/demo/crewai_human_in_the_loop/page.tsx(3 hunks)examples/demo-viewer/agent/demo/standard_human_in_the_loop/page.tsx(2 hunks)examples/demo-viewer/src/files.json(1 hunks)examples/demo-viewer/src/lib/prompts.ts(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
- GitHub Check: Build Images (coagents-qa-native, ui)
- GitHub Check: Build Images (coagents-qa-native, agent, python, local-deps)
- GitHub Check: Build Images (next-openai, next-openai)
- GitHub Check: Build Images (coagents-qa-text, ui)
- GitHub Check: Build Images (coagents-qa-text, agent, python, local-deps)
- GitHub Check: Build Images (coagents-research-canvas, ui)
- GitHub Check: Build Images (coagents-routing, agent, python, local-deps)
- GitHub Check: Build Images (coagents-routing, ui)
- GitHub Check: Build Images (coagents-research-canvas, agent, python, local-deps)
🔇 Additional comments (5)
examples/demo-viewer/src/lib/prompts.ts (1)
50-50: LGTM! Prompt instruction properly aligns with new UI capability.The addition to include user-added steps in summaries correctly reflects the new dynamic step addition functionality being introduced in the UI components.
examples/demo-viewer/agent/demo/crewai_human_in_the_loop/page.tsx (3)
71-71: Good state management for new step input.The new state variable is properly initialized and will track the input field value correctly.
98-112: Well-implemented handlers with proper input validation.The functions handle edge cases appropriately:
- Input trimming prevents whitespace-only entries
- Functional state updates maintain immutability
- Enter key handling provides good UX
- Functions are defined at component level for optimal performance
143-153: Input field properly integrated with existing UI.The controlled input is well-implemented with:
- Proper event binding
- Conditional visibility based on execution status
- Consistent styling with existing components
- Clear placeholder text
examples/demo-viewer/agent/demo/standard_human_in_the_loop/page.tsx (1)
104-114: Input field implementation looks good.The controlled input field is properly implemented with correct event handling and conditional visibility.
| const [newStep, setNewStep] = useState(""); | ||
|
|
||
| const handleAddStep = () => { | ||
| const trimmed = newStep.trim(); | ||
| if (trimmed.length === 0) return; | ||
| setLocalSteps((prevSteps) => [ | ||
| ...prevSteps, | ||
| { description: trimmed, status: "enabled" }, | ||
| ]); | ||
| setNewStep(""); | ||
| }; | ||
|
|
||
| const handleInputKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => { | ||
| if (e.key === "Enter") { | ||
| handleAddStep(); | ||
| } | ||
| }; |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Refactor function definitions outside of render callback.
The handler functions are defined inside the renderAndWaitForResponse callback, which causes them to be recreated on every render. This impacts performance and could lead to unnecessary re-renders.
Consider moving these functions outside the callback or using useCallback to memoize them:
renderAndWaitForResponse: ({ args, respond, status }) => {
+ const handleAddStep = useCallback(() => {
+ const trimmed = newStep.trim();
+ if (trimmed.length === 0) return;
+ setLocalSteps((prevSteps) => [
+ ...prevSteps,
+ { description: trimmed, status: "enabled" },
+ ]);
+ setNewStep("");
+ }, [newStep]);
+
+ const handleInputKeyDown = useCallback((e: React.KeyboardEvent<HTMLInputElement>) => {
+ if (e.key === "Enter") {
+ handleAddStep();
+ }
+ }, [handleAddStep]);Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In examples/demo-viewer/agent/demo/standard_human_in_the_loop/page.tsx around
lines 44 to 60, the handler functions handleAddStep and handleInputKeyDown are
defined inside the renderAndWaitForResponse callback, causing them to be
recreated on every render and impacting performance. To fix this, move these
functions outside the callback or wrap them with React's useCallback hook to
memoize them, ensuring they are only recreated when their dependencies change.
… functionality to dynamically add steps via an input field and handle keyboard events for better user interaction during the execution phase.
There was a problem hiding this comment.
Actionable comments posted: 4
🔭 Outside diff range comments (1)
examples/demo-viewer/agent/demo/langgraph_human_in_the_loop/page.tsx (1)
22-118: 🛠️ Refactor suggestionGood functionality implementation with architectural improvements needed.
The dynamic step addition feature works well and integrates seamlessly with the existing step management logic. The user experience is intuitive with proper validation and state updates.
However, the overall architecture should be improved by moving state and handlers outside the render function as mentioned in the previous comments. This will improve performance and follow React best practices while maintaining the same functionality.
🧰 Tools
🪛 Biome (1.9.4)
[error] 43-43: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
🧹 Nitpick comments (1)
examples/demo-viewer/agent/demo/langgraph_human_in_the_loop/page.tsx (1)
93-103: Address the commented code and improve accessibility.The input field implementation looks good, but there's commented code that suggests incomplete logic.
Consider the following improvements:
- Address the commented line - determine if this visibility logic is needed:
- // hidden={status != "executing"}
- Add accessibility attributes for better UX:
<input type="text" + id="new-step-input" + aria-label="Add a new step" className="flex-1 rounded py-2 focus:outline-none" placeholder="Add a new step..." value={newStep} onChange={(e) => setNewStep(e.target.value)} onKeyDown={handleInputKeyDown} />
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
examples/demo-viewer/agent/demo/langgraph_human_in_the_loop/page.tsx(2 hunks)examples/demo-viewer/src/files.json(4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
- GitHub Check: Build Images (coagents-routing, agent, python, local-deps)
- GitHub Check: Build Images (coagents-qa-native, agent, python, local-deps)
- GitHub Check: Build Images (coagents-qa-native, ui)
- GitHub Check: Build Images (next-openai, next-openai)
- GitHub Check: Build Images (coagents-qa-text, agent, python, local-deps)
- GitHub Check: Build Images (coagents-qa-text, ui)
- GitHub Check: Build Images (coagents-research-canvas, ui)
- GitHub Check: Build Images (coagents-routing, ui)
- GitHub Check: Build Images (coagents-research-canvas, agent, python, local-deps)
🔇 Additional comments (2)
examples/demo-viewer/src/files.json (2)
74-80: Approve CrewAI HIL component JSON entry
The JSON entry forcrewai_human_in_the_loop/page.tsxis well-formed, and thecontentstring is properly escaped. Path separators are consistent with other entries.
482-489: Approve no-chat agent graph configuration
The LangGraph flow nodes (start_flow,buffer_node,confirming_response_node,reporting_node) and the reduced sleep durations are correctly defined. Streaming config viacopilotkit_customize_configand the graph compilation look solid.
| const handleAddStep = () => { | ||
| const trimmed = newStep.trim(); | ||
| if (trimmed.length === 0) return; | ||
| setLocalSteps((prevSteps) => [ | ||
| ...prevSteps, | ||
| { description: trimmed, status: "enabled" }, | ||
| ]); | ||
| setNewStep(""); | ||
| }; | ||
|
|
||
| const handleInputKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => { | ||
| if (e.key === "Enter") { | ||
| handleAddStep(); | ||
| } | ||
| }; |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Move handlers outside the render function for better performance.
Defining handlers inside the render function causes them to be recreated on every render, which can impact performance and potentially cause unnecessary re-renders of child components.
Consider moving these handlers to the component level and using useCallback if needed:
const Chat = () => {
+ const handleAddStep = useCallback(() => {
+ const trimmed = newStep.trim();
+ if (trimmed.length === 0) return;
+ setLocalSteps((prevSteps) => [
+ ...prevSteps,
+ { description: trimmed, status: "enabled" },
+ ]);
+ setNewStep("");
+ }, [newStep]);
+
+ const handleInputKeyDown = useCallback((e: React.KeyboardEvent<HTMLInputElement>) => {
+ if (e.key === "Enter") {
+ handleAddStep();
+ }
+ }, [handleAddStep]);
useLangGraphInterrupt({
render: ({ event, resolve }) => {
- const handleAddStep = () => {
- // function body
- };
-
- const handleInputKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
- // function body
- };Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In examples/demo-viewer/agent/demo/langgraph_human_in_the_loop/page.tsx around
lines 26 to 40, the event handler functions handleAddStep and handleInputKeyDown
are defined inside the render function, causing them to be recreated on every
render and potentially hurting performance. Move these handlers outside the
render function to the component level and wrap them with React's useCallback
hook to memoize them, ensuring they are only recreated when their dependencies
change.
| const Chat = () => { | ||
| useLangGraphInterrupt({ | ||
| render: ({ event, resolve }) => { | ||
| const [newStep, setNewStep] = useState(""); |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Move state declaration outside the render function.
Declaring state inside the render function violates React best practices and can cause performance issues since the state will be recreated on every render.
Consider moving this to the component level or using a ref if the state needs to be scoped to individual render calls:
const Chat = () => {
+ const [newStep, setNewStep] = useState("");
+
useLangGraphInterrupt({
render: ({ event, resolve }) => {
- const [newStep, setNewStep] = useState("");🤖 Prompt for AI Agents
In examples/demo-viewer/agent/demo/langgraph_human_in_the_loop/page.tsx at line
24, the useState hook is declared inside the render function, which violates
React best practices and can cause performance issues. Move the useState
declaration to the top level of the functional component, outside of the render
logic, so that the state persists across renders and is not recreated each time
the component renders.
| }, | ||
| { | ||
| "name": "page.tsx", | ||
| "content": "\"use client\";\r\nimport React, { useState, useEffect } from \"react\";\r\nimport \"@copilotkit/react-ui/styles.css\";\r\nimport \"./style.css\";\r\nimport { CopilotKit, useLangGraphInterrupt } from \"@copilotkit/react-core\";\r\nimport { CopilotChat, useCopilotChatSuggestions } from \"@copilotkit/react-ui\";\r\nimport { initialPrompt, chatSuggestions } from \"@/lib/prompts\";\r\nimport { AGENT_TYPE } from \"@/config\";\r\nconst HumanInTheLoop: React.FC = () => {\r\n return (\r\n <CopilotKit\r\n runtimeUrl={AGENT_TYPE == \"general\" ? \"/api/copilotkit?langgraph=true\" : \"/api/copilotkit\"}\r\n showDevConsole={false}\r\n agent=\"human_in_the_loop\"\r\n >\r\n <Chat />\r\n </CopilotKit>\r\n );\r\n};\r\n\r\nconst Chat = () => {\r\n useLangGraphInterrupt({\r\n render: ({ event, resolve }) => {\r\n\r\n // Ensure we have valid steps data\r\n let initialSteps = [];\r\n if (event.value && event.value.steps && Array.isArray(event.value.steps)) {\r\n initialSteps = event.value.steps.map((step: any) => ({\r\n description: typeof step === 'string' ? step : step.description || '',\r\n status: (typeof step === 'object' && step.status) ? step.status : 'enabled'\r\n }));\r\n }\r\n\r\n const [localSteps, setLocalSteps] = useState<\r\n {\r\n description: string;\r\n status: \"disabled\" | \"enabled\" | \"executing\";\r\n }[]\r\n >(initialSteps);\r\n\r\n const handleCheckboxChange = (index: number) => {\r\n setLocalSteps((prevSteps) =>\r\n prevSteps.map((step, i) =>\r\n i === index\r\n ? {\r\n ...step,\r\n status: step.status === \"enabled\" ? \"disabled\" : \"enabled\",\r\n }\r\n : step\r\n )\r\n );\r\n };\r\n\r\n return (\r\n <div className=\"flex flex-col gap-4 w-[500px] bg-gray-100 rounded-lg p-8 mb-4\">\r\n <div className=\"text-black space-y-2\">\r\n <h2 className=\"text-lg font-bold mb-4\">Select Steps</h2>\r\n {localSteps.map((step, index) => (\r\n <div key={index} className=\"text-sm flex items-center\">\r\n <label className=\"flex items-center cursor-pointer\">\r\n <input\r\n type=\"checkbox\"\r\n checked={step.status === \"enabled\"}\r\n onChange={() => handleCheckboxChange(index)}\r\n className=\"mr-2\"\r\n />\r\n <span\r\n className={\r\n step.status !== \"enabled\" ? \"line-through\" : \"\"\r\n }\r\n >\r\n {step.description}\r\n </span>\r\n </label>\r\n </div>\r\n ))}\r\n <button\r\n className=\"mt-4 bg-gradient-to-r from-purple-400 to-purple-600 text-white py-2 px-4 rounded cursor-pointer w-48 font-bold\"\r\n onClick={() => {\r\n const selectedSteps = localSteps\r\n .filter((step) => step.status === \"enabled\")\r\n .map((step) => step.description);\r\n resolve(\"The user selected the following steps: \" + selectedSteps.join(\", \"));\r\n }}\r\n >\r\n ✨ Perform Steps\r\n </button>\r\n </div>\r\n </div>\r\n );\r\n },\r\n });\r\n useCopilotChatSuggestions({\r\n instructions: chatSuggestions.humanInTheLoop,\r\n })\r\n return (\r\n <div className=\"flex justify-center items-center h-screen w-screen\">\r\n <div className=\"w-8/10 h-8/10\">\r\n <CopilotChat\r\n className=\"h-full rounded-lg\"\r\n labels={{ initial: initialPrompt.humanInTheLoop }}\r\n />\r\n </div>\r\n </div>\r\n );\r\n};\r\n\r\nexport default HumanInTheLoop;\r\n", | ||
| "content": "\"use client\";\r\nimport React, { useState, useEffect } from \"react\";\r\nimport \"@copilotkit/react-ui/styles.css\";\r\nimport \"./style.css\";\r\nimport { CopilotKit, useLangGraphInterrupt } from \"@copilotkit/react-core\";\r\nimport { CopilotChat, useCopilotChatSuggestions } from \"@copilotkit/react-ui\";\r\nimport { initialPrompt, chatSuggestions } from \"@/lib/prompts\";\r\nimport { AGENT_TYPE } from \"@/config\";\r\nconst HumanInTheLoop: React.FC = () => {\r\n return (\r\n <CopilotKit\r\n runtimeUrl={AGENT_TYPE == \"general\" ? \"/api/copilotkit?langgraph=true\" : \"/api/copilotkit\"}\r\n showDevConsole={false}\r\n agent=\"human_in_the_loop\"\r\n >\r\n <Chat />\r\n </CopilotKit>\r\n );\r\n};\r\n\r\nconst Chat = () => {\r\n useLangGraphInterrupt({\r\n render: ({ event, resolve }) => {\r\n const [newStep, setNewStep] = useState(\"\");\r\n\r\n const handleAddStep = () => {\r\n const trimmed = newStep.trim();\r\n if (trimmed.length === 0) return;\r\n setLocalSteps((prevSteps) => [\r\n ...prevSteps,\r\n { description: trimmed, status: \"enabled\" },\r\n ]);\r\n setNewStep(\"\");\r\n };\r\n\r\n const handleInputKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\r\n if (e.key === \"Enter\") {\r\n handleAddStep();\r\n }\r\n };\r\n // Ensure we have valid steps data\r\n let initialSteps = [];\r\n if (event.value && event.value.steps && Array.isArray(event.value.steps)) {\r\n initialSteps = event.value.steps.map((step: any) => ({\r\n description: typeof step === 'string' ? step : step.description || '',\r\n status: (typeof step === 'object' && step.status) ? step.status : 'enabled'\r\n }));\r\n }\r\n\r\n const [localSteps, setLocalSteps] = useState<\r\n {\r\n description: string;\r\n status: \"disabled\" | \"enabled\" | \"executing\";\r\n }[]\r\n >(initialSteps);\r\n\r\n const handleCheckboxChange = (index: number) => {\r\n setLocalSteps((prevSteps) =>\r\n prevSteps.map((step, i) =>\r\n i === index\r\n ? {\r\n ...step,\r\n status: step.status === \"enabled\" ? \"disabled\" : \"enabled\",\r\n }\r\n : step\r\n )\r\n );\r\n };\r\n\r\n return (\r\n <div className=\"flex flex-col gap-4 w-[500px] bg-gray-100 rounded-lg p-8 mb-4\">\r\n <div className=\"text-black space-y-2\">\r\n <h2 className=\"text-lg font-bold mb-4\">Select Steps</h2>\r\n {localSteps.map((step, index) => (\r\n <div key={index} className=\"text-sm flex items-center\">\r\n <label className=\"flex items-center cursor-pointer\">\r\n <input\r\n type=\"checkbox\"\r\n checked={step.status === \"enabled\"}\r\n onChange={() => handleCheckboxChange(index)}\r\n className=\"mr-2\"\r\n />\r\n <span\r\n className={\r\n step.status !== \"enabled\" ? \"line-through\" : \"\"\r\n }\r\n >\r\n {step.description}\r\n </span>\r\n </label>\r\n </div>\r\n ))}\r\n <div className=\"flex items-center gap-2 mb-4\">\r\n <input\r\n type=\"text\"\r\n className=\"flex-1 rounded py-2 focus:outline-none\"\r\n placeholder=\"Add a new step...\"\r\n value={newStep}\r\n onChange={(e) => setNewStep(e.target.value)}\r\n onKeyDown={handleInputKeyDown}\r\n // hidden={status != \"executing\"}\r\n />\r\n </div>\r\n <button\r\n className=\"mt-4 bg-gradient-to-r from-purple-400 to-purple-600 text-white py-2 px-4 rounded cursor-pointer w-48 font-bold\"\r\n onClick={() => {\r\n const selectedSteps = localSteps\r\n .filter((step) => step.status === \"enabled\")\r\n .map((step) => step.description);\r\n resolve(\"The user selected the following steps: \" + selectedSteps.join(\", \"));\r\n }}\r\n >\r\n ✨ Perform Steps\r\n </button>\r\n </div>\r\n </div>\r\n );\r\n },\r\n });\r\n useCopilotChatSuggestions({\r\n instructions: chatSuggestions.humanInTheLoop,\r\n })\r\n return (\r\n <div className=\"flex justify-center items-center h-screen w-screen\">\r\n <div className=\"w-8/10 h-8/10\">\r\n <CopilotChat\r\n className=\"h-full rounded-lg\"\r\n labels={{ initial: initialPrompt.humanInTheLoop }}\r\n />\r\n </div>\r\n </div>\r\n );\r\n};\r\n\r\nexport default HumanInTheLoop;\r\n", | ||
| "path": "langgraph_human_in_the_loop\\page.tsx", | ||
| "language": "typescript", | ||
| "type": "file" |
There was a problem hiding this comment.
Critical: Re-enable step-input hiding in LangGraph HIL
The hidden prop for the <input> is commented out, causing the new-step input to be always visible—even when the component isn’t executing. Re-enable and use the status prop to conditionally hide the field.
Apply this diff:
- // hidden={status != "executing"}
+ hidden={status !== "executing"}Optionally, hoist all useState calls (including for localSteps) to the top of the render callback to adhere to the Rules of Hooks.
Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In examples/demo-viewer/src/files.json around lines 322 to 328, the input field
for adding new steps has its hidden prop commented out, causing it to always be
visible regardless of the component's execution status. To fix this, uncomment
and use the hidden prop on the input element, setting it to true when status is
not "executing" to conditionally hide the input. Additionally, move all useState
hooks, including the one for localSteps, to the top of the render function to
comply with React's Rules of Hooks.
| "files": [ | ||
| { | ||
| "name": "page.tsx", | ||
| "content": "\"use client\";\r\nimport React, { useState, useEffect } from \"react\";\r\nimport \"@copilotkit/react-ui/styles.css\";\r\nimport \"./style.css\";\r\nimport { CopilotKit, useCopilotAction, useLangGraphInterrupt } from \"@copilotkit/react-core\";\r\nimport { CopilotChat, useCopilotChatSuggestions } from \"@copilotkit/react-ui\";\r\nimport { initialPrompt, chatSuggestions, instructions } from \"@/lib/prompts\";\r\nconst HumanInTheLoop: React.FC = () => {\r\n return (\r\n <CopilotKit\r\n runtimeUrl=\"/api/copilotkit?standard=true\"\r\n showDevConsole={false}\r\n >\r\n <Chat />\r\n </CopilotKit>\r\n );\r\n};\r\n\r\nconst Chat = () => {\r\n\r\n useCopilotAction({\r\n name: \"generate_task_steps\",\r\n description: \"Make up 10 steps (only a couple of words per step) that are required for a task. The step should be in imperative form (i.e. Dig hole, Open door, ...). When the user responds with selected steps, you must generate the summary with the selected steps.\",\r\n parameters: [\r\n {\r\n type: \"object[]\",\r\n name: \"items\",\r\n description: \"An array of 10 step objects, each containing text and status\",\r\n attributes: [\r\n {\r\n type: \"string\",\r\n name: \"description\",\r\n description: \"The text of the step in imperative form\"\r\n },\r\n {\r\n type: \"string\",\r\n name: \"status\",\r\n description: \"The status of the step, always 'enabled'\"\r\n }\r\n ]\r\n }\r\n ],\r\n renderAndWaitForResponse: ({ args, respond, status }) => {\r\n useEffect(() => {\r\n console.log(args, \"args.steps\")\r\n setLocalSteps(args?.items || [])\r\n }, [args])\r\n const [localSteps, setLocalSteps] = useState<\r\n {\r\n description: string;\r\n status: string;\r\n }[]\r\n >(args?.items || [])\r\n const handleCheckboxChange = (index: number) => {\r\n debugger\r\n const newSteps = [...localSteps];\r\n newSteps[index].status = newSteps[index].status === \"enabled\" ? \"disabled\" : \"enabled\";\r\n setLocalSteps(newSteps);\r\n };\r\n return (localSteps) ? <div className=\"flex flex-col gap-4 w-[500px] bg-gray-100 rounded-lg p-8 mb-4\">\r\n <div className=\"text-black space-y-2\">\r\n <h2 className=\"text-lg font-bold mb-4\">Select Steps</h2>\r\n {localSteps.map((step: any, index: number) => (\r\n <div key={index} className=\"text-sm flex items-center\">\r\n <label className=\"flex items-center cursor-pointer\">\r\n <input\r\n type=\"checkbox\"\r\n checked={step.status == \"enabled\"}\r\n onChange={() => {\r\n if (respond) {\r\n handleCheckboxChange(index)\r\n }\r\n }}\r\n className=\"mr-2\"\r\n />\r\n <span\r\n className={\r\n step.status !== \"enabled\" ? \"line-through\" : \"\"\r\n }\r\n >\r\n {step.description}\r\n </span>\r\n </label>\r\n </div>\r\n ))}\r\n <button\r\n className=\"mt-4 bg-gradient-to-r from-purple-400 to-purple-600 text-white py-2 px-4 rounded cursor-pointer w-48 font-bold\"\r\n hidden={!respond}\r\n onClick={() => {\r\n if (respond) {\r\n console.log(`The user has selected the following steps: ${localSteps.filter((step) => step.status === \"enabled\").map((step) => step.description).join(\", \")}`)\r\n respond(`The user has selected the following steps: ${localSteps.filter((step) => step.status === \"enabled\").map((step) => step.description).join(\", \")}`)\r\n }\r\n }}\r\n >\r\n ✨ Perform Steps\r\n </button>\r\n </div>\r\n </div> : <></>\r\n }\r\n })\r\n\r\n\r\n useCopilotChatSuggestions({\r\n instructions: chatSuggestions.humanInTheLoop,\r\n })\r\n return (\r\n <div className=\"flex justify-center items-center h-screen w-screen\">\r\n <div className=\"w-8/10 h-8/10\">\r\n <CopilotChat\r\n className=\"h-full rounded-lg\"\r\n labels={{ initial: initialPrompt.humanInTheLoop }}\r\n instructions={instructions.humanInTheLoop}\r\n />\r\n </div>\r\n </div>\r\n );\r\n};\r\n\r\nexport default HumanInTheLoop;\r\n", | ||
| "content": "\"use client\";\r\nimport React, { useState, useEffect } from \"react\";\r\nimport \"@copilotkit/react-ui/styles.css\";\r\nimport \"./style.css\";\r\nimport { CopilotKit, useCopilotAction, useLangGraphInterrupt } from \"@copilotkit/react-core\";\r\nimport { CopilotChat, useCopilotChatSuggestions } from \"@copilotkit/react-ui\";\r\nimport { initialPrompt, chatSuggestions, instructions } from \"@/lib/prompts\";\r\nconst HumanInTheLoop: React.FC = () => {\r\n return (\r\n <CopilotKit\r\n runtimeUrl=\"/api/copilotkit?standard=true\"\r\n showDevConsole={false}\r\n >\r\n <Chat />\r\n </CopilotKit>\r\n );\r\n};\r\n\r\nconst Chat = () => {\r\n\r\n useCopilotAction({\r\n name: \"generate_task_steps\",\r\n description: \"Make up 10 steps (only a couple of words per step) that are required for a task. The step should be in imperative form (i.e. Dig hole, Open door, ...). When the user responds with selected steps, you must generate the summary with the selected steps.\",\r\n parameters: [\r\n {\r\n type: \"object[]\",\r\n name: \"items\",\r\n description: \"An array of 10 step objects, each containing text and status\",\r\n attributes: [\r\n {\r\n type: \"string\",\r\n name: \"description\",\r\n description: \"The text of the step in imperative form\"\r\n },\r\n {\r\n type: \"string\",\r\n name: \"status\",\r\n description: \"The status of the step, always 'enabled'\"\r\n }\r\n ]\r\n }\r\n ],\r\n renderAndWaitForResponse: ({ args, respond, status }) => {\r\n const [newStep, setNewStep] = useState(\"\");\r\n\r\n const handleAddStep = () => {\r\n const trimmed = newStep.trim();\r\n if (trimmed.length === 0) return;\r\n setLocalSteps((prevSteps) => [\r\n ...prevSteps,\r\n { description: trimmed, status: \"enabled\" },\r\n ]);\r\n setNewStep(\"\");\r\n };\r\n\r\n const handleInputKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\r\n if (e.key === \"Enter\") {\r\n handleAddStep();\r\n }\r\n };\r\n\r\n useEffect(() => {\r\n console.log(args, \"args.steps\")\r\n setLocalSteps(args?.items || [])\r\n }, [args])\r\n const [localSteps, setLocalSteps] = useState<\r\n {\r\n description: string;\r\n status: string;\r\n }[]\r\n >(args?.items || [])\r\n const handleCheckboxChange = (index: number) => {\r\n debugger\r\n const newSteps = [...localSteps];\r\n newSteps[index].status = newSteps[index].status === \"enabled\" ? \"disabled\" : \"enabled\";\r\n setLocalSteps(newSteps);\r\n };\r\n return (localSteps) ? <div className=\"flex flex-col gap-4 w-[500px] bg-gray-100 rounded-lg p-8 mb-4\">\r\n <div className=\"text-black space-y-2\">\r\n <h2 className=\"text-lg font-bold mb-4\">Select Steps</h2>\r\n {localSteps.map((step: any, index: number) => (\r\n <div key={index} className=\"text-sm flex items-center\">\r\n <label className=\"flex items-center cursor-pointer\">\r\n <input\r\n type=\"checkbox\"\r\n checked={step.status == \"enabled\"}\r\n onChange={() => {\r\n if (respond) {\r\n handleCheckboxChange(index)\r\n }\r\n }}\r\n className=\"mr-2\"\r\n />\r\n <span\r\n className={\r\n step.status !== \"enabled\" ? \"line-through\" : \"\"\r\n }\r\n >\r\n {step.description}\r\n </span>\r\n </label>\r\n </div>\r\n ))}\r\n <div className=\"flex items-center gap-2 mb-4\">\r\n <input\r\n type=\"text\"\r\n className=\"flex-1 rounded py-2 focus:outline-none\"\r\n placeholder=\"Add a new step...\"\r\n value={newStep}\r\n onChange={(e) => setNewStep(e.target.value)}\r\n onKeyDown={handleInputKeyDown}\r\n hidden={status != \"executing\"}\r\n />\r\n </div>\r\n <button\r\n className=\"mt-4 bg-gradient-to-r from-purple-400 to-purple-600 text-white py-2 px-4 rounded cursor-pointer w-48 font-bold\"\r\n hidden={!respond}\r\n onClick={() => {\r\n if (respond) {\r\n console.log(`The user has selected the following steps: ${localSteps.filter((step) => step.status === \"enabled\").map((step) => step.description).join(\", \")}`)\r\n respond(`The user has selected the following steps: ${localSteps.filter((step) => step.status === \"enabled\").map((step) => step.description).join(\", \")}`)\r\n }\r\n }}\r\n >\r\n ✨ Perform Steps\r\n </button>\r\n </div>\r\n </div> : <></>\r\n }\r\n })\r\n\r\n\r\n useCopilotChatSuggestions({\r\n instructions: chatSuggestions.humanInTheLoop,\r\n })\r\n return (\r\n <div className=\"flex justify-center items-center h-screen w-screen\">\r\n <div className=\"w-8/10 h-8/10\">\r\n <CopilotChat\r\n className=\"h-full rounded-lg\"\r\n labels={{ initial: initialPrompt.humanInTheLoop }}\r\n instructions={instructions.humanInTheLoop}\r\n />\r\n </div>\r\n </div>\r\n );\r\n};\r\n\r\nexport default HumanInTheLoop;\r\n", | ||
| "path": "standard_human_in_the_loop\\page.tsx", | ||
| "language": "typescript", | ||
| "type": "file" |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Critical: Remove leftover debugger and correct logging/conditional rendering in Standard HIL
A debugger statement remains in handleCheckboxChange, and the console log labels args.steps instead of args.items. Also, localSteps (always truthy) is used for the render guard, so the UI shows even when there are no items.
Proposed fix:
const handleCheckboxChange = (index: number) => {
- debugger
+ // debugger removed for production
const newSteps = [...localSteps];
newSteps[index].status = newSteps[index].status === "enabled" ? "disabled" : "enabled";
setLocalSteps(newSteps);
};
useEffect(() => {
- console.log(args, "args.steps")
+ console.log(args, "args.items")
setLocalSteps(args?.items || [])
}, [args]);
- return (localSteps) ? <div className="flex flex-col gap-4 ..."> ...
+ return (args?.items?.length > 0) ? <div className="flex flex-col gap-4 ..."> ... 🤖 Prompt for AI Agents
In examples/demo-viewer/src/files.json around lines 539 to 545, remove the
leftover debugger statement inside the handleCheckboxChange function. Change the
console.log label from "args.steps" to "args.items" to correctly reflect the
logged data. Replace the render guard condition from simply checking localSteps
(which is always truthy) to checking if localSteps has any items (e.g.,
localSteps.length > 0) to prevent rendering the UI when there are no steps.
…create_agents function and directly initialized the CopilotKitSDK with the LangGraph agent, simplifying the code structure.
⏭️ Changeset Not RequiredLatest commit: 5d9370a No changes in this PR affected the Changeset is not required for this PR. |
|
Preview environments destroyed for this pull request. |
Test ResultsStatus: ✅ Passed (View Run) Commit: 7a0a1bc Duration: 385.5s Total Tests: 32 Pass Rate: 100.0% Failed Tests: 0 🔍 Detailed Resultscoagents-research-canvasCoAgents Research Canvas (UI) - Local Depenencies
coagents-qa-nativeCoAgents QA Native (UI) - Local
coagents-qa-textCoAgents QA Text (UI) - Local
coagents-routingCoAgents Routing (UI) - Local
next-openaiNext OpenAI - Self Hosted
|
This reverts commit c1db09e.
What does this PR do?
(Describe the changes introduced in this PR)
Related PRs and Issues
Checklist
Summary by CodeRabbit
New Features
Enhancements