From 88bad37ec2eb6be227323d6ec46ffbae41e24aa8 Mon Sep 17 00:00:00 2001 From: Harrison Chase Date: Tue, 3 Oct 2023 09:01:05 -0700 Subject: [PATCH] fix get_tool_return (#11346) --- libs/langchain/langchain/agents/agent.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/langchain/langchain/agents/agent.py b/libs/langchain/langchain/agents/agent.py index 47aa3ae9720..662ea5d3650 100644 --- a/libs/langchain/langchain/agents/agent.py +++ b/libs/langchain/langchain/agents/agent.py @@ -1229,11 +1229,14 @@ class AgentExecutor(Chain): """Check if the tool is a returning tool.""" agent_action, observation = next_step_output name_to_tool_map = {tool.name: tool for tool in self.tools} + return_value_key = "output" + if len(self.agent.return_values) > 0: + return_value_key = self.agent.return_values[0] # Invalid tools won't be in the map, so we return False. if agent_action.tool in name_to_tool_map: if name_to_tool_map[agent_action.tool].return_direct: return AgentFinish( - {self.agent.return_values[0]: observation}, + {return_value_key: observation}, "", ) return None