Skip to content

The agent engineering platform.

fix async in agent (#1723)

Harrison Chase40e948805549
diff --git a/langchain/agents/agent.py b/langchain/agents/agent.py
index cf9096016a..fa52fe1655 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]