Skip to content

[BUG] Regression in CrewAI 1.9.3: custom BaseTool wrapper around BedrockKBRetrieverTool gets called without args (_run() missing query) and enters infinite tool-use loop #4495

@jonas-cohen-verbit

Description

@jonas-cohen-verbit

Description

After upgrading CrewAI from 1.6.1 → 1.9.3, a custom tool wrapper around BedrockKBRetrieverTool no longer receives its required query argument. The tool call fails with:
• ParsedBedrockKBRetrieverTool._run() missing 1 required positional argument: 'query'
…and the agent repeatedly attempts to use the tool, effectively entering an infinite tool-calling loop.
In crewai==1.6.1, the same code and workflow work as expected.

The logs also show an events mismatch warning during the loop:
[CrewAIEventsBus] Warning: Event pairing mismatch. 'tool_usage_finished' closed
'flow_started' (expected 'tool_usage_started')
Tool kb_retrieve executed with result: Error executing tool: ParsedBedrockKBRetrieverTool._run() missing 1 required positional argument: 'query'

This looks like a regression in how tool arguments are passed from the agent → tool execution in newer CrewAI versions.

Environment
• crewai==1.9.3 (broken)
• crewai==1.6.1 (works)
• Tool involved: crewai_tools.aws.bedrock.knowledge_base.retriever_tool.BedrockKBRetrieverTool 
• Custom tool extends crewai.tools.BaseTool (wrapper with post-processing)

Steps to Reproduce

  1. Install and run with crewai==1.9.3
    2. Create an agent (in a Crew) that has a tool list including a custom wrapper tool around BedrockKBRetrieverTool.
    3. Ask the agent a question that triggers retrieval from the knowledge base.
    4. Observe that the tool fails with a missing query arg, and the agent repeatedly retries tool usage.

Expected behavior

Expected behavior
• The tool should be invoked with the query argument (as defined by the tool schema), execute once, and return retrieval results (JSON).

Actual behavior
• Tool execution fails because _run() is called without the required query parameter.
• The agent loops, repeatedly trying to use the tool.
• Event bus warning appears: “Event pairing mismatch … expected tool_usage_started”.

Screenshots/Code snippets

from typing import Type
import json
from pydantic import BaseModel, Field, PrivateAttr
from crewai.tools import BaseTool
from crewai_tools.aws.bedrock.knowledge_base.retriever_tool import BedrockKBRetrieverTool

class KBQueryInput(BaseModel):
"""Input schema for KB retrieval tool."""
query: str = Field(..., description="Natural language query for the knowledge base.")

class ParsedBedrockKBRetrieverTool(BaseTool):
name: str = "kb.retrieve"
description: str = "Retrieve from Bedrock KB and parse results into RetrievedRef-shaped objects."
args_schema: Type[BaseModel] = KBQueryInput
_inner: BedrockKBRetrieverTool = PrivateAttr()

def __init__(self, inner: BedrockKBRetrieverTool):
    super().__init__()
    self._inner = inner

def _run(self, query: str) -> str:
    raw = self._inner._run(query)

    try:
        payload = json.loads(raw) if isinstance(raw, str) else raw
    except Exception:
        return json.dumps({"message": "Failed to parse BedrockKBRetrieverTool response as JSON."})

    if not isinstance(payload, dict):
        return json.dumps({"message": "Unexpected BedrockKBRetrieverTool response type."})

    results = payload.get("results")
    if results is None:
        return json.dumps({"message": payload.get("message", "No results found for the given query.")})

    # parsing logic omitted for brevity...
    return json.dumps({"results": results})

def build_kb_retrieval_tool(knowledge_base_id: str, n_results: int = 100) -> BaseTool:
inner = BedrockKBRetrieverTool(
knowledge_base_id=knowledge_base_id,
number_of_results=n_results
)
return ParsedBedrockKBRetrieverTool(inner=inner)

Operating System

Ubuntu 22.04

Python Version

3.12

crewAI Version

1.9.3

crewAI Tools Version

1.9.3

Virtual Environment

Poetry

Evidence

[CrewAIEventsBus] Warning: Event pairing mismatch. 'tool_usage_finished' closed
'flow_started' (expected 'tool_usage_started')
Tool kb_retrieve executed with result: Error executing tool: ParsedBedrockKBRetrieverTool._run() missing 1 required positional argument: 'query'...

Possible Solution

None
in early version its works

Additional context

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions