LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangChain
  • Browser
  • Universal
  • Hub
  • Node
  • Load
  • Serializable
  • Encoder Backed
  • File System
  • In Memory
  • Tools
LangChain Core
  • Agents
  • Caches
  • Base
  • Dispatch
  • Web
  • Manager
  • Promises
  • Chat History
  • Context
  • Base
  • Langsmith
  • Documents
  • Embeddings
  • Errors
  • Example Selectors
  • Indexing
  • Base
  • Chat Models
  • Compat
  • Event
  • Llms
  • Openai Completions Stream
  • Profile
  • Stream
  • Structured Output
  • Load
  • Serializable
  • Memory
  • Messages
  • Tool
  • Output Parsers
  • Openai Functions
  • Openai Tools
  • Outputs
  • Prompt Values
  • Prompts
  • Retrievers
  • Document Compressors
  • Runnables
  • Graph
  • Singletons
  • Stores
  • Structured Query
  • Testing
  • Tools
  • Base
  • Console
  • Log Stream
  • Run Collector
  • Tracer Langchain
  • Stream
  • Async Caller
  • Chunk Array
  • Context
  • Env
  • Event Source Parse
  • Format
  • Function Calling
  • Gateway
  • Hash
  • Json Patch
  • Json Schema
  • Math
  • Ssrf
  • Standard Schema
  • Stream
  • Testing
  • Tiktoken
  • Types
  • Uuid
  • Vectorstores
Text Splitters
MCP Adapters
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

LangChain
BrowserUniversalHubNodeLoadSerializableEncoder BackedFile SystemIn MemoryTools
LangChain Core
AgentsCachesBaseDispatchWebManagerPromisesChat HistoryContextBaseLangsmithDocumentsEmbeddingsErrorsExample SelectorsIndexingBaseChat ModelsCompatEventLlmsOpenai Completions StreamProfileStreamStructured OutputLoadSerializableMemoryMessagesToolOutput ParsersOpenai FunctionsOpenai ToolsOutputsPrompt ValuesPromptsRetrieversDocument CompressorsRunnablesGraphSingletonsStoresStructured QueryTestingToolsBaseConsoleLog StreamRun CollectorTracer LangchainStreamAsync CallerChunk ArrayContextEnvEvent Source ParseFormatFunction CallingGatewayHashJson PatchJson SchemaMathSsrfStandard SchemaStreamTestingTiktokenTypesUuidVectorstores
Text Splitters
MCP Adapters
Language
Theme
JavaScript@langchain/coretracersconsoleConsoleCallbackHandler
Class●Since v1.0

ConsoleCallbackHandler

A tracer that logs all events to the console. It extends from the BaseTracer class and overrides its methods to provide custom logging functionality.

Copy
class ConsoleCallbackHandler

Bases

BaseTracer

Example

Copy
const llm = new ChatAnthropic({
  temperature: 0,
  tags: ["example", "callbacks", "constructor"],
  callbacks: [new ConsoleCallbackHandler()],
});

Constructors

constructor
constructor→ ConsoleCallbackHandler

Properties

property
awaitHandlers: boolean
property
ignoreAgent: boolean
property
ignoreChain: boolean
property
ignoreCustomEvent: boolean
property
ignoreLLM: boolean
property
ignoreRetriever: boolean
property
lc_kwargs: SerializedFields
property
lc_serializable: boolean
property
name: "console_callback_handler"
property
raiseError: boolean
property
runTreeMap: Map<string, RunTree>
property
usesRunTreeMap: boolean
property
lc_aliases: __type | undefined
property
lc_attributes: __type | undefined
property
lc_id: string[]
property
lc_namespace: ["langchain_core", "callbacks", string]

A path to the module that contains the class, eg. ["langchain", "llms"] Usually should be the same as the entrypoint the class is exported from.

property
lc_secrets: __type | undefined
property
lc_serializable_keys: string[] | undefined
deprecatedproperty
runMap: Map<string, Run>

Methods

method
_addChildRun
method
_addRunToRunMap→ __type
method
_createRunForChainStart→ __type

Create and add a run to the run map for chain start events. This must sometimes be done synchronously to avoid race conditions when callbacks are backgrounded, so we expose it as a separate method here.

method
_createRunForChatModelStart→ __type

Create and add a run to the run map for chat model start events. This must sometimes be done synchronously to avoid race conditions when callbacks are backgrounded, so we expose it as a separate method here.

method
_createRunForLLMStart→ __type

Create and add a run to the run map for LLM start events. This must sometimes be done synchronously to avoid race conditions when callbacks are backgrounded, so we expose it as a separate method here.

method
_createRunForRetrieverStart→ __type

Create and add a run to the run map for retriever start events. This must sometimes be done synchronously to avoid race conditions when callbacks are backgrounded, so we expose it as a separate method here.

method
_createRunForToolStart→ __type

Create and add a run to the run map for tool start events. This must sometimes be done synchronously to avoid race conditions when callbacks are backgrounded, so we expose it as a separate method here.

method
_endTrace→ Promise<void>
method
_getExecutionOrder→ number
method
copy→ this
method
getBreadcrumbs→ string

