Home / Class/ ContextTestHandler Class — langchain Architecture

ContextTestHandler Class — langchain Architecture

Architecture documentation for the ContextTestHandler class in test_async_callback_manager.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  c2677f9e_671b_f79c_68a2_698cec0b8129["ContextTestHandler"]
  64513429_d001_87b1_5f19_cc17a3f3577b["AsyncCallbackHandler"]
  c2677f9e_671b_f79c_68a2_698cec0b8129 -->|extends| 64513429_d001_87b1_5f19_cc17a3f3577b
  f1a09d1e_2693_1456_76d6_3f34ca061a65["test_async_callback_manager.py"]
  c2677f9e_671b_f79c_68a2_698cec0b8129 -->|defined in| f1a09d1e_2693_1456_76d6_3f34ca061a65
  a8bfe441_61ea_66ff_e59e_8b9e17a5e63f["__init__()"]
  c2677f9e_671b_f79c_68a2_698cec0b8129 -->|method| a8bfe441_61ea_66ff_e59e_8b9e17a5e63f
  04fc3b21_48f4_024e_026e_0e95026ac119["on_llm_end()"]
  c2677f9e_671b_f79c_68a2_698cec0b8129 -->|method| 04fc3b21_48f4_024e_026e_0e95026ac119
  000bca7f_11b5_0c40_88ed_3a18292895b8["on_chain_end()"]
  c2677f9e_671b_f79c_68a2_698cec0b8129 -->|method| 000bca7f_11b5_0c40_88ed_3a18292895b8

Relationship Graph

Source Code

libs/core/tests/unit_tests/callbacks/test_async_callback_manager.py lines 170–187

    class ContextTestHandler(AsyncCallbackHandler):
        """Handler that reads context variables in shielded callbacks."""

        def __init__(self) -> None:
            self.run_inline = False
            self.context_values: list[str] = []

        @override
        async def on_llm_end(self, response: Any, **kwargs: Any) -> None:
            """This method is decorated with @shielded in the run manager."""
            # This should preserve the context variable value
            self.context_values.append(context_var.get("not_found"))

        @override
        async def on_chain_end(self, outputs: Any, **kwargs: Any) -> None:
            """This method is decorated with @shielded in the run manager."""
            # This should preserve the context variable value
            self.context_values.append(context_var.get("not_found"))

Frequently Asked Questions

What is the ContextTestHandler class?
ContextTestHandler is a class in the langchain codebase, defined in libs/core/tests/unit_tests/callbacks/test_async_callback_manager.py.
Where is ContextTestHandler defined?
ContextTestHandler is defined in libs/core/tests/unit_tests/callbacks/test_async_callback_manager.py at line 170.
What does ContextTestHandler extend?
ContextTestHandler extends AsyncCallbackHandler.

Analyze Your Own Codebase

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

Try Supermodel Free