StdOutCallbackHandler Class — langchain Architecture
Architecture documentation for the StdOutCallbackHandler class in stdout.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD dcf2a9b2_8ab4_fbe0_5f57_ef548417d10e["StdOutCallbackHandler"] af283d05_75a6_5813_267b_f03a32501460["BaseCallbackHandler"] dcf2a9b2_8ab4_fbe0_5f57_ef548417d10e -->|extends| af283d05_75a6_5813_267b_f03a32501460 0ac81bdf_4e75_0bc6_a08b_3f201a8e9da1["stdout.py"] dcf2a9b2_8ab4_fbe0_5f57_ef548417d10e -->|defined in| 0ac81bdf_4e75_0bc6_a08b_3f201a8e9da1 706efa82_e825_167a_0237_a721f8185def["__init__()"] dcf2a9b2_8ab4_fbe0_5f57_ef548417d10e -->|method| 706efa82_e825_167a_0237_a721f8185def 8245925b_379e_91d8_182e_d404bc9515ee["on_chain_start()"] dcf2a9b2_8ab4_fbe0_5f57_ef548417d10e -->|method| 8245925b_379e_91d8_182e_d404bc9515ee d49bad0e_757b_b92c_a5da_4c3d949372f3["on_chain_end()"] dcf2a9b2_8ab4_fbe0_5f57_ef548417d10e -->|method| d49bad0e_757b_b92c_a5da_4c3d949372f3 6d45cae6_dc82_8565_0075_94e95353b674["on_agent_action()"] dcf2a9b2_8ab4_fbe0_5f57_ef548417d10e -->|method| 6d45cae6_dc82_8565_0075_94e95353b674 9b871232_001e_2f5e_a2c6_e390b77ed440["on_tool_end()"] dcf2a9b2_8ab4_fbe0_5f57_ef548417d10e -->|method| 9b871232_001e_2f5e_a2c6_e390b77ed440 c011477e_678b_fe9a_e5b4_f9b294075a13["on_text()"] dcf2a9b2_8ab4_fbe0_5f57_ef548417d10e -->|method| c011477e_678b_fe9a_e5b4_f9b294075a13 515de6a0_4d8b_67cc_455a_065218e2e8c7["on_agent_finish()"] dcf2a9b2_8ab4_fbe0_5f57_ef548417d10e -->|method| 515de6a0_4d8b_67cc_455a_065218e2e8c7
Relationship Graph
Source Code
libs/core/langchain_core/callbacks/stdout.py lines 16–123
class StdOutCallbackHandler(BaseCallbackHandler):
"""Callback handler that prints to std out."""
def __init__(self, color: str | None = None) -> None:
"""Initialize callback handler.
Args:
color: The color to use for the text.
"""
self.color = color
@override
def on_chain_start(
self, serialized: dict[str, Any], inputs: dict[str, Any], **kwargs: Any
) -> None:
"""Print out that we are entering a chain.
Args:
serialized: The serialized chain.
inputs: The inputs to the chain.
**kwargs: Additional keyword arguments.
"""
if "name" in kwargs:
name = kwargs["name"]
elif serialized:
name = serialized.get("name", serialized.get("id", ["<unknown>"])[-1])
else:
name = "<unknown>"
print(f"\n\n\033[1m> Entering new {name} chain...\033[0m") # noqa: T201
@override
def on_chain_end(self, outputs: dict[str, Any], **kwargs: Any) -> None:
"""Print out that we finished a chain.
Args:
outputs: The outputs of the chain.
**kwargs: Additional keyword arguments.
"""
print("\n\033[1m> Finished chain.\033[0m") # noqa: T201
@override
def on_agent_action(
self, action: AgentAction, color: str | None = None, **kwargs: Any
) -> Any:
"""Run on agent action.
Args:
action: The agent action.
color: The color to use for the text.
**kwargs: Additional keyword arguments.
"""
print_text(action.log, color=color or self.color)
@override
def on_tool_end(
self,
output: Any,
color: str | None = None,
observation_prefix: str | None = None,
llm_prefix: str | None = None,
**kwargs: Any,
) -> None:
"""If not the final action, print out observation.
Args:
output: The output to print.
color: The color to use for the text.
observation_prefix: The observation prefix.
llm_prefix: The LLM prefix.
**kwargs: Additional keyword arguments.
"""
output = str(output)
if observation_prefix is not None:
print_text(f"\n{observation_prefix}")
print_text(output, color=color or self.color)
if llm_prefix is not None:
print_text(f"\n{llm_prefix}")
@override
def on_text(
self,
Defined In
Extends
Source
Frequently Asked Questions
What is the StdOutCallbackHandler class?
StdOutCallbackHandler is a class in the langchain codebase, defined in libs/core/langchain_core/callbacks/stdout.py.
Where is StdOutCallbackHandler defined?
StdOutCallbackHandler is defined in libs/core/langchain_core/callbacks/stdout.py at line 16.
What does StdOutCallbackHandler extend?
StdOutCallbackHandler extends BaseCallbackHandler.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free