Supervisor need support pre post model hook #343

Closed
opened 2026-02-15 18:16:03 -05:00 by yindo · 2 comments
Owner

Originally created by @lzj960515 on GitHub (Aug 20, 2025).

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangGraph.js documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangGraph.js rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangGraph (or the specific integration package).

Example Code

just add preModelHook and postModelHook param at createSupervisor function, like this

export type CreateSupervisorParams<AnnotationRootT extends AnnotationRoot<any>, StructuredResponseFormat extends Record<string, any> = Record<string, any>> = {
    agents: CompiledStateGraph<AnnotationRootT["State"], AnnotationRootT["Update"], string, AnnotationRootT["spec"], AnnotationRootT["spec"]>[];
    llm: LanguageModelLike;
    tools?: (StructuredToolInterface | RunnableToolLike | DynamicTool)[];
    prompt?: CreateReactAgentParams["prompt"];
    responseFormat?: InteropZodType<StructuredResponseFormat> | {
        prompt: string;
        schema: InteropZodType<StructuredResponseFormat> | Record<string, unknown>;
    } | Record<string, unknown>;
    stateSchema?: AnnotationRootT;
    contextSchema?: AnnotationRootT;
    outputMode?: OutputMode;
    addHandoffBackMessages?: boolean;
    supervisorName?: string;
    includeAgentName?: AgentNameMode;
    preModelHook?: RunnableLike<
    ToAnnotationRoot<A>["State"] & PreHookAnnotation["State"],
    ToAnnotationRoot<A>["Update"] & PreHookAnnotation["Update"],
    LangGraphRunnableConfig
  >;
  postModelHook?: RunnableLike<
    ToAnnotationRoot<A>["State"],
    ToAnnotationRoot<A>["Update"],
    LangGraphRunnableConfig
  >;
};
    const supervisorAgent = (0, prebuilt_1.createReactAgent)({
        name: supervisorName,
        llm: supervisorLLM,
        tools: allTools,
        prompt,
        responseFormat,
        stateSchema: schema,
        preModelHook,
        postModelHook,
    });

Error Message and Stack Trace (if applicable)

No response

Description

https://github.com/langchain-ai/langgraphjs/blob/3320793bffffa02682227644aefbee95dee330a2/libs/langgraph-supervisor/src/supervisor.ts#L89-L120

https://github.com/langchain-ai/langgraphjs/blob/3320793bffffa02682227644aefbee95dee330a2/libs/langgraph-supervisor/src/supervisor.ts#L255-L262

System Info

lastest

Originally created by @lzj960515 on GitHub (Aug 20, 2025). ### Checked other resources - [x] I added a very descriptive title to this issue. - [x] I searched the LangGraph.js documentation with the integrated search. - [x] I used the GitHub search to find a similar question and didn't find it. - [x] I am sure that this is a bug in LangGraph.js rather than my code. - [x] The bug is not resolved by updating to the latest stable version of LangGraph (or the specific integration package). ### Example Code just add preModelHook and postModelHook param at createSupervisor function, like this ``` export type CreateSupervisorParams<AnnotationRootT extends AnnotationRoot<any>, StructuredResponseFormat extends Record<string, any> = Record<string, any>> = { agents: CompiledStateGraph<AnnotationRootT["State"], AnnotationRootT["Update"], string, AnnotationRootT["spec"], AnnotationRootT["spec"]>[]; llm: LanguageModelLike; tools?: (StructuredToolInterface | RunnableToolLike | DynamicTool)[]; prompt?: CreateReactAgentParams["prompt"]; responseFormat?: InteropZodType<StructuredResponseFormat> | { prompt: string; schema: InteropZodType<StructuredResponseFormat> | Record<string, unknown>; } | Record<string, unknown>; stateSchema?: AnnotationRootT; contextSchema?: AnnotationRootT; outputMode?: OutputMode; addHandoffBackMessages?: boolean; supervisorName?: string; includeAgentName?: AgentNameMode; preModelHook?: RunnableLike< ToAnnotationRoot<A>["State"] & PreHookAnnotation["State"], ToAnnotationRoot<A>["Update"] & PreHookAnnotation["Update"], LangGraphRunnableConfig >; postModelHook?: RunnableLike< ToAnnotationRoot<A>["State"], ToAnnotationRoot<A>["Update"], LangGraphRunnableConfig >; }; ``` ``` const supervisorAgent = (0, prebuilt_1.createReactAgent)({ name: supervisorName, llm: supervisorLLM, tools: allTools, prompt, responseFormat, stateSchema: schema, preModelHook, postModelHook, }); ``` ### Error Message and Stack Trace (if applicable) _No response_ ### Description https://github.com/langchain-ai/langgraphjs/blob/3320793bffffa02682227644aefbee95dee330a2/libs/langgraph-supervisor/src/supervisor.ts#L89-L120 https://github.com/langchain-ai/langgraphjs/blob/3320793bffffa02682227644aefbee95dee330a2/libs/langgraph-supervisor/src/supervisor.ts#L255-L262 ### System Info lastest
yindo closed this issue 2026-02-15 18:16:03 -05:00
Author
Owner

@dinuka-rp commented on GitHub (Aug 22, 2025):

It'll be really nice if the pre-model-hook can be added to the JS package, similar to the Python supervisor package, as soon as possible 🙏🏾

@dinuka-rp commented on GitHub (Aug 22, 2025): It'll be really nice if the pre-model-hook can be added to the JS package, similar to the Python supervisor package, as soon as possible 🙏🏾
Author
Owner

@dinuka-rp commented on GitHub (Aug 22, 2025):

According to my understanding and based on what I see in the Python package code and existing JS package code, the supervisor needs to accept the pre and post model hooks, then pass them down to the createReactApp initialisation here.

I'd be happy to work on this :)

@dinuka-rp commented on GitHub (Aug 22, 2025): According to my understanding and based on what I see in the [Python package code](https://github.com/langchain-ai/langgraph-supervisor-py/blob/23ba418364c7adfc5aac6aaaa8b10311e932175a/langgraph_supervisor/supervisor.py#L432C8-L432C39) and existing JS package code, the supervisor needs to accept the pre and post model hooks, then pass them down to the createReactApp initialisation [here](https://github.com/langchain-ai/langgraphjs/blob/3320793bffffa02682227644aefbee95dee330a2/libs/langgraph-supervisor/src/supervisor.ts#L255). I'd be happy to work on this :)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraphjs#343