Replies: 1 comment 6 replies
-
Hey there, @wuodar! 👋 I'm here to help you with any bugs, questions, or contributions you have in mind. Let's work together to solve the issue you're facing. The
Here is how these attributes are used in the async def _ahandle_event_for_handler(
handler: BaseCallbackHandler,
event_name: str,
ignore_condition_name: Optional[str],
*args: Any,
**kwargs: Any,
) -> None:
try:
if ignore_condition_name is None or not getattr(handler, ignore_condition_name):
event = getattr(handler, event_name)
if asyncio.iscoroutinefunction(event):
await event(*args, **kwargs)
else:
if handler.run_inline:
event(*args, **kwargs)
else:
await asyncio.get_event_loop().run_in_executor(
None,
cast(
Callable,
functools.partial(
copy_context().run, event, *args, **kwargs
),
),
)
except Exception as e:
if handler.raise_error:
raise e In your case, to propagate the error raised in the tool, you should set class MyCustomCallback(BaseCallbackHandler):
raise_error = True
def on_tool_error(self, error: BaseException, **kwargs: Any) -> Any:
logger.error("Tool error", extra={"error": error})
if self.raise_error:
raise error This setup will ensure that the error is logged and then raised if |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Checked other resources
Commit to Help
Example Code
""
Description
BaseCallbackHandler contains two attributes
raise_error
run_inline
Question 1
I see that
run_inline
is being used somewhere in the code, but I don't understand what it actually does?Question 2
Regarding
raise_error
- I don't see it is being used anywhere in the code. I also use langgraph with langchain StructuredTool and when the tool raise an Error, it is not being populated (raised). It is catched somewhere in the code. So my question is, to propagate the Error that was raised in the tool, should I setraise_error
to True, and then in my callback handler implement sth like:Or I'm missing the point and it can be done easier (e.g. by setting some flag or class attribute)?
System Info
""
Beta Was this translation helpful? Give feedback.
All reactions