From c1d1fc13c214008d16850701fc223a32843ac496 Mon Sep 17 00:00:00 2001 From: Jesus Martinez Date: Fri, 19 Jul 2024 21:27:43 -0600 Subject: [PATCH] langchain[patch]: Remove multiagent return_direct validation (#24419) **Description:** When you use Agents with multi-input tool and some of these tools have `return_direct=True`, langchain thrown an error related to one validator. This change is implemented on [JS community](https://github.com/langchain-ai/langchainjs/pull/4643) as well **Issue**: This MR resolves #19843 **Dependencies:** None Co-authored-by: Jesus Martinez Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com> --- libs/langchain/langchain/agents/agent.py | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/libs/langchain/langchain/agents/agent.py b/libs/langchain/langchain/agents/agent.py index 060281f5a37..3e47ac1094f 100644 --- a/libs/langchain/langchain/agents/agent.py +++ b/libs/langchain/langchain/agents/agent.py @@ -1146,30 +1146,6 @@ class AgentExecutor(Chain): ) return values - @root_validator(pre=False, skip_on_failure=True) - def validate_return_direct_tool(cls, values: Dict) -> Dict: - """Validate that tools are compatible with agent. - - Args: - values: Values to validate. - - Returns: - Dict: Validated values. - - Raises: - ValueError: If tools that have `return_direct=True` are not allowed. - """ - agent = values["agent"] - tools = values["tools"] - if isinstance(agent, BaseMultiActionAgent): - for tool in tools: - if tool.return_direct: - raise ValueError( - "Tools that have `return_direct=True` are not allowed " - "in multi-action agents" - ) - return values - @root_validator(pre=True) def validate_runnable_agent(cls, values: Dict) -> Dict: """Convert runnable to agent if passed in.