Skip to content

Cpk 2442 hitl option 2 add new items - #1945

Merged
copilotkit-support merged 5 commits into
mainfrom
CPK-2442-HITL-option-2-add-new-items
Jun 6, 2025
Merged

copilotkit-support merged 5 commits into
mainfrom
CPK-2442-HITL-option-2-add-new-items

Conversation

@copilotkit-support

@copilotkit-support copilotkit-support commented Jun 6, 2025 •

Copy link
Copy Markdown
Contributor

What does this PR do?

(Describe the changes introduced in this PR)

Related PRs and Issues

  • (Direct link to related PR or issue, if relevant)

Checklist

  • I have read the Contribution Guide
  • If the PR changes or adds functionality, I have updated the relevant documentation

Summary by CodeRabbit

  • New Features

    • Added the ability for users to dynamically add new steps in human-in-the-loop demos via a text input and keyboard interaction.
    • Enhanced UI in agent demos to display current progress, step completion, and allow resetting the workflow.
    • Improved wizard-style visual feedback for step-based flows in no-chat demos.
  • Improvements

    • Upgraded key dependencies for stability and compatibility.
    • Refined prompts to include user-added steps in summary responses.
    • Improved backend handling for agent state and step data.
  • Bug Fixes

    • Minor timing and formatting adjustments for smoother user experience.

…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.
… functionality to dynamically add steps via an input field and handle keyboard events for better user interaction during the execution phase.
…create_agents function and directly initialized the CopilotKitSDK with the LangGraph agent, simplifying the code structure.
…graded @CopilotKit packages to version 1.8.14 in demo viewer and updated Python SDK version to 0.1.48 in agent configuration files.
@changesets-bot-copilotkit

Copy link
Copy Markdown

⏭️ Changeset Not Required

Latest commit: 486fb7c

