add explicit agent end method (#486)

This commit is contained in:
Harrison Chase
2022-12-29 22:23:15 -05:00
committed by GitHub
parent 7e36f28e78
commit 52490e2dcd
7 changed files with 39 additions and 22 deletions

View File

@@ -90,8 +90,9 @@ def test_agent_with_callbacks() -> None:
output = agent.run("when was langchain made")
assert output == "curses foiled again"
# 1 top level chain run, 2 LLMChain runs, 2 LLM runs, 1 tool run, 1 ending
assert handler.starts == 7
# 1 top level chain run, 2 LLMChain runs, 2 LLM runs, 1 tool run
assert handler.starts == 6
# 1 extra agent end
assert handler.ends == 7
assert handler.errors == 0

View File

@@ -58,3 +58,7 @@ class FakeCallbackHandler(BaseCallbackHandler):
def on_tool_error(self, error: Exception) -> None:
"""Run when tool errors."""
self.errors += 1
def on_agent_end(self, log: str, **kwargs: Any) -> None:
"""Run when agent is ending."""
self.ends += 1