fix: force output visibility for human_input when verbose is False#6243
fix: force output visibility for human_input when verbose is False#6243Gul-A05 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
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.
📝 WalkthroughWalkthroughIn ChangesHuman Input Output Display Fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
lib/crewai/src/crewai/experimental/agent_executor.py (1)
2805-2813: ⚡ Quick winExtract 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
📒 Files selected for processing (2)
lib/crewai/src/crewai/experimental/agent_executor.pytest_bug.py
| 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") |
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
📒 Files selected for processing (1)
lib/crewai/src/crewai/experimental/agent_executor.py
| 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) |
There was a problem hiding this comment.
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.
| 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.
This PR fixes a bug where enabling
human_input=Trueon a task while the agent or crew hasverbose=Falsecauses 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
AgentExecutor.invokeandAgentExecutor.invoke_asyncwithin the experimental agent executor pipeline.Final Answerright before triggering the_handle_human_feedbackprompt, 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
Tests