No changes in this PR affected the @copilitkit/* packages. Merging this PR will not cause a version bump for any packages.

Changeset is not required for this PR.

@linear

linear Bot commented Jun 6, 2025

Copy link
Copy Markdown

@coderabbitai

coderabbitai Bot commented Jun 6, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

The changes introduce dynamic step addition in several human-in-the-loop React components by adding state and handlers for a new step input field. Related backend Python agent logic is updated for improved step handling. Dependency versions are incremented in configuration files, and prompt instructions are updated to reference user-added steps in summaries.

Changes

Files/Groups Change Summary
.../crewai_human_in_the_loop/page.tsx
.../langgraph_human_in_the_loop/page.tsx
.../standard_human_in_the_loop/page.tsx
Added state and handlers for dynamic step addition via input; input field shown conditionally; logic for toggling steps updated.
.../langgraph_server.py Refactored agent registration: removed agent-creation function, registered agents inline during SDK instantiation.
.../pyproject.toml
.../package.json
Updated copilotkit and @copilotkit/* dependencies to newer versions.
.../src/files.json Summarizes all frontend and backend changes, including UI enhancements for step addition and wizard progress, backend agent improvements, and minor formatting.
.../src/lib/prompts.ts Updated prompt instructions to require summaries to include user-added steps.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ReactComponent
    participant BackendAgent

    User->>ReactComponent: Types new step in input
    ReactComponent->>ReactComponent: handleAddStep (on Enter key)
    ReactComponent->>ReactComponent: Add step to local steps list
    User->>ReactComponent: Clicks "Perform Steps"
    ReactComponent->>BackendAgent: Send enabled steps (including user-added)
    BackendAgent->>BackendAgent: Process steps and respond
    BackendAgent->>ReactComponent: Return summary including user-added steps
    ReactComponent->>User: Display summary
Loading

Possibly related PRs

Suggested labels

preview

Suggested reviewers

  • mme
  • suhasdeshpande
  • ataibarkai
  • ranst91
  • tylerslaton
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@vercel

vercel Bot commented Jun 6, 2025

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ag2-feature-viewer ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 6, 2025 1:46pm
ag2-starter ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 6, 2025 1:46pm
coagents-starter-crewai-flows ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 6, 2025 1:46pm
copilot-kit ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 6, 2025 1:46pm
copilot-kit-qd8p ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 6, 2025 1:46pm
copilot-kit-wq8x ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 6, 2025 1:46pm
copilot-mastra-starter ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 6, 2025 1:46pm
copilotkit-feature-viewer ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 6, 2025 1:46pm
copilotkit-mastra-feature-viewer ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 6, 2025 1:46pm
demo-viewer ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 6, 2025 1:46pm
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 6, 2025 1:46pm
examples-coagents-ai-travel-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 6, 2025 1:46pm
examples-coagents-research-canvas-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 6, 2025 1:46pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
examples-coagents-ai-researcher-ui ⬜️ Ignored (Inspect) Jun 6, 2025 1:46pm

@github-actions

github-actions Bot commented Jun 6, 2025 •

Copy link
Copy Markdown
Contributor

Preview environments destroyed for this pull request.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🔭 Outside diff range comments (2)
examples/demo-viewer/agent/demo/langgraph_server.py (1)

27-70: 🛠️ Refactor suggestion

Address the deprecated CopilotKitSDK usage.

While the inline agent instantiation is cleaner, the code is using CopilotKitSDK which is deprecated since version 0.1.31. This will generate deprecation warnings in the logs.

Update to use the recommended CopilotKitRemoteEndpoint:

-from copilotkit import CopilotKitSDK, LangGraphAgent
+from copilotkit import CopilotKitRemoteEndpoint, LangGraphAgent

-sdk = CopilotKitSDK(
+sdk = CopilotKitRemoteEndpoint(
     agents=[
         # Register the LangGraph agent using the LangGraphAgent class
         LangGraphAgent(
examples/demo-viewer/src/files.json (1)

542-547: ⚠️ Potential issue

Remove leftover debugger statement. There's a stray debugger in standard_human_in_the_loop/page.tsx which will halt execution in browsers. Please delete it:

-        debugger
♻️ Duplicate comments (1)
examples/demo-viewer/agent/demo/standard_human_in_the_loop/page.tsx (1)

46-54: Apply the same input validation as suggested for langgraph demo.

This function has the same XSS vulnerability as the langgraph implementation. The logic is identical and needs the same security improvements.

Refer to the security fix suggested for the langgraph demo's handleAddStep function.

🧹 Nitpick comments (5)
examples/demo-viewer/agent/demo/langgraph_human_in_the_loop/page.tsx (1)

93-103: Consider adding visual feedback and accessibility attributes.

The input field implementation is functional but could benefit from better UX and accessibility improvements.

Apply this diff to improve the input field:

 <div className="flex items-center gap-2 mb-4">
   <input
     type="text"
     className="flex-1 rounded py-2 focus:outline-none"
     placeholder="Add a new step..."
     value={newStep}
     onChange={(e) => setNewStep(e.target.value)}
     onKeyDown={handleInputKeyDown}
-    // hidden={status != "executing"}
+    aria-label="Add new step"
+    maxLength={100}
   />
+  <button
+    onClick={handleAddStep}
+    className="px-3 py-2 bg-blue-500 text-white rounded hover:bg-blue-600"
+    disabled={!newStep.trim()}
+    aria-label="Add step"
+  >
+    Add
+  </button>
 </div>
examples/demo-viewer/agent/demo/standard_human_in_the_loop/page.tsx (1)

104-114: Good conditional rendering but consider same UX improvements.

The conditional hiding based on status is a good UX decision that's missing from the langgraph demo. However, the input field could still benefit from the same accessibility and validation improvements.

Apply similar improvements as suggested for the langgraph demo, but keep the conditional rendering:

 <div className="flex items-center gap-2 mb-4">
   <input
     type="text"
     className="flex-1 rounded py-2 focus:outline-none"
     placeholder="Add a new step..."
     value={newStep}
     onChange={(e) => setNewStep(e.target.value)}
     onKeyDown={handleInputKeyDown}
     hidden={status != "executing"}
+    aria-label="Add new step"
+    maxLength={100}
   />
+  {status === "executing" && (
+    <button
+      onClick={handleAddStep}
+      className="px-3 py-2 bg-blue-500 text-white rounded hover:bg-blue-600"
+      disabled={!newStep.trim()}
+      aria-label="Add step"
+    >
+      Add
+    </button>
+  )}
 </div>
examples/demo-viewer/src/files.json (3)

74-80: Reduce unnecessary useEffect dependencies. The effect in StepsFeedback is re-run any time localSteps changes, although it should only initialize state once when execution starts. Remove localSteps from the dependency array to avoid redundant calls:

-}, [status, args.steps, localSteps]);
+}, [status, args.steps]);

484-489: Avoid static delays with asyncio.sleep. Fixed sleep calls can slow the flow and lead to poor UX. Replace or parameterize these with event-driven signals or use CopilotKit streaming hooks (e.g., copilotkit_emit_state) instead of hardcoded sleeps.


542-547: Correct the console.log message. The log prints "args.steps" but the parameter is now args.items. Update the label for clarity:

- console.log(args, "args.steps");
+ console.log(args, "args.items");
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a2fd005 and 486fb7c.

⛔ Files ignored due to path filters (2)
  • examples/demo-viewer/agent/poetry.lock is excluded by !**/*.lock
  • examples/demo-viewer/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (8)
  • examples/demo-viewer/agent/demo/crewai_human_in_the_loop/page.tsx (3 hunks)
  • examples/demo-viewer/agent/demo/langgraph_human_in_the_loop/page.tsx (2 hunks)
  • examples/demo-viewer/agent/demo/langgraph_server.py (1 hunks)
  • examples/demo-viewer/agent/demo/standard_human_in_the_loop/page.tsx (2 hunks)
  • examples/demo-viewer/agent/pyproject.toml (1 hunks)
  • examples/demo-viewer/package.json (1 hunks)
  • examples/demo-viewer/src/files.json (4 hunks)
  • examples/demo-viewer/src/lib/prompts.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
