core[major]: On Tool End Observation Casting Fix (#18798)

This PR updates the on_tool_end handlers to return the raw output from the tool instead of casting it to a string. 

This is technically a breaking change, though it's impact is expected to be somewhat minimal. It will fix behavior in `astream_events` as well.

Fixes the following issue #18760 raised by @eyurtsev

---------

Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
This commit is contained in:
Mohammad Mohtashim
2024-03-11 19:59:04 +05:00
committed by GitHub
parent a96a6e0f2c
commit 43db4cd20e
20 changed files with 42 additions and 34 deletions

View File

@@ -1068,7 +1068,7 @@
"\n",
" def on_tool_end(\n",
" self,\n",
" output: str,\n",
" output: Any,\n",
" *,\n",
" run_id: UUID,\n",
" parent_run_id: Optional[UUID] = None,\n",
@@ -1076,7 +1076,7 @@
" ) -> Any:\n",
" \"\"\"Run when tool ends running.\"\"\"\n",
" print(\"Tool end\")\n",
" print(output)\n",
" print(str(output))\n",
"\n",
" async def on_llm_end(\n",
" self,\n",

View File

@@ -59,7 +59,7 @@ class BaseCallbackHandler:
) -> Any:
"""Run when tool starts running."""
def on_tool_end(self, output: str, **kwargs: Any) -> Any:
def on_tool_end(self, output: Any, **kwargs: Any) -> Any:
"""Run when tool ends running."""
def on_tool_error(