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

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

LangChain
UniversalHubNodeLoadSerializableEncoder BackedFile SystemIn Memory
LangChain Core
AgentsCachesBaseDispatchWebManagerPromisesChat HistoryContextBaseLangsmithDocumentsEmbeddingsErrorsExample SelectorsIndexingBaseChat ModelsLlmsProfileLoadSerializableMemoryMessagesToolOutput ParsersOpenai FunctionsOpenai ToolsOutputsPrompt ValuesPromptsRetrieversDocument CompressorsRunnablesGraphSingletonsStoresStructured QueryToolsBaseConsoleLog StreamRun CollectorTracer LangchainStreamAsync CallerChunk ArrayContextEnvEvent Source ParseFormatFunction CallingHashJson PatchJson SchemaMathSsrfStreamTestingTiktokenTypesVectorstores
Text Splitters
MCP Adapters
Language
Theme
JavaScript@langchain/corecontextregisterConfigureHook
Functionā—Since v1.0

registerConfigureHook

Register a callback configure hook to automatically add callback handlers to all runs.

There are two ways to use this:

  1. Using a context variable:

    • Set contextVar to specify the variable name
    • Use setContextVariable() to store your handler instance
  2. Using an environment variable:

    • Set both envVar and handlerClass
    • The handler will be instantiated when the env var is set to "true".
Copy
registerConfigureHook(config: ConfigureHook)

Parameters

NameTypeDescription
config*ConfigureHook

Configuration object for the hook

Example

Copy
// Method 1: Using context variable
import {
  registerConfigureHook,
  setContextVariable
} from "@langchain/core/context";

const tracer = new MyCallbackHandler();
registerConfigureHook({
  contextVar: "my_tracer",
});
setContextVariable("my_tracer", tracer);

// ...run code here

// Method 2: Using environment variable
registerConfigureHook({
  handlerClass: MyCallbackHandler,
  envVar: "MY_TRACER_ENABLED",
});
process.env.MY_TRACER_ENABLED = "true";

// ...run code here
View source on GitHub