examples/demo-viewer/agent/demo/langgraph_server.py (1)
sdk-python/copilotkit/sdk.py (1)
  • CopilotKitSDK (391-401)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Build Images (next-openai, next-openai)
  • GitHub Check: Build Images (coagents-qa-native, ui)
  • GitHub Check: Build Images (coagents-qa-native, agent, python, local-deps)
  • GitHub Check: Build Images (coagents-qa-text, ui)
  • GitHub Check: Build Images (coagents-qa-text, agent, python, local-deps)
  • GitHub Check: Build Images (coagents-routing, ui)
  • GitHub Check: Build Images (coagents-routing, agent, python, local-deps)
  • GitHub Check: Build Images (coagents-research-canvas, ui)
  • GitHub Check: Build Images (coagents-research-canvas, agent, python, local-deps)
🔇 Additional comments (11)
examples/demo-viewer/agent/pyproject.toml (1)

10-10: LGTM: Standard dependency version update.

The copilotkit version bump from 0.1.46 to 0.1.48 aligns with the frontend dependency updates and supports the new human-in-the-loop features.

examples/demo-viewer/package.json (1)

13-16: LGTM: Dependency versions updated with exact pinning.

The @CopilotKit packages are updated to version 1.8.14 with exact version pinning (removing the ^ prefix). This ensures reproducible builds for the demo, which is appropriate for this use case.

examples/demo-viewer/src/lib/prompts.ts (1)

50-50: LGTM: Prompt instruction updated to support dynamic step addition.

The addition of "While summarizing, include the steps that user added as well." properly aligns the prompt with the new UI functionality that allows users to add steps dynamically during execution.

examples/demo-viewer/agent/demo/crewai_human_in_the_loop/page.tsx (4)

71-71: LGTM: State variable for new step input.

The newStep state is properly initialized to track the input value for adding new steps.


98-106: LGTM: Well-implemented step addition handler.

The handleAddStep function includes proper input validation (trimming and empty check), adds new steps with appropriate default status, and clears the input field. The implementation follows React best practices.


108-112: LGTM: Keyboard interaction support.

The Enter key handling provides good user experience for adding steps without requiring mouse interaction.


143-153: LGTM: Well-designed input field for step addition.

The input field implementation is solid:

  • Controlled component with proper state binding
  • Hidden when not in executing status (appropriate UX)
  • Supports both Enter key and blur interactions
  • Clear placeholder text

