langchain-ai / langchain-ai/langgraphjs
Running in Firebase Function
- Dominant language
- TypeScript
- Stars
- 3.3k
- Forks
- 580
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 56
Description
I am getting run-time error when trying to run LangGraph inside a Firebase function.
Firebase Function:
```
exports.langgraph = onRequest(async (request, response) => {
const articleId = request.query.articleId as string;
const workflow = getWorkflow();
const result = await workflow.invoke({
articleId,
});
response.json(result);
});
```
Workflow:
```
import { END, START, StateGraph } from "@langchain/langgraph";
import { AgentState } from "./state";
import { testNode, wikipediaNode } from "./nodes";
import { researcherNode } from "./nodes/researcher";
export const getWorkflow = () => {
const workflow = new StateGraph(AgentState)
.addNode("final", testNode)
.addNode("wikipedia", wikipediaNode)
.addNode("researcher", researcherNode)
.addEdge(START, "wikipedia")
.addEdge("wikipedia", "researcher")
.addEdge("researcher", "final")
.addEdge("final", END);
return workflow.compile();
};
```
Error:
```
⚠ functions: Error: Expected a Runnable, function or object.
Instead got an unsupported type.
at _coerceToRunnable (/Users/user/workspace/foo-api/functions/node_modules/@langchain/core/dist/runnables/base.cjs:1857:15)
at StateGraph.addNode (/Users/user/workspace/foo-api/functions/node_modules/@langchain/langgraph/dist/graph/state.cjs:204:57)
at getWorkflow (/Users/user/workspace/foo-api/functions/lib/src/graph/index.js:11:10)
at /Users/user/workspace/foo-api/functions/lib/src/index.js:225:46
at /Users/user/workspace/foo-api/functions/node_modules/firebase-functions/lib/v2/providers/https.js:65:29
at cors (/Users/user/workspace/foo-api/functions/node_modules/cors/lib/index.js:188:7)
at /Users/user/workspace/foo-api/functions/node_modules/cors/lib/index.js:224:17
at originCallback (/Users/user/workspace/foo-api/functions/node_modules/cors/lib/index.js:214:15)
at /Users/user/workspace/foo-api/functions/node_modules/cors/lib/index.js:219:13
at optionsCallback (/Users/user/workspace/foo-api/functions/node_modules/cors/lib/index.js:199:9)
⚠ Your function was killed because it raised an unhandled error.
```
Any thoughts on why this might happen? My code worked with LangGraph studio. I've tried two ways of doing this: 1) the workflow is compiled at script start time, and 2) on demand via getWorkflow(). Both fail with same error.
Thanks
Packages:
```
"@langchain/anthropic": "^0.2.17",
"@langchain/core": "^0.2.31",
"@langchain/langgraph": "^0.2.2",
"@langchain/openai": "^0.2.10",
```
Contributor guide
Research direction
Start with the StateGraph.addNode call in functions/lib/src/graph/index.js and compare it with the Firebase entry point in functions/lib/src/index.js. Reproduce the error in the Firebase function context using the listed package versions, then determine which node registration causes the unsupported type error. Done means the workflow can be compiled and invoked successfully from the Firebase function.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- firebase, typescript
- Domain
- backend, cloud
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100