Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

streamEvents call for agent created with model ChatDeepInfra throws error: "Cannot read properties of undefined (reading 'message')" #7638

Open
5 tasks done
vshtishi opened this issue Feb 2, 2025 · 1 comment
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@vshtishi
Copy link

vshtishi commented Feb 2, 2025

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain.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 LangChain.js rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

const llm = new ChatDeepInfra({
model: "deepseek-ai/DeepSeek-R1",
apiKey: process.env.DEEPINFRA_API_TOKEN,
temperature: 0.7,
});

  // const llm = new ChatOpenAI({
  //   model: "gpt-4o-mini",
  //   apiKey: process.env.OPENAI_API_KEY,
  //   temperature: 0.7,
  // });

  const agent = createReactAgent({
    llm,
    tools: this.tools,
  }).withConfig({ runName: "Agent" });

const stream = agent.streamEvents(
{
messages: [new HumanMessage("Hello")],
},
{ version: "v2" },
);

Error Message and Stack Trace (if applicable)

2025-02-02 12:45:18 TypeError: Cannot read properties of undefined (reading 'message')
2025-02-02 12:45:18 at ChatDeepInfra.invoke (/usr/src/app/node_modules/@langchain/core/dist/language_models/chat_models.cjs:71:31)
2025-02-02 12:45:18 at processTicksAndRejections (node:internal/process/task_queues:95:5)
2025-02-02 12:45:18 at RunnableSequence.invoke (/usr/src/app/node_modules/@langchain/core/dist/runnables/base.cjs:1291:27)
2025-02-02 12:45:18 at RunnableCallable.callModel [as func] (/usr/src/app/node_modules/@langchain/langgraph/dist/prebuilt/react_agent_executor.cjs:175:29)
2025-02-02 12:45:18 at RunnableCallable.invoke (/usr/src/app/node_modules/@langchain/langgraph/dist/utils.cjs:82:27)
2025-02-02 12:45:18 at RunnableSequence.invoke (/usr/src/app/node_modules/@langchain/core/dist/runnables/base.cjs:1285:33)
2025-02-02 12:45:18 at _runWithRetry (/usr/src/app/node_modules/@langchain/langgraph/dist/pregel/retry.cjs:70:22)
2025-02-02 12:45:18 at PregelRunner._executeTasksWithRetry (/usr/src/app/node_modules/@langchain/langgraph/dist/pregel/runner.cjs:211:33)
2025-02-02 12:45:18 at PregelRunner.tick (/usr/src/app/node_modules/@langchain/langgraph/dist/pregel/runner.cjs:48:40)
2025-02-02 12:45:18 at CompiledStateGraph._runLoop (/usr/src/app/node_modules/@langchain/langgraph/dist/pregel/index.cjs:1018:17)
2025-02-02 12:45:18 at createAndRunLoop (/usr/src/app/node_modules/@langchain/langgraph/dist/pregel/index.cjs:907:17) {
2025-02-02 12:45:18 pregelTaskId: '84d27050-8f24-5b8b-9b7b-cbf31ac60197'
2025-02-02 12:45:18 }

Description

I am trying to call streamEventson a react agent created with llm ChatDeepInfra (deepseek-ai/DeepSeek-R1). The code works fine when I use another llm (ChatOpenAI) so I am guessing it is specific for this case. Also, it works if I invoke streamEvents directly on the model without creating an agent. Any feedback would be much appreciated. Thank you in advance.

System Info

| -- @langchain/[email protected] deduped +-- @langchain/[email protected] | +-- @langchain/[email protected] deduped | +-- @langchain/[email protected] deduped | -- [email protected] deduped
+-- @langchain/[email protected]
+-- @langchain/[email protected]
| +-- @langchain/[email protected] deduped
| -- @langchain/[email protected] | -- @langchain/[email protected] deduped
+-- @langchain/[email protected]
| -- @langchain/[email protected] deduped +-- @langchain/[email protected] -- [email protected]
+-- @langchain/[email protected] deduped
+-- @langchain/[email protected] deduped
+-- @langchain/[email protected] deduped
-- @langchain/[email protected] -- @langchain/[email protected] deduped

Copy link

dosubot bot commented Feb 2, 2025

Hey there, @vshtishi! I'm here to help you with any bugs or questions you have. Let's tackle this together!

I found a similar unsolved discussion regarding an issue with LangChain agents: langchain agent -> Exiting LLM run with output: { "generations": [ [ null ] ] } [1]. However, it does not provide a solution applicable to your specific problem.

The error "Cannot read properties of undefined (reading 'message')" suggests that there might be an issue with how the ChatDeepInfra model is handling the message properties when used with the createReactAgent function. This error typically occurs when trying to access a property on an undefined object.

Here are a few things you might consider checking or trying:

  1. Message Structure: Ensure that the messages array passed to streamEvents is correctly structured and that each message is properly instantiated as a HumanMessage.

  2. Model-Specific Handling: Since the code works with ChatOpenAI but not with ChatDeepInfra, there might be a model-specific issue. Check if there are any known limitations or differences in how ChatDeepInfra handles messages compared to ChatOpenAI.

  3. Direct Invocation: You mentioned that invoking streamEvents directly on the model works. This suggests that the issue might be related to how the agent is configured or how it interacts with the ChatDeepInfra model. Consider reviewing the agent's configuration and any model-specific settings.

  4. Error Handling: Implement additional error handling or logging around the streamEvents call to capture more detailed information about what might be going wrong.

If these steps do not resolve the issue, it might be necessary to further investigate the interaction between ChatDeepInfra and the createReactAgent function, possibly by reviewing the implementation details or reaching out to the maintainers for more specific guidance.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@dosubot dosubot bot added the auto:bug Related to a bug, vulnerability, unexpected error with an existing feature label Feb 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

No branches or pull requests

1 participant