Dispatch a custom event.
Note: this method is only supported in non-web environments due to usage of async_hooks to infer config.
If you are using this method in the browser, please import and use from "@langchain/core/callbacks/dispatch/web".
dispatchCustomEvent(
eventName: string,
payload: any,
config: RunnableConfig<Record<string, any>>
): Promise<void>| Name | Type | Description |
|---|---|---|
eventName* | string | |
payload* | any | The data for the custom event. Ideally should be JSON serializable to avoid serialization issues downstream, but not enforced. |
config | RunnableConfig<Record<string, any>> | Optional config object. |
import { dispatchCustomEvent } from "@langchain/core/callbacks/dispatch";
const foo = RunnableLambda.from(async (input: string) => {
await dispatchCustomEvent("my_custom_event", { arbitraryField: "someval" });
return input;
});
const callbacks = [{
handleCustomEvent: (eventName: string, payload: any) => {
// Logs "my_custom_event" and { arbitraryField: "someval" }
console.log(eventName, payload);
}
}];
await foo.invoke("hi", { callbacks })