The conditional visibility (hidden={status != "executing"}) ensures the input only appears when users can actually add steps.

examples/demo-viewer/agent/demo/langgraph_human_in_the_loop/page.tsx (2)

24-24: LGTM: State variable declaration is correct.

The newStep state variable is properly initialized as an empty string for tracking the input field value.


36-40: LGTM: Keyboard event handler is implemented correctly.

The handleInputKeyDown function properly handles the Enter key press to trigger step addition, providing good UX.

examples/demo-viewer/agent/demo/standard_human_in_the_loop/page.tsx (2)

44-44: LGTM: State variable declaration is consistent.

The newStep state variable follows the same pattern as the langgraph implementation, maintaining consistency across demos.


56-60: LGTM: Keyboard handler is implemented consistently.

The implementation matches the langgraph demo and provides good user experience.

Comment on lines +26 to +34
const handleAddStep = () => {
const trimmed = newStep.trim();
if (trimmed.length === 0) return;
setLocalSteps((prevSteps) => [
...prevSteps,
{ description: trimmed, status: "enabled" },
]);
setNewStep("");
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add input validation to prevent XSS attacks.

The handleAddStep function lacks proper input sanitization. While basic trimming is performed, there's no validation against potentially malicious content that could lead to XSS vulnerabilities when the step descriptions are rendered.

Consider adding input validation:

 const handleAddStep = () => {
   const trimmed = newStep.trim();
   if (trimmed.length === 0) return;
+  // Add basic validation to prevent XSS
+  if (trimmed.length > 100) {
+    console.warn("Step description too long");
+    return;
+  }
+  if (/<script|javascript:|on\w+=/i.test(trimmed)) {
+    console.warn("Invalid characters in step description");
+    return;
+  }
   setLocalSteps((prevSteps) => [
     ...prevSteps,
     { description: trimmed, status: "enabled" },
   ]);
   setNewStep("");
 };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const handleAddStep = () => {
const trimmed = newStep.trim();
if (trimmed.length === 0) return;
setLocalSteps((prevSteps) => [
...prevSteps,
{ description: trimmed, status: "enabled" },
]);
setNewStep("");
};
const handleAddStep = () => {
const trimmed = newStep.trim();
if (trimmed.length === 0) return;
// Add basic validation to prevent XSS
if (trimmed.length > 100) {
console.warn("Step description too long");
return;
}
if (/<script|javascript:|on\w+=/i.test(trimmed)) {
console.warn("Invalid characters in step description");
return;
}
setLocalSteps((prevSteps) => [
...prevSteps,
{ description: trimmed, status: "enabled" },
]);
setNewStep("");
};
🤖 Prompt for AI Agents
In examples/demo-viewer/agent/demo/langgraph_human_in_the_loop/page.tsx around
lines 26 to 34, the handleAddStep function currently only trims input but does
not sanitize it, which can lead to XSS vulnerabilities when rendering step
descriptions. To fix this, implement input validation that sanitizes or escapes
any potentially malicious content in newStep before adding it to localSteps. Use
a library or custom function to remove or encode harmful characters or scripts
to ensure safe rendering.

Comment on lines 74 to 80
},
{
"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 } from \"@copilotkit/react-core\";\r\nimport { CopilotChat, useCopilotChatSuggestions } from \"@copilotkit/react-ui\";\r\nimport { chatSuggestions, initialPrompt } 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?crewai=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\n\r\nconst Chat = () => {\r\n useCopilotAction({\r\n name: \"generate_task_steps\",\r\n parameters: [\r\n {\r\n name: \"steps\",\r\n type: \"object[]\",\r\n attributes: [\r\n {\r\n name: \"description\",\r\n type: \"string\",\r\n },\r\n {\r\n name: \"status\",\r\n type: \"string\",\r\n enum: [\"enabled\", \"disabled\", \"executing\"],\r\n },\r\n ],\r\n },\r\n ],\r\n renderAndWaitForResponse: ({ args, respond, status }) => {\r\n return <StepsFeedback args={args} respond={respond} status={status} />;\r\n },\r\n });\r\n\r\n\r\n useCopilotChatSuggestions({\r\n instructions: chatSuggestions.humanInTheLoop,\r\n })\r\n\r\n return (\r\n <div className=\"flex justify-center items-center h-full w-full\">\r\n <div className=\"w-8/10 h-8/10 rounded-lg\">\r\n <CopilotChat\r\n className=\"h-full rounded-2xl\"\r\n labels={{ initial: initialPrompt.humanInTheLoop }}\r\n />\r\n </div>\r\n </div>\r\n );\r\n};\r\n\r\nconst StepsFeedback = ({ args, respond, status }: { args: any, respond: any, status: any }) => {\r\n const [localSteps, setLocalSteps] = useState<\r\n {\r\n description: string;\r\n status: \"disabled\" | \"enabled\" | \"executing\";\r\n }[]\r\n >([]);\r\n\r\n useEffect(() => {\r\n if (status === \"executing\" && localSteps.length === 0) {\r\n setLocalSteps(args.steps);\r\n }\r\n }, [status, args.steps, localSteps]);\r\n\r\n if (args.steps === undefined || args.steps.length === 0) {\r\n return <></>;\r\n }\r\n\r\n const steps = localSteps.length > 0 ? localSteps : args.steps;\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 {steps.map((step: any, index: any) => (\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\" && status != \"inProgress\"\r\n ? \"line-through\"\r\n : \"\"\r\n }\r\n >\r\n {step.description}\r\n </span>\r\n </label>\r\n </div>\r\n ))}\r\n {status === \"executing\" && (\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 respond(\r\n \"The user selected the following steps: \" +\r\n selectedSteps.join(\", \")\r\n );\r\n }}\r\n >\r\n ✨ Perform Steps\r\n </button>\r\n )}\r\n </div>\r\n </div>\r\n );\r\n};\r\n\r\nfunction Spinner() {\r\n return (\r\n <svg\r\n className=\"mr-2 size-3 animate-spin text-slate-500\"\r\n xmlns=\"http://www.w3.org/2000/svg\"\r\n fill=\"none\"\r\n viewBox=\"0 0 24 24\"\r\n >\r\n <circle\r\n className=\"opacity-25\"\r\n cx=\"12\"\r\n cy=\"12\"\r\n r=\"10\"\r\n stroke=\"currentColor\"\r\n strokeWidth=\"4\"\r\n ></circle>\r\n <path\r\n className=\"opacity-75\"\r\n fill=\"currentColor\"\r\n d=\"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z\"\r\n ></path>\r\n </svg>\r\n );\r\n}\r\nexport default HumanInTheLoop;\r\n\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 } from \"@copilotkit/react-core\";\r\nimport { CopilotChat, useCopilotChatSuggestions } from \"@copilotkit/react-ui\";\r\nimport { chatSuggestions, initialPrompt } 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?crewai=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\n\r\nconst Chat = () => {\r\n useCopilotAction({\r\n name: \"generate_task_steps\",\r\n parameters: [\r\n {\r\n name: \"steps\",\r\n type: \"object[]\",\r\n attributes: [\r\n {\r\n name: \"description\",\r\n type: \"string\",\r\n },\r\n {\r\n name: \"status\",\r\n type: \"string\",\r\n enum: [\"enabled\", \"disabled\", \"executing\"],\r\n },\r\n ],\r\n },\r\n ],\r\n renderAndWaitForResponse: ({ args, respond, status }) => {\r\n return <StepsFeedback args={args} respond={respond} status={status} />;\r\n },\r\n });\r\n\r\n\r\n useCopilotChatSuggestions({\r\n instructions: chatSuggestions.humanInTheLoop,\r\n })\r\n\r\n return (\r\n <div className=\"flex justify-center items-center h-full w-full\">\r\n <div className=\"w-8/10 h-8/10 rounded-lg\">\r\n <CopilotChat\r\n className=\"h-full rounded-2xl\"\r\n labels={{ initial: initialPrompt.humanInTheLoop }}\r\n />\r\n </div>\r\n </div>\r\n );\r\n};\r\n\r\nconst StepsFeedback = ({ args, respond, status }: { args: any, respond: any, status: any }) => {\r\n const [localSteps, setLocalSteps] = useState<\r\n {\r\n description: string;\r\n status: \"disabled\" | \"enabled\" | \"executing\";\r\n }[]\r\n >([]);\r\n const [newStep, setNewStep] = useState(\"\");\r\n\r\n useEffect(() => {\r\n if (status === \"executing\" && localSteps.length === 0) {\r\n setLocalSteps(args.steps);\r\n }\r\n }, [status, args.steps, localSteps]);\r\n\r\n if (args.steps === undefined || args.steps.length === 0) {\r\n return <></>;\r\n }\r\n\r\n const steps = localSteps.length > 0 ? localSteps : args.steps;\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 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 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 {steps.map((step: any, index: any) => (\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\" && status != \"inProgress\"\r\n ? \"line-through\"\r\n : \"\"\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 {status === \"executing\" && (\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 respond(\r\n \"The user selected the following steps: \" +\r\n selectedSteps.join(\", \")\r\n );\r\n }}\r\n >\r\n ✨ Perform Steps\r\n </button>\r\n )}\r\n </div>\r\n </div>\r\n );\r\n};\r\n\r\nfunction Spinner() {\r\n return (\r\n <svg\r\n className=\"mr-2 size-3 animate-spin text-slate-500\"\r\n xmlns=\"http://www.w3.org/2000/svg\"\r\n fill=\"none\"\r\n viewBox=\"0 0 24 24\"\r\n >\r\n <circle\r\n className=\"opacity-25\"\r\n cx=\"12\"\r\n cy=\"12\"\r\n r=\"10\"\r\n stroke=\"currentColor\"\r\n strokeWidth=\"4\"\r\n ></circle>\r\n <path\r\n className=\"opacity-75\"\r\n fill=\"currentColor\"\r\n d=\"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z\"\r\n ></path>\r\n </svg>\r\n );\r\n}\r\nexport default HumanInTheLoop;\r\n\r\n",
"path": "crewai_human_in_the_loop\\page.tsx",
"language": "typescript",
"type": "file"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Propagate checkbox toggles back to the agent. Currently handleCheckboxChange updates only local state. To inform the backend of interim step changes, call respond with the updated step list inside the onChange handler:

- onChange={() => { handleCheckboxChange(index); }}
+ onChange={() => {
+   const updated = prevStepsAfterToggle(index);
+   setLocalSteps(updated);
+   respond(updated.map(s => s.description));
+ }}

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In examples/demo-viewer/src/files.json around lines 74 to 80 in
crewai_human_in_the_loop\page.tsx, the handleCheckboxChange function updates
only the localSteps state but does not notify the backend of these changes. To
fix this, modify the onChange handler of the checkbox input to call respond with
the updated steps after toggling the status, ensuring the agent receives the
current step list. This involves updating handleCheckboxChange to accept respond
as a parameter or calling respond directly after updating localSteps with the
new step statuses.

Comment on lines 324 to 328
"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"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Reinitialize steps when new interrupt events arrive. The initial state is set once from event.value.steps but never updated on subsequent events. Add an effect to sync localSteps with event.value.steps:

 const [localSteps, setLocalSteps] = useState(initialSteps);
+useEffect(() => {
+  if (event.value?.steps) {
+    setLocalSteps(event.value.steps.map(step => ({
+      description: typeof step === 'string' ? step : step.description || '',
+      status: step.status || 'enabled'
+    })));
+  }
+}, [event.value]);
🤖 Prompt for AI Agents
In examples/demo-viewer/src/files.json around lines 324 to 328, the localSteps
state is initialized once from event.value.steps but does not update when new
interrupt events arrive. To fix this, add a useEffect hook that listens for
changes in event.value.steps and updates localSteps accordingly, ensuring the
steps reinitialize properly on each new event.

@github-actions

github-actions Bot commented Jun 6, 2025 •

Copy link
Copy Markdown
Contributor

Test Results

Status: ✅ Passed (View Run)

Commit: 692c5ef

Duration: 445.3s

Total Tests: 32

Pass Rate: 100.0%

Failed Tests: 0

🔍 Detailed Results

coagents-research-canvas

CoAgents Research Canvas (UI) - Local Depenencies

Model Browser Status Video
OpenAI chromium ✅ PASSED -
Anthropic chromium ✅ PASSED -
CrewAI chromium ✅ PASSED -
OpenAI (LGC Python in-memory) chromium ✅ PASSED -
Anthropic (LGC Python in-memory) chromium ✅ PASSED -
OpenAI (LGC JS in-memory) chromium ✅ PASSED -
Anthropic (LGC JS in-memory) chromium ✅ PASSED -

coagents-qa-native

CoAgents QA Native (UI) - Local

Model Browser Status Video
OpenAI chromium ✅ PASSED -
Anthropic chromium ✅ PASSED -
OpenAI (LGC Python) chromium ✅ PASSED -
Anthropic (LGC Python) chromium ✅ PASSED -
OpenAI (LGC JS) chromium ✅ PASSED -
Anthropic (LGC JS) chromium ✅ PASSED -

coagents-qa-text

CoAgents QA Text (UI) - Local

Model Browser Status Video
OpenAI chromium ✅ PASSED -
Anthropic chromium ✅ PASSED -
OpenAI (LGC Python) chromium ✅ PASSED -
Anthropic (LGC Python) chromium ✅ PASSED -
OpenAI (LGC JS) chromium ✅ PASSED -
Anthropic (LGC JS) chromium ✅ PASSED -

coagents-routing

CoAgents Routing (UI) - Local

Model Browser Status Video
OpenAI chromium ✅ PASSED -
Anthropic chromium ✅ PASSED -
OpenAI (LGC Python) chromium ✅ PASSED -
Anthropic (LGC Python) chromium ✅ PASSED -
OpenAI (LGC JS) chromium ✅ PASSED -
Anthropic (LGC JS) chromium ✅ PASSED -

next-openai

Next OpenAI - Self Hosted

Model Browser Status Video
OpenAI chromium ✅ PASSED -
Anthropic chromium ✅ PASSED -
Google Generative AI chromium ✅ PASSED -
LangChain (OpenAI) chromium ✅ PASSED -
LangChain (Anthropic) chromium ✅ PASSED -
LangChain (Gemini) chromium ✅ PASSED -
Groq chromium ✅ PASSED -

@copilotkit-support
copilotkit-support merged commit 06a7a57 into main Jun 6, 2025
@copilotkit-support
copilotkit-support deleted the CPK-2442-HITL-option-2-add-new-items branch June 6, 2025 14:12
@coderabbitai coderabbitai Bot mentioned this pull request Oct 13, 2025
2 tasks done

This branch was successfully deployed

14 active deployments
Production – demo-viewer — 486fb7c7 Deployed Jun 6, 2025 by vercel[bot]
Preview – docs — 486fb7c7 Deployed Jun 6, 2025 by vercel[bot]
Preview – examples-coagents-research-canvas-ui — 486fb7c7 Deployed Jun 6, 2025 by vercel[bot]
Preview – examples-coagents-ai-travel-app — 486fb7c7 Deployed Jun 6, 2025 by vercel[bot]
Preview – demo-viewer — 486fb7c7 Deployed Jun 6, 2025 by vercel[bot]
Preview – copilot-kit — 486fb7c7 Deployed Jun 6, 2025 by vercel[bot]
Preview – copilot-kit-qd8p — 486fb7c7 Deployed Jun 6, 2025 by vercel[bot]
Preview – copilotkit-mastra-feature-viewer — 486fb7c7 Deployed Jun 6, 2025 by vercel[bot]
Preview – ag2-starter — 486fb7c7 Deployed Jun 6, 2025 by vercel[bot]
Preview – ag2-feature-viewer — 486fb7c7 Deployed Jun 6, 2025 by vercel[bot]
Preview – copilotkit-feature-viewer — 486fb7c7 Deployed Jun 6, 2025 by vercel[bot]
Preview – copilot-kit-wq8x — 486fb7c7 Deployed Jun 6, 2025 by vercel[bot]
Preview – copilot-mastra-starter — 486fb7c7 Deployed Jun 6, 2025 by vercel[bot]
Preview – coagents-starter-crewai-flows — 486fb7c7 Deployed Jun 6, 2025 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant