From 40e9488055497a8ba13a35b8106de5dc2ca919f3 Mon Sep 17 00:00:00 2001 From: Harrison Chase Date: Thu, 16 Mar 2023 21:43:22 -0700 Subject: [PATCH] fix async in agent (#1723) --- langchain/agents/agent.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/langchain/agents/agent.py b/langchain/agents/agent.py index cf909601..fa52fe16 100644 --- a/langchain/agents/agent.py +++ b/langchain/agents/agent.py @@ -453,9 +453,15 @@ class AgentExecutor(Chain, BaseModel): # If the tool chosen is the finishing tool, then we end and return. if isinstance(output, AgentFinish): return output - self.callback_manager.on_agent_action( - output, verbose=self.verbose, color="green" - ) + if self.callback_manager.is_async: + await self.callback_manager.on_agent_action( + output, verbose=self.verbose, color="green" + ) + else: + self.callback_manager.on_agent_action( + output, verbose=self.verbose, color="green" + ) + # Otherwise we lookup the tool if output.tool in name_to_tool_map: tool = name_to_tool_map[output.tool]