this.fn is not a function #54

Closed
opened 2026-02-15 17:15:07 -05:00 by yindo · 3 comments
Owner

Originally created by @leSullivan on GitHub (Jul 22, 2024).

Hi,

im currently trying to develop a langgraph app for our nestJS backend but face one major difficulty.

I have a langgraph service, which purpose it is to compile the graph. It's major function is basically something similar to this

compileGraph() {
        const workflow = new StateGraph<GraphState>({
          channels: this.graphStateChannels,
        })
          .addNode(AgentName.GENERALIST, this.generalistNode)
          .addNode(AgentName.RETRIEVAL, this.retrievelAgentNode);
    
        workflow.addEdge(AgentName.RETRIEVAL, AgentName.GENERALIST);
    
        workflow.addConditionalEdges(AgentName.GENERALIST, this.router);
    
        workflow.addEdge(START, AgentName.GENERALIST);
    
        return workflow.compile();
}

when i invoke my compiled Graph in my ChatService i get errors that part of the nodes logic is not available. For Instance:

The simplest case from the langgraph documentation i define a node as:

private async retrievelAgentNode(state: GraphState, config?: RunnableConfig) {
    return this.runAgentNode({
      state,
      name: AgentName.RETRIEVAL,
      config,
    });
  }

private async runAgentNode(props: {
    state: GraphState;
    name: AgentName;
    config?: RunnableConfig;
  }) {
    const { state, name, config } = props;

    const agent = this.buildAgent(name, config.configurable.llm);

    const result = await agent.invoke(state, config);

    console.log('Node result', result);

    return {
      messages: [result],
    };
  }

i get the error that "runAgentNode" is not a function. I also tried it many other ways but don't seem to get it to work. Is LangGraph not compatible in a class based service environment or am i making a mistake ?

Originally created by @leSullivan on GitHub (Jul 22, 2024). Hi, im currently trying to develop a langgraph app for our nestJS backend but face one major difficulty. I have a langgraph service, which purpose it is to compile the graph. It's major function is basically something similar to this compileGraph() { const workflow = new StateGraph<GraphState>({ channels: this.graphStateChannels, }) .addNode(AgentName.GENERALIST, this.generalistNode) .addNode(AgentName.RETRIEVAL, this.retrievelAgentNode); workflow.addEdge(AgentName.RETRIEVAL, AgentName.GENERALIST); workflow.addConditionalEdges(AgentName.GENERALIST, this.router); workflow.addEdge(START, AgentName.GENERALIST); return workflow.compile(); } when i invoke my compiled Graph in my ChatService i get errors that part of the nodes logic is not available. For Instance: The simplest case from the langgraph documentation i define a node as: private async retrievelAgentNode(state: GraphState, config?: RunnableConfig) { return this.runAgentNode({ state, name: AgentName.RETRIEVAL, config, }); } private async runAgentNode(props: { state: GraphState; name: AgentName; config?: RunnableConfig; }) { const { state, name, config } = props; const agent = this.buildAgent(name, config.configurable.llm); const result = await agent.invoke(state, config); console.log('Node result', result); return { messages: [result], }; } i get the error that "runAgentNode" is not a function. I also tried it many other ways but don't seem to get it to work. Is LangGraph not compatible in a class based service environment or am i making a mistake ?
yindo closed this issue 2026-02-15 17:15:07 -05:00
Author
Owner

@josefernandezceiba commented on GitHub (Nov 18, 2024):

Same here!!

@josefernandezceiba commented on GitHub (Nov 18, 2024): Same here!!
Author
Owner

@leSullivan commented on GitHub (Nov 28, 2024):

@josefernandezatceiba you need to bind "this" to your nodes

const workflow = new StateGraph<GraphState>({
      channels: this.graphStateChannels,
    })
      .addNode("agent123", this.agent123Node.bind(this))
@leSullivan commented on GitHub (Nov 28, 2024): @josefernandezatceiba you need to bind "this" to your nodes const workflow = new StateGraph<GraphState>({ channels: this.graphStateChannels, }) .addNode("agent123", this.agent123Node.bind(this))
Author
Owner

@josefernandezceiba commented on GitHub (Nov 28, 2024):

yeah, i did just that !!

On Thu, Nov 28, 2024 at 9:39 AM John @.***> wrote:

