Better agent execution error handling (#54)

A few quality of life improvements around cache handling and repeated tool usage
This commit is contained in:
João Moura
2024-01-05 11:04:59 -03:00
committed by GitHub
parent 6b054651a7
commit 3f9c4df32d
16 changed files with 38 additions and 43 deletions

View File

@@ -3,10 +3,9 @@ from typing import Union
from langchain.agents.output_parsers import ReActSingleInputOutputParser
from langchain_core.agents import AgentAction, AgentFinish
from langchain_core.exceptions import OutputParserException
from .cache_handler import CacheHandler
from .cache_hit import CacheHit
from .cache import CacheHandler, CacheHit
from .exceptions import TaskRepeatedUsageException
from .tools_handler import ToolsHandler
FINAL_ANSWER_ACTION = "Final Answer:"
@@ -67,9 +66,7 @@ class CrewAgentOutputParser(ReActSingleInputOutputParser):
"input": tool_input,
}
if usage == last_tool_usage:
raise OutputParserException(
f"""\nI just used the {action} tool with input {tool_input}. So I already know the result of that."""
)
raise TaskRepeatedUsageException(tool=action, tool_input=tool_input)
result = self.cache.read(action, tool_input)
if result: