dispatchCustomEvent() doesn't work properly in tool. #6652
-
Checked other resources
Commit to Help
Example Codeprivate async getDocuments(
{
query,
reasoningStep,
}: { query?: string; filter?: string; reasoningStep?: string },
config: RunnableConfig,
) {
if (!query) {
throw new Error("Please provide the required 'query' property.");
}
this.streamReasoningStep(reasoningStep);
....
}
async streamReasoningStep(reasoningStep: string) {
if (!reasoningStep) {
this.logger.warn('No reasoning step provided from', this.name);
return;
}
await dispatchCustomEvent('onNewReasoningStep', {
reasoningStep,
agent: this.name,
});
} DescriptionHi im using a function Inside different Nodes of my Langgraph app to trigger a custom Event with dispatchCustomEvent(). I call this function after every tool call, but run into the error: Error: Unable to dispatch a custom event without a parent run id. This function can only be called from within an existing run (e.g., inside a tool or a RunnableLambda). Can someone help me with this problem ? System Info"@langchain/anthropic": "^0.2.15", MacOS Node 20.3.1 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 14 replies
-
Hey @leSullivan! 👋 I'm here to help you with your code, answer your questions, and provide support while waiting for a human maintainer. Let's take a look at the issue together. The error occurs because To resolve this issue, ensure that you are calling 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 }); Ensure that the |
Beta Was this translation helpful? Give feedback.
Ah is this in Nest.js? Someone reported an issue with using async hooks on Nest class methods that I still need to dig into.