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

Bug in LangGraph API server for graphs in relative paths. #772

Open
tjrivera opened this issue Jan 4, 2025 · 0 comments
Open

Bug in LangGraph API server for graphs in relative paths. #772

tjrivera opened this issue Jan 4, 2025 · 0 comments

Comments

@tjrivera
Copy link

tjrivera commented Jan 4, 2025

Hi folks,

Not sure where the best place to put this is as I can't find the actual code for the LangGraph API server/LangGraph Studio and figure its not on GitHub

Issue:

I have a graph defined within a monorepo and have my langgraph.json file in the root of my repository. My langgraph configuration looks like:

{
  "node_version": "20",
  "dockerfile_lines": [],
  "dependencies": ["./packages/agents", "./packages/core"],
  "graphs": {
    "agent": "./packages/agents/src/test/graph.ts:graph"
  },
  "env": "packages/agents/.env"
}

I found that I can get the graph to build and load into studio, but that my Input form was not rendering properly -- I could only enter raw input i.e. { messages: [{...}]} instead of the nice form with the ability to select Human, AI, System, etc.

Bad build:
Screenshot 2025-01-04 at 6 34 57 PM
Expected build:
Screenshot 2025-01-04 at 6 36 30 PM

Checking my logs I found warnings of:

langgraph-api-1       | Failed to obtain symbol "__langgraph__graph__input": Unsupported type: 0 extends 1 & ValueType ? ValueType | undefined : Wrap<MatchBaseMessageArray<ValueType>> extends Wrap<...> ? import("/Users/tyler/code/test/node_modules/@langchain/core/dist/messages/base").BaseMessage[] : Wrap<...> extends Wrap<...> ? import("/Users/tyler/code/plum-fit-web/node_modules/@langchain/core/dist/messages/base").BaseMess...
langgraph-api-1       | Failed to obtain symbol "__langgraph__graph__input": Unsupported type: 0 extends 1 & ValueType ? ValueType | undefined : Wrap<MatchBaseMessageArray<ValueType>> extends Wrap<...> ? import("/Users/tyler/code/plum-fit-web/node_modules/@langchain/core/dist/messages/base").BaseMessage[] : Wrap<...> extends Wrap<...> ? import("/Users/tyler/code/test/node_modules/@langchain/core/dist/messages/base").BaseMess...

I tracked this down to the /api/langgraph_api/js/src/parser/parser.mts in the API server container:

    host.compilerHost.resolveModuleNames = (moduleNames, containingFile) => {
      const resolvedModules: (ts.ResolvedModule | undefined)[] = [];
      for (const moduleName of moduleNames) {
        let target = containingFile;
        const relative = path.relative(dirname, containingFile);
        if (
          moduleName.startsWith("@langchain/langgraph") &&
          relative &&
          !relative.startsWith("..") &&
          !path.isAbsolute(relative)
        ) {
          target = path.resolve(__dirname, relative);
        }

        resolvedModules.push(
          ts.resolveModuleName(
            moduleName,
            target,
            compilerOptions,
            host.compilerHost
          ).resolvedModule
        );
      }

      return resolvedModules;
    };

and noticed that it is only taking into account the @langchain/langgraph package, whereas the BaseMessage types are in @langchain/core. Updating the conditional to:

        if (
          (
            moduleName.startsWith("@langchain/langgraph") || 
            moduleName.startsWith("@langchain/core")
          ) &&
          relative &&
          !relative.startsWith("..") &&
          !path.isAbsolute(relative)
        ) {
          target = path.resolve(__dirname, relative);
        }

seems to resolve the issue. My current workaround is creating a patch file:

--- parser.mts	2025-01-04 23:23:38.820551112 +0000
+++ parser.mts	2025-01-04 23:24:19.279845893 +0000
@@ -373,7 +373,7 @@
         let target = containingFile;
         const relative = path.relative(dirname, containingFile);
         if (
-          moduleName.startsWith("@langchain/langgraph") &&
+          (moduleName.startsWith("@langchain/langgraph") || moduleName.startsWith("@langchain/core")) &&
           relative &&
           !relative.startsWith("..") &&
           !path.isAbsolute(relative)

and including the patch in my dockerfile lines:

{
  "node_version": "20",
  "dockerfile_lines": [
    "COPY packages/agents/langgraph_api.patch /tmp/langgraph_api.patch",
    "RUN patch --forward -p0 /api/langgraph_api/js/src/parser/parser.mts < /tmp/langgraph_api.patch"
  ],
  "dependencies": ["./packages/agents", "./packages/core"],
  "graphs": {
    "agent": "./packages/agents/src/fitness/graph.ts:graph"
  },
  "env": "packages/agents/.env"
}

I'm happy to submit a patch for this, but if that's not possible, hope this report helps resolve on yourside. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant