Skip to content

fix: force output visibility for human_input when verbose is False#6243

Open
Gul-A05 wants to merge 2 commits into
crewAIInc:mainfrom
Gul-A05:fix-human-input-verbose-bug
Open

fix: force output visibility for human_input when verbose is False#6243
Gul-A05 wants to merge 2 commits into
crewAIInc:mainfrom
Gul-A05:fix-human-input-verbose-bug

Conversation

@Gul-A05

@Gul-A05 Gul-A05 commented Jun 19, 2026

Copy link
Copy Markdown

This PR fixes a bug where enabling human_input=True on a task while the agent or crew has verbose=False causes the execution loop to halt and request feedback on a blank terminal screen. Because logs are suppressed, the human reviewer is prompted for input without any context regarding the agent's final answer.

Changes

  • Updated AgentExecutor.invoke and AgentExecutor.invoke_async within the experimental agent executor pipeline.
  • Forced a dedicated print statement displaying the agent's Final Answer right before triggering the _handle_human_feedback prompt, ensuring execution visibility even when global verbosity is disabled.

Testing Done

Verified using a minimal reproduction script containing an agent with a stubbed LLM (verbose=False) and a task (human_input=True). The console successfully prints the final agent output immediately prior to displaying the yellow "Human Feedback Required" panel.

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • When human feedback is enabled, the agent’s final response is now shown immediately in the console (using the formatted “Final Answer” presentation when available) before human feedback is requested and processed.
  • Tests

    • Added a targeted regression test that exercises the human-input flow with a stubbed LLM to ensure the updated console output behavior occurs during execution.

@corridor-security corridor-security Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary: This PR adds console output of the final answer before human feedback prompts and includes a local reproduction script; no exploitable security vulnerabilities were identified.

Risk: Low risk. The change affects local/interactive output behavior and does not introduce new authentication, authorization, data access, SQL, filesystem, or network attack surfaces.

@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

In AgentExecutor.invoke() and invoke_async(), when ask_for_human_input is enabled, the final answer is now printed to the console immediately before _handle_human_feedback / _ahandle_human_feedback is called. A new _force_display_final_answer() helper handles the conditional printing with Rich formatting fallback. A local debug reproduction script (test_bug.py) is also included.

Changes

Human Input Output Display Fix

Layer / File(s) Summary
Force-print final answer before human feedback (sync + async)
lib/crewai/src/crewai/experimental/agent_executor.py
New _force_display_final_answer() helper (line 2935–2941) conditionally prints formatted_answer.output using Rich formatting with plain print fallback. Both invoke() (line 2805–2808) and invoke_async() (line 2913–2916) now call this helper before the human feedback handler when ask_for_human_input is true.
Local reproduction script
test_bug.py
Adds a standalone debug script with hardcoded Windows sys.path entries, a StubLLM returning a fixed "Thought … Final Answer …" string with supports_function_calling=False, and a minimal Agent + Task(human_input=True) + Crew that immediately calls kickoff().

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: forcing output visibility for human input when verbose is disabled. It directly corresponds to the core change in AgentExecutor methods.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
lib/crewai/src/crewai/experimental/agent_executor.py (1)

2805-2813: ⚡ Quick win

Extract forced-answer rendering into one helper and avoid duplicate emission.

The same forced-output block is duplicated in sync/async paths and currently prints the final answer twice. Centralize this into a single helper and do rich-first with plain-print fallback to keep behavior consistent.

