Home / Function/ _ahandle_event_for_handler() — langchain Function Reference

_ahandle_event_for_handler() — langchain Function Reference

Architecture documentation for the _ahandle_event_for_handler() function in manager.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  a0a20183_6bd3_06cf_a493_38caccf5bc78["_ahandle_event_for_handler()"]
  35cf5db6_bcb1_b854_6ebb_5e0368e51b58["manager.py"]
  a0a20183_6bd3_06cf_a493_38caccf5bc78 -->|defined in| 35cf5db6_bcb1_b854_6ebb_5e0368e51b58
  a4599a47_aca5_b467_7c4b_86c89fdfcaff["ahandle_event()"]
  a4599a47_aca5_b467_7c4b_86c89fdfcaff -->|calls| a0a20183_6bd3_06cf_a493_38caccf5bc78
  style a0a20183_6bd3_06cf_a493_38caccf5bc78 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/callbacks/manager.py lines 368–417

async def _ahandle_event_for_handler(
    handler: BaseCallbackHandler,
    event_name: str,
    ignore_condition_name: str | None,
    *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)
            elif 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 NotImplementedError as e:
        if event_name == "on_chat_model_start":
            message_strings = [get_buffer_string(m) for m in args[1]]
            await _ahandle_event_for_handler(
                handler,
                "on_llm_start",
                "ignore_llm",
                args[0],
                message_strings,
                *args[2:],
                **kwargs,
            )
        else:
            logger.warning(
                "NotImplementedError in %s.%s callback: %s",
                handler.__class__.__name__,
                event_name,
                repr(e),
            )
    except Exception as e:
        logger.warning(
            "Error in %s.%s callback: %s",
            handler.__class__.__name__,
            event_name,
            repr(e),
        )
        if handler.raise_error:
            raise

Subdomains

Called By

Frequently Asked Questions

What does _ahandle_event_for_handler() do?
_ahandle_event_for_handler() is a function in the langchain codebase, defined in libs/core/langchain_core/callbacks/manager.py.
Where is _ahandle_event_for_handler() defined?
_ahandle_event_for_handler() is defined in libs/core/langchain_core/callbacks/manager.py at line 368.
What calls _ahandle_event_for_handler()?
_ahandle_event_for_handler() is called by 1 function(s): ahandle_event.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free