Refactoring task cache to be a tool (#50)

* Refactoring task cache to be a tool

The previous implementation of the task caching system was early exiting
the agent executor due to the fact it was returning an AgentFinish object.

This now refactors it to use a cache specific tool that is dynamically
added and forced into the agent in case of a task execution that was
already executed with the same input.
This commit is contained in:
João Moura
2024-01-04 21:29:42 -03:00
committed by GitHub
parent 35f4169d6a
commit 5602160caf
12 changed files with 1851 additions and 576 deletions

View File

@@ -2,6 +2,7 @@ from typing import Any, Dict
from langchain.callbacks.base import BaseCallbackHandler
from ..tools.cache_tools import CacheTools
from .cache_handler import CacheHandler
@@ -35,8 +36,9 @@ class ToolsHandler(BaseCallbackHandler):
and "Invalid or incomplete response" not in output
and "Invalid Format" not in output
):
self.cache.add(
tool=self.last_used_tool["tool"],
input=self.last_used_tool["input"],
output=output,
)
if self.last_used_tool["tool"] != CacheTools().name:
self.cache.add(
tool=self.last_used_tool["tool"],
input=self.last_used_tool["input"],
output=output,
)