Files
crewAI/src/crewai/tools/cache_tools.py
Brandon Hancock (bhancock_ai) 5d8f8cbc79 reduce import time by 6x (#1396)
* reduce import by 6x

* fix linting
2024-10-06 17:55:32 -03:00

29 lines
800 B
Python

from pydantic import BaseModel, Field
from crewai.agents.cache import CacheHandler
class CacheTools(BaseModel):
"""Default tools to hit the cache."""
name: str = "Hit Cache"
cache_handler: CacheHandler = Field(
description="Cache Handler for the crew",
default_factory=CacheHandler,
)
def tool(self):
from langchain.tools import StructuredTool
return StructuredTool.from_function(
func=self.hit_cache,
name=self.name,
description="Reads directly from the cache",
)
def hit_cache(self, key):
split = key.split("tool:")
tool = split[1].split("|input:")[0].strip()
tool_input = split[1].split("|input:")[1].strip()
return self.cache_handler.read(tool, tool_input)