Proposed refactor
@@
-                if self.state.ask_for_human_input:
-                            # Force output display using standard print & console utilities
-                            if formatted_answer and hasattr(formatted_answer, "output"):
-                                print(f"\n[FORCED OUTPUT] Final Answer: {formatted_answer.output}\n")
-                                try:
-                                    self._console.print(f"[bold purple]Final Answer:[/bold purple] {formatted_answer.output}")
-                                except Exception:
-                                    pass
-
-                            formatted_answer = self._handle_human_feedback(formatted_answer)
+                if self.state.ask_for_human_input:
+                    self._force_display_final_answer(formatted_answer)
+                    formatted_answer = self._handle_human_feedback(formatted_answer)
@@
-                if self.state.ask_for_human_input:
-                            # Force output display using standard print & console utilities
-                            if formatted_answer and hasattr(formatted_answer, "output"):
-                                print(f"\n[FORCED OUTPUT] Final Answer: {formatted_answer.output}\n")
-                                try:
-                                    self._console.print(f"[bold purple]Final Answer:[/bold purple] {formatted_answer.output}")
-                                except Exception:
-                                    pass
-                                    
-                            formatted_answer = await self._ahandle_human_feedback(
-                                formatted_answer
-                            )
+                if self.state.ask_for_human_input:
+                    self._force_display_final_answer(formatted_answer)
+                    formatted_answer = await self._ahandle_human_feedback(
+                        formatted_answer
+                    )
+
+    def _force_display_final_answer(self, formatted_answer: AgentFinish) -> None:
+        output = formatted_answer.output
+        try:
+            self._console.print(f"[bold purple]Final Answer:[/bold purple] {output}")
+        except Exception:
+            print(f"\nFinal Answer: {output}\n")

Also applies to: 2918-2928

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/crewai/src/crewai/experimental/agent_executor.py` around lines 2805 -
2813, The forced-output rendering code block is duplicated in both sync and
async execution paths (around lines 2805-2813 and 2918-2928), causing the final
answer to be printed twice. Extract this logic into a single helper method
(e.g., _display_forced_answer or similar) that takes the formatted_answer as a
parameter and handles the rich console printing with a fallback to plain print.
Update both occurrences in the sync and async code paths to call this
centralized helper method instead of duplicating the print and console logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test_bug.py`:
- Around line 1-4: Remove the two sys.path.insert() calls on lines 3-4 in
test_bug.py that reference hardcoded Windows paths (C:\Users\zero\crewAI\...).
These machine-specific paths make the test non-portable and
environment-dependent. If these paths are necessary for local development,
either move this code to a separate dev-only script outside the repository, or
replace the hardcoded absolute paths with relative paths computed from the
repository root using appropriate path resolution methods that work
cross-platform.
- Around line 17-23: The Crew instantiation and kickoff() method call are
executing at module import time, which causes the test file to hang during test
discovery when human_input=True is set. Move the entire code block containing
the Task creation and Crew(agents=[agent], tasks=[task],
process=Process.sequential, verbose=False).kickoff() execution inside an if
__name__ == "__main__": guard block so it only runs when the script is executed
directly, not during test collection.

---

Nitpick comments:
In `@lib/crewai/src/crewai/experimental/agent_executor.py`:
- Around line 2805-2813: The forced-output rendering code block is duplicated in
both sync and async execution paths (around lines 2805-2813 and 2918-2928),
causing the final answer to be printed twice. Extract this logic into a single
helper method (e.g., _display_forced_answer or similar) that takes the
formatted_answer as a parameter and handles the rich console printing with a
fallback to plain print. Update both occurrences in the sync and async code
paths to call this centralized helper method instead of duplicating the print
and console logic.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b8f574c3-2e84-427d-8b3e-9901a606c90a

📥 Commits

Reviewing files that changed from the base of the PR and between 854c67d and d84c8be.

📒 Files selected for processing (2)
  • lib/crewai/src/crewai/experimental/agent_executor.py
  • test_bug.py

Comment thread test_bug.py
Comment on lines +1 to +4
import sys
# Forcing Python to read the precise source directories for both components
sys.path.insert(0, r"C:\Users\zero\crewAI\lib\crewai\src")
sys.path.insert(0, r"C:\Users\zero\crewAI\lib\crewai-core\src")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Remove machine-specific sys.path injection from committed test code.

