crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

[BUG] Anthropic tool_search given as a dict is silently disabled

Open heyseere opened this issue 1 month ago • 2 comments

Label: llm-generated — this report was produced with AI assistance (ZCode agent) and human-reviewed. Please apply the llm-generated label.

Problem

When tool_search is passed as a dict (e.g. from a YAML agent config, where the llm: block arrives as plain dicts), the pre-validator in lib/crewai/src/crewai/llms/providers/anthropic/completion.py drops it to None, silently disabling tool search with no warning:

ts = data.get("tool_search")
if ts is True:
    data["tool_search"] = AnthropicToolSearchConfig()
elif ts is not None and not isinstance(ts, AnthropicToolSearchConfig):
    data["tool_search"] = None   # dicts are actively discarded here

Reproduction

from crewai import LLM

llm = LLM(model="anthropic/claude-sonnet-4-5", tool_search={"type": "regex"})
print(llm.tool_search)  # None (expected: AnthropicToolSearchConfig(type="regex"))

No model call or credentials are needed.

Expected behavior

The field is annotated AnthropicToolSearchConfig | None; a valid dict should be coerced by pydantic and an invalid one should fail loudly. True keeps meaning "default variant" and False/None keep disabling.

Bounded scope

Fix the pre-validator only: special-case True and False, and let the field itself coerce/validate dict inputs. A PR with regression tests is attached.

heyseere avatar Oct 28 '26 16:10 heyseere

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Nov 28 '26 12:11 github-actions[bot]

Related fix is up for review in #8738 (dict tool_search config is coerced instead of silently disabled). Happy to iterate there.

heyseere avatar Nov 30 '26 09:11 heyseere