Skip to content

Revert "refactor: remove unused and methods from (#5172)"#5243

Merged
lucasgomide merged 2 commits intomainfrom
luzk/revert-remove-unused-code
Apr 2, 2026
Merged

Revert "refactor: remove unused and methods from (#5172)"#5243
lucasgomide merged 2 commits intomainfrom
luzk/revert-remove-unused-code

Conversation

@lucasgomide
Copy link
Copy Markdown
Contributor

@lucasgomide lucasgomide commented Apr 2, 2026

This reverts commit bb9bcd6.

The AgentExecutor is a Flow — its execution is driven by state transitions defined via @router decorators. Here's exactly what happens:

The deleted check_native_todo_completion was the router for the execute_native_tool state:

@router(execute_native_tool)          # ← routes FROM this state
def check_native_todo_completion(
    self,
) -> Literal["todo_satisfied", "todo_not_satisfied"]:

When the agent uses native tool calling (which gpt-5.4-mini does), the execution path is:

call_llm_native_tools → "native_tool_calls" → execute_native_tool → ???

With check_native_todo_completion present, the flow continues:

execute_native_tool → check_native_todo_completion → "todo_satisfied"/"todo_not_satisfied" → ... → eventually  AgentFinish

With it deleted, the Flow has no router registered for the execute_native_tool output. The flow simply stops — it has nowhere to go. At that point, state.current_answer is still an AgentAction (a tool call), not an AgentFinish, so the check at line 2591 raises:

if not isinstance(formatted_answer, AgentFinish):
    raise RuntimeError("Agent execution ended without reaching a final answer.")

The _extract_tool_name helper was also deleted — it's used by other routing logic to figure out which tool was called. Without it, any code path that tries to identify tool calls by name would also break.

In short: deleting these methods broke the Flow's state machine by removing a critical routing node. The agent successfully called a tool, but the Flow had no transition defined for what to do after the tool executed, so it silently exited the loop without a final answer.


Note

Medium Risk
Touches AgentExecutor flow routing for the native tool-calling path; mistakes here could cause executions to stop early or mark todos incorrectly, but the change is small and covered by a targeted unit test.

Overview
Restores missing AgentExecutor Flow nodes for the native tool-calling execution path by re-adding _extract_tool_name and a @router(execute_native_tool) method (check_native_todo_completion).

This ensures that after execute_native_tool runs, the Flow can transition to todo_satisfied/todo_not_satisfied (instead of dead-ending) when todos are active. Adds a regression test validating check_native_todo_completion behavior with and without an active todo.

Written by Cursor Bugbot for commit f121f79. This will update automatically on new commits. Configure here.

@github-actions github-actions bot added the size/S label Apr 2, 2026
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

return sanitize_tool_name(
func_info.get("name", "") or tool_call.get("name", "unknown")
)
return "unknown"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reverted method _extract_tool_name is unused dead code

Low Severity

The _extract_tool_name method is defined but never called anywhere in the codebase — not in production code, not in tests. The similar utility extract_tool_call_info (imported and used throughout the file) already handles tool call info extraction. This is dead code that adds maintenance burden. The original PR (#5172) correctly identified it as unused; reverting it reintroduces the same dead code.

Fix in Cursor Fix in Web

@lucasgomide lucasgomide merged commit 1b7be63 into main Apr 2, 2026
48 checks passed
@lucasgomide lucasgomide deleted the luzk/revert-remove-unused-code branch April 2, 2026 22:03
royzhz pushed a commit to royzhz/crewAI that referenced this pull request Apr 3, 2026
…rewAIInc#5243)

* Revert "refactor: remove unused  and  methods from (crewAIInc#5172)"

This reverts commit bb9bcd6.

* test: fix tests
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