• Dispatch a custom event. Requires an explicit config object.

    Parameters

    • name: string

      The name of the custom event.

    • payload: any

      The data for the custom event. Ideally should be JSON serializable to avoid serialization issues downstream, but not enforced.

    • Optionalconfig: RunnableConfig

      Config object.

    Returns Promise<void>

    import { dispatchCustomEvent } from "@langchain/core/callbacks/dispatch";

    const foo = RunnableLambda.from(async (input: string, config?: RunnableConfig) => {
    await dispatchCustomEvent(
    "my_custom_event",
    { arbitraryField: "someval" },
    config
    );
    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 })