Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:CrewAIInc CrewAI Tool Collection

From Leeroopedia
Revision as of 11:09, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/CrewAIInc_CrewAI_Tool_Collection.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Tool_Management, Data_Structures, Collections
Last Updated 2026-02-11 00:00 GMT

Overview

Concrete enhanced list container for BaseTool instances with name-based access provided by CrewAI.

Description

The ToolCollection class extends Python's built-in list with Generic[T] typing (where T is bound to BaseTool) to provide both index-based and name-based access to tools. It maintains an internal _name_cache dictionary that maps lowercase tool names to tool instances, enabling case-insensitive lookup via tools["search"] syntax alongside traditional tools[0] indexing. All mutating list operations (append, extend, insert, remove, pop, clear) are overridden to keep the name cache synchronized. The class also provides filter_by_names() to create filtered subcollections from a list of names, and filter_where() for custom filtering using callable predicates.

Usage

Import and use ToolCollection when you need to manage a set of CrewAI tools with convenient name-based access and filtering. It is used internally by MCPServerAdapter and other adapters to wrap tool lists, but can also be used directly for custom tool management scenarios.

Code Reference

Source Location

  • Repository: CrewAI
  • File: lib/crewai-tools/src/crewai_tools/adapters/tool_collection.py
  • Lines: 1-79

Signature

class ToolCollection(list, Generic[T]):
    def __init__(self, tools: list[T] | None = None):

Import

from crewai_tools.adapters.tool_collection import ToolCollection

I/O Contract

Inputs

Name Type Required Description
tools None No Initial list of BaseTool instances to populate the collection (default: None, creates empty collection)

Outputs

Name Type Description
__getitem__(int) T Returns tool at the specified integer index
__getitem__(str) T Returns tool matching the name (case-insensitive)
filter_by_names() ToolCollection[T] New ToolCollection containing only tools matching the provided names
filter_where() ToolCollection[T] New ToolCollection containing tools that pass the predicate function

Usage Examples

Basic Usage

from crewai_tools.adapters.tool_collection import ToolCollection

tools = ToolCollection(list_of_tools)

# Access by index
first_tool = tools[0]

# Access by name (case-insensitive)
search_tool = tools["search"]

# Filter by names
subset = tools.filter_by_names(["search", "read_file"])

# Filter with predicate
custom_subset = tools.filter_where(lambda t: "web" in t.name.lower())

Related Pages

  • Principle needed: Tool management and collection patterns for CrewAI

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment