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/corecallbacksdispatchdispatchCustomEvent
Functionā—Since v1.0

dispatchCustomEvent

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".

Copy
dispatchCustomEvent(
  eventName: string,
  payload: any,
  config: RunnableConfig<Record<string, any>>
): Promise<void>

Parameters

NameTypeDescription
eventName*string
payload*any

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

configRunnableConfig<Record<string, any>>

Optional config object.

Example

Copy
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 })
View source on GitHub