Files
crewAI/crewai/agents/cache/cache_handler.py
João Moura 3f9c4df32d Better agent execution error handling (#54)
A few quality of life improvements around cache handling and repeated tool usage
2024-01-05 11:04:59 -03:00

21 lines
457 B
Python

from typing import Optional
from pydantic import PrivateAttr
class CacheHandler:
"""Callback handler for tool usage."""
_cache: PrivateAttr = {}
def __init__(self):
self._cache = {}
def add(self, tool, input, output):
input = input.strip()
self._cache[f"{tool}-{input}"] = output
def read(self, tool, input) -> Optional[str]:
input = input.strip()
return self._cache.get(f"{tool}-{input}")