I’m working on a task management app built with React and CopilotKit. The app incorporates features to handle message responses, read data, and execute user actions such as adding tasks.
Setup Overview:
Initially, I was using the public Copilot service with its API key, and everything functioned without problems. All features, including actions and responsive messages, worked smoothly. However, after the trial period ended, I transitioned to a self-hosted server setup using the LangChain adapter along with my own Gemini API key.
Current Issue:
In my custom server setup, I can successfully handle messages and process readable data, but the useCopilotAction functionality does not work at all. While the AI responds to messages appropriately, the action triggers simply won’t activate.
Current Code Implementation:
import express from "express";
import {
CopilotRuntime,
LangChainAdapter,
copilotRuntimeNodeHttpEndpoint,
} from "@copilotkit/runtime";
import { ChatGoogleGenerativeAI } from "@langchain/google-genai";
import dotenv from "dotenv";
dotenv.config();
const server = express();
const aiModel = new ChatGoogleGenerativeAI({
model: "gemini-1.5-flash",
apiKey: process.env.GEMINI_API_KEY,
region: "us-central1",
});
const adapter = new LangChainAdapter({
chainFn: async ({ messages, tools }) => {
return aiModel.bindTools(tools).stream(messages);
},
});
server.use("/api/copilot", (req, res, next) => {
const runtime = new CopilotRuntime();
const handler = copilotRuntimeNodeHttpEndpoint({
endpoint: "/api/copilot",
runtime,
serviceAdapter: adapter,
});
return handler(req, res, next);
});
server.listen(3000, () => {
console.log("Server running on http://localhost:3000/api/copilot");
});
What steps can I take to ensure the action functionality works on my self-hosted server setup with the Gemini API? Are there specific configurations that differ from the public service?