Skip to content

fix: validate tool kwargs even when empty to prevent cryptic TypeError (#4611)#4612

Open
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin/1772131572-fix-recall-memory-tool-4611
Open

fix: validate tool kwargs even when empty to prevent cryptic TypeError (#4611)#4612
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin/1772131572-fix-recall-memory-tool-4611

Conversation

@devin-ai-integration
Copy link
Contributor

fix: validate tool kwargs even when empty to prevent cryptic TypeError (#4611)

Summary

Fixes #4611RecallMemoryTool._run() missing 1 required positional argument: 'queries'.

Root cause: BaseTool._validate_kwargs had a if kwargs and ... guard that skipped schema validation when kwargs was an empty dict {}. In the native tool-calling path, if the LLM sends back empty or malformed arguments, tool.run(**{}) bypasses validation entirely, and _run() is called without required arguments — producing a confusing TypeError instead of a clear ValueError with field-level details.

Fix: Remove the kwargs truthiness check so args_schema.model_validate() always runs when a schema with fields is present. Add if not args: guards in run()/arun() to preserve backwards compatibility for positional-arg calls like tool.run("value").

Applied consistently to all 4 entry points: BaseTool.run, BaseTool.arun, Tool.run, Tool.arun.

Review & Testing Checklist for Human

  • Verify the if not args: guard is safe: When positional args are provided (tool.run("val")), kwargs validation is skipped. Confirm this doesn't allow invalid kwargs to slip through silently in any important code path (the native tool-calling path always uses kwargs, never positional args, so it should be fine).
  • Check for edge cases with tools that have no required fields: Tools with only optional/default fields should still work when called with tool.run()model_validate({}) should return defaults. Worth a quick manual check.
  • Run the full test suite to confirm no regressions beyond what was validated locally (the test_max_usage_count_is_respected VCR test was skipped locally due to missing API key).

Suggested test plan: Create a simple crew with memory=True, give the agent a task that would trigger memory search, and confirm it no longer crashes with the TypeError. The new unit tests cover the direct tool invocation path.

Notes

#4611)

When BaseTool.run() was called with no keyword arguments (empty dict),
_validate_kwargs skipped validation because 'if kwargs' is False for {}.
This meant required schema fields like 'queries' in RecallMemoryTool were
never checked, causing a confusing TypeError:
  '_run() missing 1 required positional argument: queries'

Fix: Remove the 'kwargs' truthiness check so validation always runs when
an args_schema with fields is present. Skip validation only when positional
args are provided (backwards compat for tool.run('value') style calls).

Also adds dedicated test coverage for RecallMemoryTool and RememberTool.

Co-Authored-By: João <joao@crewai.com>
@devin-ai-integration
Copy link
Contributor Author

Prompt hidden (unlisted session)

@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring


from __future__ import annotations

from typing import Any
Comment on lines +13 to +18
from crewai.tools.memory_tools import (
RecallMemorySchema,
RecallMemoryTool,
RememberTool,
create_memory_tools,
)
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.

[BUG] Recall Memory Tool fails with missing required positional argument

0 participants