[Help Needed] Copilot Action Triggering with LangChain Adapter and Gemini API
I’m integrating CopilotKit in a React app and facing an issue with triggering actions using my own server.
Setup:
Using LangChain adapter with Gemini API (gemini-1.5-flash model).
Express server handles API calls and user messages.
Server Code:
import express from "express";
import { CopilotRuntime, LangChainAdapter, copilotRuntimeNodeHttpEndpoint } from "@copilotkit/runtime";
import { ChatGoogleGenerativeAI } from "@langchain/google-genai";
import dotenv from "dotenv";
dotenv.config();
const app = express();
const model = new ChatGoogleGenerativeAI({
model: "gemini-1.5-flash",
apiKey: process.env.GEMINI_API_KEY,
region: "us-central1",
});
const serviceAdapter = new LangChainAdapter({
chainFn: async ({ messages, tools }) => {
return model.bindTools(tools).stream(messages);
},
});
app.use("/copilotkit", (req, res, next) => {
const runtime = new CopilotRuntime();
const handler = copilotRuntimeNodeHttpEndpoint({
endpoint: "/copilotkit",
runtime,
serviceAdapter,
});
return handler(req, res, next);
});
app.listen(4000, () => {
console.log("Listening at http://localhost:4000/copilotkit");
});
Issue:
When using the publicApiKey="<your-copilot-cloud-public-api-key>", everything works: messages, responses, and actions.
With my own server, only messages and responses work, but actions (like adding tasks) don’t trigger.
Question:
What could be missing in the configuration to trigger actions when using my own server?
Any advice would be greatly appreciated!