mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-24 23:58:15 +00:00
Better agent execution error handling (#54)
A few quality of life improvements around cache handling and repeated tool usage
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from .cache_handler import CacheHandler
|
||||
from .cache.cache_handler import CacheHandler
|
||||
from .executor import CrewAgentExecutor
|
||||
from .output_parser import CrewAgentOutputParser
|
||||
from .tools_handler import ToolsHandler
|
||||
|
||||
2
crewai/agents/cache/__init__.py
vendored
Normal file
2
crewai/agents/cache/__init__.py
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
from .cache_handler import CacheHandler
|
||||
from .cache_hit import CacheHit
|
||||
20
crewai/agents/exceptions.py
Normal file
20
crewai/agents/exceptions.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from langchain_core.exceptions import OutputParserException
|
||||
|
||||
|
||||
class TaskRepeatedUsageException(OutputParserException):
|
||||
"""Exception raised when a task is used twice in a roll."""
|
||||
|
||||
error: str = "TaskRepeatedUsageException"
|
||||
message: str = "\nI just used the {tool} tool with input {tool_input}. So I already know the result of that.\n"
|
||||
|
||||
def __init__(self, tool: str, tool_input: str):
|
||||
self.tool = tool
|
||||
self.tool_input = tool_input
|
||||
self.message = self.message.format(tool=tool, tool_input=tool_input)
|
||||
|
||||
super().__init__(
|
||||
error=self.error, observation=self.message, send_to_llm=True, llm_output=""
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return self.message
|
||||
@@ -9,7 +9,7 @@ from langchain_core.exceptions import OutputParserException
|
||||
from langchain_core.tools import BaseTool
|
||||
|
||||
from ..tools.cache_tools import CacheTools
|
||||
from .cache_hit import CacheHit
|
||||
from .cache.cache_hit import CacheHit
|
||||
|
||||
|
||||
class CrewAgentExecutor(AgentExecutor):
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -3,7 +3,7 @@ from typing import Any, Dict
|
||||
from langchain.callbacks.base import BaseCallbackHandler
|
||||
|
||||
from ..tools.cache_tools import CacheTools
|
||||
from .cache_handler import CacheHandler
|
||||
from .cache.cache_handler import CacheHandler
|
||||
|
||||
|
||||
class ToolsHandler(BaseCallbackHandler):
|
||||
|
||||
Reference in New Issue
Block a user