@josefernandezatceiba https://github.com/josefernandezatceiba you need
to bind "this" to your nodes

const workflow = new StateGraph({
channels: this.graphStateChannels,
})
.addNode("agent123", this.agent123Node.bind(this))


Reply to this email directly, view it on GitHub
https://github.com/langchain-ai/langgraphjs/issues/277#issuecomment-2506273336,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ANNLEA4DYF2HWTWJEMFC2SL2C4TLLAVCNFSM6AAAAABLIY53MWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMBWGI3TGMZTGY
.
You are receiving this because you were mentioned.Message ID:
@.***>

--

  • Jose Alfredo Fernandez Mendoza Coach Técnico Ceiba Software * Tel:
    Medellín (+57)604-444-5111 || Cel: (+57)3177403580
    CNCF Certified Kubernetes Administrator - Google Professional Cloud
    Architect - Microsoft MCSD App Builder - Microsoft MCSA Web Applications

--

Cl 8 B 65 - 191 Of 409
@.***,-75.5873189,355m/data=!3m1!1e3!4m2!3m1!1s0x0000000000000000:0x95885d68890e7b2c>,
Centro Empresarial Puertoseco - Medellín, Colombia

Visite nuestro 

sitio www.ceiba.co http://www.ceiba.co
Facebook
https://www.facebook.com/CeibaSoftware| Twitter
https://twitter.com/CeibaSoftware| Youtube
http://www.youtube.com/user/ceibasw| Linkedin
http://www.linkedin.com/company/ceiba-software-house

--

Este mensaje, incluido su adjunto, es confidencial y puede ser
privilegiado. Si usted no es su destinatario, por favor notifique al
emisor, luego destruya la comunicación y todas las copias. Usted no debe
copiar, distribuir y/o revelar esta comunicación parcial o totalmente sin
autorización del emisor.
This message, including attachments, is
confidential and may be privileged. If you are not an intended recipient,
please notify the sender then delete and destroy the original message and
all copies. You should not copy, forward and/or disclose this message, in
whole or in part, without permission of the sender.

@josefernandezceiba commented on GitHub (Nov 28, 2024): yeah, i did just that !! On Thu, Nov 28, 2024 at 9:39 AM John ***@***.***> wrote: > @josefernandezatceiba <https://github.com/josefernandezatceiba> you need > to bind "this" to your nodes > > const workflow = new StateGraph<GraphState>({ > channels: this.graphStateChannels, > }) > .addNode("agent123", this.agent123Node.bind(this)) > > — > Reply to this email directly, view it on GitHub > <https://github.com/langchain-ai/langgraphjs/issues/277#issuecomment-2506273336>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/ANNLEA4DYF2HWTWJEMFC2SL2C4TLLAVCNFSM6AAAAABLIY53MWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMBWGI3TGMZTGY> > . > You are receiving this because you were mentioned.Message ID: > ***@***.***> > -- * Jose Alfredo Fernandez Mendoza Coach Técnico Ceiba Software * Tel: Medellín (+57)604-444-5111 || Cel: (+57)3177403580 CNCF Certified Kubernetes Administrator - Google Professional Cloud Architect - Microsoft MCSD App Builder - Microsoft MCSA Web Applications -- Cl 8 B 65 - 191 Of 409 ***@***.***,-75.5873189,355m/data=!3m1!1e3!4m2!3m1!1s0x0000000000000000:0x95885d68890e7b2c>, Centro Empresarial Puertoseco - Medellín, Colombia Visite nuestro sitio www.ceiba.co <http://www.ceiba.co> Facebook <https://www.facebook.com/CeibaSoftware>| Twitter <https://twitter.com/CeibaSoftware>| Youtube <http://www.youtube.com/user/ceibasw>| Linkedin <http://www.linkedin.com/company/ceiba-software-house> -- Este mensaje, incluido su adjunto, es confidencial y puede ser privilegiado. Si usted no es su destinatario, por favor notifique al emisor, luego destruya la comunicación y todas las copias. Usted no debe copiar, distribuir y/o revelar esta comunicación parcial o totalmente sin autorización del emisor. This message, including attachments, is confidential and may be privileged. If you are not an intended recipient, please notify the sender then delete and destroy the original message and all copies. You should not copy, forward and/or disclose this message, in whole or in part, without permission of the sender.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraphjs#54