Method used to get a string representation of the run's lineage, which is used in logging.

method
getParents→ Run[]

Method used to get all the parent runs of a given run.

method
getRunById→ Run | undefined
method
handleAgentAction→ Promise<void>

Called when an agent is about to execute an action, with the action and the run ID.

method
handleAgentEnd→ Promise<void>

Called when an agent finishes execution, before it exits. with the final output and the run ID.

method
handleChainEnd→ Promise<Run>

Called at the end of a Chain run, with the outputs and the run ID.

method
handleChainError→ Promise<Run>

Called if a Chain run encounters an error

method
handleChainStart→ Promise<Run>

Called at the start of a Chain run, with the chain name and inputs and the run ID.

method
handleChatModelStart→ Promise<Run>

Called at the start of a Chat Model run, with the prompt(s) and the run ID.

method
handleChatModelStreamEvent→ any

Called when a Chat Model emits a content-block-centric stream event.

method
handleCustomEvent→ any
method
handleLLMEnd→ Promise<Run>

Called at the end of an LLM/ChatModel run, with the output and the run ID.

method
handleLLMError→ Promise<Run>

Called if an LLM/ChatModel run encounters an error

method
handleLLMNewToken→ Promise<Run>

Called when an LLM/ChatModel in streaming mode produces a new token

method
handleLLMStart→ Promise<Run>

Called at the start of an LLM or Chat Model run, with the prompt(s) and the run ID.

method
handleRetrieverEnd→ Promise<Run>
method
handleRetrieverError→ Promise<Run>
method
handleRetrieverStart→ Promise<Run>
method
handleText→ Promise<void>
method
handleToolEnd→ Promise<Run>

Called at the end of a Tool run, with the tool output and the run ID.

method
handleToolError→ Promise<Run>

Called if a Tool run encounters an error

method
handleToolEvent→ any

Called when a streaming tool yields a partial value. Tools that are async generators invoke this once per yielded value.

method
handleToolStart→ Promise<Run>

Called at the start of a Tool run, with the tool name and input and the run ID.

method
onAgentAction

Method used to log the action selected by the agent.

method
onAgentEnd→ void | Promise<void>
method
onChainEnd

Method used to log the end of a chain run.

method
onChainError

Method used to log any errors of a chain run.

method
onChainStart

Method used to log the start of a chain run.

method
onLLMEnd

Method used to log the end of an LLM run.

method
onLLMError

Method used to log any errors of an LLM run.

method
onLLMNewToken→ void | Promise<void>
method
onLLMStart

Method used to log the start of an LLM run.

method
onRetrieverEnd

Method used to log the end of a retriever run.

method
onRetrieverError

Method used to log any errors of a retriever run.

method
onRetrieverStart

Method used to log the start of a retriever run.

method
onRunCreate→ void | Promise<void>
method
onRunUpdate→ void | Promise<void>
method
onText→ void | Promise<void>
method
onToolEnd

Method used to log the end of a tool run.

method
onToolError

Method used to log any errors of a tool run.

method
onToolStart

Method used to log the start of a tool run.

method
persistRun→ Promise<void>

Method used to persist the run. In this case, it simply returns a resolved promise as there's no persistence logic.

method
stringifyError→ string
method
toJSON→ Serialized
method
toJSONNotImplemented→ SerializedNotImplemented
method
fromMethods→ Handler
method
lc_name→ string

The name of the serializable. Override to provide an alias or to preserve the serialized module name in minified environments.

Implemented as a static method to support loading logic.

Inherited fromBaseTracer

Properties

PawaitHandlers: booleanPignoreAgent: booleanPignoreChain: booleanPignoreCustomEvent: booleanPignoreLLM: booleanPignoreRetriever: booleanPlc_kwargs: SerializedFieldsPlc_serializable: booleanPname: stringPraiseError: booleanPrunMap: Map<string, Run>PrunTreeMap: Map<string, RunTree>PusesRunTreeMap: booleanPlc_aliases: __type | undefinedPlc_attributes: __type | undefinedPlc_id: string[]Plc_namespace: ["langchain_core", "callbacks", string]
—

A path to the module that contains the class, eg. ["langchain", "llms"]

Plc_secrets: __type | undefinedPlc_serializable_keys: string[] | undefined

Methods

M_addChildRunM_addRunToRunMap→ __typeM_createRunForChainStart→ __type
—

Create and add a run to the run map for chain start events.

M_createRunForChatModelStart→ __type
—

Create and add a run to the run map for chat model start events.

M_createRunForLLMStart→ __type
—

Create and add a run to the run map for LLM start events.

M_createRunForRetrieverStart→ __type
—

Create and add a run to the run map for retriever start events.

M_createRunForToolStart→ __type
—

Create and add a run to the run map for tool start events.

M_endTrace→ Promise<void>M_getExecutionOrder→ numberMcopy→ thisMgetRunById→ Run | undefinedMhandleAgentAction→ Promise<void>
—

Called when an agent is about to execute an action,

MhandleAgentEnd→ Promise<void>
—

Called when an agent finishes execution, before it exits.

MhandleChainEnd→ Promise<Run>
—