Hardcoded local Windows paths are not portable and can cause environment-dependent import behavior. If this is a local repro utility, keep it out of the repository test surface or resolve paths relative to repo root in a dev-only script.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test_bug.py` around lines 1 - 4, Remove the two sys.path.insert() calls on
lines 3-4 in test_bug.py that reference hardcoded Windows paths
(C:\Users\zero\crewAI\...). These machine-specific paths make the test
non-portable and environment-dependent. If these paths are necessary for local
development, either move this code to a separate dev-only script outside the
repository, or replace the hardcoded absolute paths with relative paths computed
from the repository root using appropriate path resolution methods that work
cross-platform.

Comment thread test_bug.py
Comment on lines +17 to +23
agent = Agent(role="Tester", goal="Be a Minimal Reproduction", backstory="bg",
llm=StubLLM(model="stub"), verbose=False)

task = Task(description="Sky colour?", expected_output="a colour",
agent=agent, human_input=True)

Crew(agents=[agent], tasks=[task], process=Process.sequential, verbose=False).kickoff() No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Avoid import-time interactive execution in a test_*.py file.

This executes kickoff() at module import with human_input=True, which can hang automated test runs during discovery. Move execution behind if __name__ == "__main__": and keep it out of default test collection.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test_bug.py` around lines 17 - 23, The Crew instantiation and kickoff()
method call are executing at module import time, which causes the test file to
hang during test discovery when human_input=True is set. Move the entire code
block containing the Task creation and Crew(agents=[agent], tasks=[task],
process=Process.sequential, verbose=False).kickoff() execution inside an if
__name__ == "__main__": guard block so it only runs when the script is executed
directly, not during test collection.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/crewai/src/crewai/experimental/agent_executor.py`:
- Around line 2804-2808: Remove the duplicate invocation of the
_handle_human_feedback method in the ask_for_human_input branch. Within the if
self.state.ask_for_human_input block, there are two consecutive calls to
_handle_human_feedback(formatted_answer) on separate lines (lines 2806 and
2808). Delete the second duplicate call on line 2808 so that
_handle_human_feedback is only invoked once after _force_display_final_answer,
ensuring the user is only prompted for human feedback one time instead of two.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 0061880a-e224-451c-8c63-9549a42f4f42

📥 Commits

Reviewing files that changed from the base of the PR and between d84c8be and 08d009a.

📒 Files selected for processing (1)
  • lib/crewai/src/crewai/experimental/agent_executor.py

Comment on lines 2804 to +2808
if self.state.ask_for_human_input:
formatted_answer = self._handle_human_feedback(formatted_answer)
self._force_display_final_answer(formatted_answer)
formatted_answer = self._handle_human_feedback(formatted_answer)

formatted_answer = self._handle_human_feedback(formatted_answer)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Remove the duplicate human-feedback invocation in sync flow.

formatted_answer is passed to _handle_human_feedback(...) twice in the ask_for_human_input branch (Line 2806 and Line 2808), which can trigger two prompts/loops instead of one.

Suggested fix
                 if self.state.ask_for_human_input:
-                            self._force_display_final_answer(formatted_answer)
-                            formatted_answer = self._handle_human_feedback(formatted_answer)
-
-                            formatted_answer = self._handle_human_feedback(formatted_answer)
+                    self._force_display_final_answer(formatted_answer)
+                    formatted_answer = self._handle_human_feedback(formatted_answer)
📝 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
if self.state.ask_for_human_input:
formatted_answer = self._handle_human_feedback(formatted_answer)
self._force_display_final_answer(formatted_answer)
formatted_answer = self._handle_human_feedback(formatted_answer)
formatted_answer = self._handle_human_feedback(formatted_answer)
if self.state.ask_for_human_input:
self._force_display_final_answer(formatted_answer)
formatted_answer = self._handle_human_feedback(formatted_answer)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/crewai/src/crewai/experimental/agent_executor.py` around lines 2804 -
2808, Remove the duplicate invocation of the _handle_human_feedback method in
the ask_for_human_input branch. Within the if self.state.ask_for_human_input
block, there are two consecutive calls to
_handle_human_feedback(formatted_answer) on separate lines (lines 2806 and
2808). Delete the second duplicate call on line 2808 so that
_handle_human_feedback is only invoked once after _force_display_final_answer,
ensuring the user is only prompted for human feedback one time instead of two.

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.

1 participant