Skip to content

fix: prevent result_as_answer from returning hook-block message as final answer - #5697

Merged
Greyson LaLonde (greysonlalonde) merged 1 commit into
mainfrom
gl/fix/result-as-answer-hook-blocked
May 4, 2026
Merged

Greyson LaLonde (greysonlalonde) merged 1 commit into
mainfrom
gl/fix/result-as-answer-hook-blocked

Conversation

@greysonlalonde

@greysonlalonde Greyson LaLonde (greysonlalonde) commented May 4, 2026 •

Copy link
Copy Markdown
Contributor

Note

Low Risk
Low risk: a small boolean gating change plus a regression test; behavior only changes when a before-tool hook blocks execution.

Overview
Prevents execute_single_native_tool_call from setting result_as_answer=True when a before-tool hook blocks execution, so the hook-block message can’t be returned as the agent’s final answer.

Adds a regression test ensuring result_as_answer stays False for result_as_answer=True tools when blocked by a registered before-hook.

Reviewed by Cursor Bugbot for commit fca3e89. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions github-actions Bot added the size/S label May 4, 2026

@iris-clawd iris-clawd 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.

Tiny, surgical fix. Adding and not hook_blocked to the result_as_answer guard is the obvious correct thing — if a hook blocked execution, the block message should never be treated as the agent's final answer. Test covers it cleanly.

LGTM ✅

@greysonlalonde
Greyson LaLonde (greysonlalonde) merged commit 095f796 into main May 4, 2026
55 checks passed
@greysonlalonde
Greyson LaLonde (greysonlalonde) deleted the gl/fix/result-as-answer-hook-blocked branch May 4, 2026 11:42
电大老baby (HhH666-ux) added a commit to HhH666-ux/crewAI that referenced this pull request Oct 29, 2026
The shared native path (execute_single_native_tool_call) excludes
hook-blocked calls from result_as_answer (crewAIInc#5697), and the ReAct path does
too. AgentExecutor keeps its own copy of that logic and missed the check:
when a before_tool_call hook blocks a tool with result_as_answer=True, the
'Tool execution blocked by hook' notice satisfied the short-circuit
condition (tool_failure is None for a block), became the agent's final
answer, and the model was never called again. Since crewAIInc#8192 made
AgentExecutor the default executor, every function-calling agent hits
this.

Surface hook_blocked on the per-call execution result and require it to
be false in both result_as_answer short-circuit sites, mirroring the
shared path. The block notice still reaches the model as ordinary tool
context and the agent continues.

Fixes crewAIInc#8338
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.

2 participants