Called at the end of a Chain run, with the outputs and the run ID.

MhandleChainError→ Promise<Run>
—

Called if a Chain run encounters an error

MhandleChainStart→ Promise<Run>
—

Called at the start of a Chain run, with the chain name and inputs

MhandleChatModelStart→ Promise<Run>
—

Called at the start of a Chat Model run, with the prompt(s)

MhandleChatModelStreamEvent→ any
—

Called when a Chat Model emits a content-block-centric stream event.

MhandleCustomEvent→ anyMhandleLLMEnd→ Promise<Run>
—

Called at the end of an LLM/ChatModel run, with the output and the run ID.

MhandleLLMError→ Promise<Run>
—

Called if an LLM/ChatModel run encounters an error

MhandleLLMNewToken→ Promise<Run>
—

Called when an LLM/ChatModel in streaming mode produces a new token

MhandleLLMStart→ Promise<Run>
—

Called at the start of an LLM or Chat Model run, with the prompt(s)

MhandleRetrieverEnd→ Promise<Run>MhandleRetrieverError→ Promise<Run>MhandleRetrieverStart→ Promise<Run>MhandleText→ Promise<void>MhandleToolEnd→ Promise<Run>
—

Called at the end of a Tool run, with the tool output and the run ID.

MhandleToolError→ Promise<Run>
—

Called if a Tool run encounters an error

MhandleToolEvent→ any
—

Called when a streaming tool yields a partial value. Tools that are async generators

MhandleToolStart→ Promise<Run>
—

Called at the start of a Tool run, with the tool name and input

MonAgentAction→ void | Promise<void>MonAgentEnd→ void | Promise<void>MonChainEnd→ void | Promise<void>MonChainError→ void | Promise<void>MonChainStart→ void | Promise<void>MonLLMEnd→ void | Promise<void>MonLLMError→ void | Promise<void>MonLLMNewToken→ void | Promise<void>MonLLMStart→ void | Promise<void>MonRetrieverEnd→ void | Promise<void>MonRetrieverError→ void | Promise<void>MonRetrieverStart→ void | Promise<void>MonRunCreate→ void | Promise<void>MonRunUpdate→ void | Promise<void>MonText→ void | Promise<void>MonToolEnd→ void | Promise<void>MonToolError→ void | Promise<void>MonToolStart→ void | Promise<void>MpersistRun→ Promise<void>MstringifyError→ stringMtoJSON→ SerializedMtoJSONNotImplemented→ SerializedNotImplementedMfromMethods→ HandlerMlc_name→ string
—

The name of the serializable. Override to provide an alias or

Inherited fromBaseCallbackHandler

Properties

PawaitHandlers: booleanPignoreAgent: booleanPignoreChain: booleanPignoreCustomEvent: booleanPignoreLLM: booleanPignoreRetriever: booleanPlc_kwargs: SerializedFieldsPlc_serializable: booleanPname: stringPraiseError: booleanPlc_aliases: __type | undefinedPlc_attributes: __type | undefinedPlc_id: string[]Plc_namespace: ["langchain_core", "callbacks", string]
—

A path to the module that contains the class, eg. ["langchain", "llms"]

Plc_secrets: __type | undefinedPlc_serializable_keys: string[] | undefined

Methods

Mcopy→ BaseCallbackHandlerMhandleAgentAction→ void | Promise<void>
—

Called when an agent is about to execute an action,

MhandleAgentEnd→ void | Promise<void>
—

Called when an agent finishes execution, before it exits.

MhandleChainEnd→ any
—

Called at the end of a Chain run, with the outputs and the run ID.

MhandleChainError→ any
—

Called if a Chain run encounters an error

MhandleChainStart→ any
—

Called at the start of a Chain run, with the chain name and inputs

MhandleChatModelStart→ any
—

Called at the start of a Chat Model run, with the prompt(s)

MhandleChatModelStreamEvent→ any
—

Called when a Chat Model emits a content-block-centric stream event.

MhandleCustomEvent→ anyMhandleLLMEnd→ any
—

Called at the end of an LLM/ChatModel run, with the output and the run ID.

MhandleLLMError→ any
—

Called if an LLM/ChatModel run encounters an error

MhandleLLMNewToken→ any
—

Called when an LLM/ChatModel in streaming mode produces a new token

MhandleLLMStart→ any
—

Called at the start of an LLM or Chat Model run, with the prompt(s)

MhandleRetrieverEnd→ anyMhandleRetrieverError→ anyMhandleRetrieverStart→ anyMhandleText→ void | Promise<void>MhandleToolEnd→ any
—

Called at the end of a Tool run, with the tool output and the run ID.

MhandleToolError→ any
—

Called if a Tool run encounters an error

MhandleToolEvent→ any
—

Called when a streaming tool yields a partial value. Tools that are async generators

MhandleToolStart→ any
—

Called at the start of a Tool run, with the tool name and input

MtoJSON→ SerializedMtoJSONNotImplemented→ SerializedNotImplementedMfromMethods→ HandlerMlc_name→ string
—

The name of the serializable. Override to provide an alias or

View source on GitHub