Skip to content

feat: human-in-the-loop (user input)#1420

Merged
EItanya merged 6 commits intokagent-dev:mainfrom
supreme-gg-gg:feat/hitl
Mar 4, 2026
Merged

feat: human-in-the-loop (user input)#1420
EItanya merged 6 commits intokagent-dev:mainfrom
supreme-gg-gg:feat/hitl

Conversation

@supreme-gg-gg
Copy link
Contributor

Signed-off-by: Jet Chiang <pokyuen.jetchiang-ext@solo.io>
Signed-off-by: Jet Chiang <pokyuen.jetchiang-ext@solo.io>
Signed-off-by: Jet Chiang <pokyuen.jetchiang-ext@solo.io>
Copilot AI review requested due to automatic review settings March 3, 2026 21:29
@supreme-gg-gg
Copy link
Contributor Author

Screenshot 2026-03-03 at 4 24 21 PM

^ This is how the tool looks like in the new UI component. The flow follows pretty much exactly as existing HITL.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds two HITL (human-in-the-loop) enhancements: (1) a built-in ask_user tool that lets the agent pose questions to the user with optional predefined choices, and (2) optional rejection reasons for tool approval denials that are passed to the LLM as context.

Changes:

  • New AskUserTool (Python) and AskUserDisplay (React) that use the existing request_confirmation plumbing to interrupt execution and collect structured answers from the user
  • Rejection reason support: UI collects per-tool free-text reasons on rejection; backend reads and attaches them to ToolConfirmation.payload so the LLM sees them

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
python/packages/kagent-adk/src/kagent/adk/tools/ask_user_tool.py New built-in AskUserTool implementing the two-phase request_confirmation pattern
python/packages/kagent-adk/src/kagent/adk/types.py Appends AskUserTool unconditionally to every agent's tool list
python/packages/kagent-adk/src/kagent/adk/_agent_executor.py Adds ask-user answers extraction/routing in _process_hitl_decision; attaches rejection reasons to ToolConfirmation.payload for batch and uniform denials
python/packages/kagent-adk/src/kagent/adk/_approval.py Changes rejection callback return type from dict to string; includes optional rejection_reason from payload
python/packages/kagent-core/src/kagent/core/a2a/_hitl.py Adds extract_rejection_reasons_from_message and extract_ask_user_answers_from_message helpers
python/packages/kagent-core/src/kagent/core/a2a/_consts.py New constants: KAGENT_HITL_REJECTION_REASONS_KEY, KAGENT_ASK_USER_TOOL_NAME, KAGENT_ASK_USER_ANSWERS_KEY
python/packages/kagent-core/src/kagent/core/a2a/__init__.py Exports new constants and utility functions
python/packages/kagent-adk/tests/unittests/test_hitl.py New tests for rejection with reason, batch per-tool reasons, ask-user answer flow; updates test assertions for string-return rejection
ui/src/components/chat/AskUserDisplay.tsx New React component rendering interactive question chips and free-text input
ui/src/components/chat/ChatMessage.tsx Routes AskUserRequest messages to AskUserDisplay; adds onAskUserSubmit prop
ui/src/components/chat/ChatInterface.tsx Adds handleAskUserSubmit, pendingRejectionReasons state, and rejection-reason propagation in submitDecisions
ui/src/components/chat/ToolCallDisplay.tsx Threads optional reason through onReject callback signature
ui/src/components/ToolDisplay.tsx Adds "Reject" two-step flow (button → textarea → confirm/cancel) with optional reason
ui/src/lib/messageHandlers.ts buildApprovalMessage branches on ask_user name; adds AskUserRequest to OriginalMessageType; skips pending function-response status
python/packages/kagent-adk/src/kagent/adk/_memory_service.py Adds gemini provider case to the LiteLLM model identifier builder
docs/architecture/human-in-the-loop.md Documents new "Rejection Reasons" and "Ask-User Tool" enhancements

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Signed-off-by: Jet Chiang <pokyuen.jetchiang-ext@solo.io>
@EItanya
Copy link
Contributor

EItanya commented Mar 4, 2026

2 quick things:

  1. I think we can make the UX slightly better for the forms, but that can happen in a follow-up
  2. I think it's a bit confusing that the ask_user tool shows up in the list of called tools, it's really an internal detail and we should just surface the questions, not the tool call.

Signed-off-by: Jet Chiang <pokyuen.jetchiang-ext@solo.io>
@supreme-gg-gg
Copy link
Contributor Author

2 quick things:

  1. I think we can make the UX slightly better for the forms, but that can happen in a follow-up
  2. I think it's a bit confusing that the ask_user tool shows up in the list of called tools, it's really an internal detail and we should just surface the questions, not the tool call.

yea fixed 2, skipped showing ask user function call.

For 1 do you have any specific ideas for what we need for better UX? I mainly copied the design from open code / claudecode where there's multi-select, single-select, or type your own option.

@EItanya
Copy link
Contributor

EItanya commented Mar 4, 2026

2 quick things:

  1. I think we can make the UX slightly better for the forms, but that can happen in a follow-up
  2. I think it's a bit confusing that the ask_user tool shows up in the list of called tools, it's really an internal detail and we should just surface the questions, not the tool call.

yea fixed 2, skipped showing ask user function call.

For 1 do you have any specific ideas for what we need for better UX? I mainly copied the design from open code / claudecode where there's multi-select, single-select, or type your own option.

Sorry, I meant UI, not UX, the feature makes sense as written

@EItanya EItanya merged commit 92f6283 into kagent-dev:main Mar 4, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants