Register a callback configure hook to automatically add callback handlers to all runs.
There are two ways to use this:
Using a context variable:
contextVar to specify the variable namesetContextVariable() to store your handler instanceUsing an environment variable:
envVar and handlerClassregisterConfigureHook(config: ConfigureHook)| Name | Type | Description |
|---|---|---|
config* | ConfigureHook | Configuration object for the hook |
// 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