#copilotkit dev not working: Tunnel error: connection refused: tunnels.devcopilotkit.com:42897

1 messages · Page 1 of 1 (latest)

strange merlin
#

Hey guys, I am new to CopilotKit and am trying to put together a demo for my company as I feel like it will be perfect for our needs. I am following the tutorials, but I get stuck when running:

npx copilotkit dev --port 8000

I can confirm that I have my Langgraph agent running on localhost:8000.

Note that I also seem to have issues authenticating the Langgraph Studio Desktop app. For this I get "Error: Failed to connect to LangGraph Server". However this might be an unrelated issue.

Would love a bit of help as I have a deadline to get this demo done by tomorrow 😅

south bone
#

@strange merlin I just tried the tunnel in my system and its seems to be workign just fine.
Can you send me screenshots of your langgrpah agent running and the screenshot of the copilotkit tunnel returning an error? That will give me more details to debug this.

strange merlin
#

After four hours of sleep I'm back at it 💪🚀
Tried this from the FAQ:

curl -I https://tunnels.devcopilotkit.com
HTTP/2 302 
server: nginx/1.10.1
date: Mon, 12 May 2025 08:08:49 GMT
content-type: text/html; charset=utf-8
content-length: 99
location: https://localtunnel.github.io/www/
strange merlin
#

Are these what you wanted? Let me know and I can grab whatever else can help

south bone
#

@strange merlin In the log, it first states that the local tunnel is live and linked, and only after that, it throws an error. Is this error happening some time after the tunnel opens, or is it immediate?

strange merlin
#

It's within about 1 second, so pretty immediate

#

Just tried again and it was instant

#

Tried a couple times more now and it seems to even fail before sometimes

south bone
#

It seems like something is blocking or removing the connection. Do you have any firewalls or antivirus software, etc, set up that may interfere with these connections?

This issue seems specific to your system, since I tried with a couple of other machines also, and the tunnel is setting up without any issues.

If you are still not able to, you can self-host the Copilot Runtime locally instead—see the “Self-Hosted Copilot Runtime” section in the quickstart.

strange merlin
#

I don't seem to have any firewalls set up. I'm using a MacbookPro. I have managed to set up other tunnels and also use it for a lot of dev work and haven't hit errors like this before. But it's very possible that something is interfering.

Thanks - I'll check out self-hosted and see where I get

south bone
#

@strange merlin Try restarting your system. Sometimes that will work 🙂

strange merlin
#

A restart didn't work 😦

south bone
#

Oh, okay. It might be something else. I will also pass this on to the team so they can check it.
In the meantime, you can use the self-hosted method to continue your testing.

strange merlin
#

Thank you very much! If I come across a solution I will make sure I share too.

strange merlin
#

Hey @south bone - when I set up the self hosted server (I went with ExpressJS) how can I connect it with my local langgraph setup? I looked through the documentation that I could find but am still at a loss. I could be misunderstanding how the overall setup is supposed to work.

I am super psyched about CopilotKit so I'm very eager to get something together that I can share!

strange merlin
#

Hey @south bone - I'm a bit blocked and need to get a demo done soon, so I would really appreciate the help. Apologies for pestering but I'm not sure where to look to make progress

south bone
#

Hello @strange merlin , you can refer to this demo we have https://github.com/CopilotKit/example-todos-app/blob/final/app/api/copilotkit/route.ts

Here, this route. ts is the runtime you need to configure.
Overall, check this repo https://github.com/CopilotKit/example-todos-app/tree/final

And you can see the CopilotKit component is initialized with a runtime URL, which points to the route ts file above.

In the route ts, you need to provide the URL of the agent running, and that's it.
There are other examples too in here, please check them out
https://github.com/CopilotKit/CopilotKit/tree/main/examples/demo-viewer

GitHub

Contribute to CopilotKit/example-todos-app development by creating an account on GitHub.

GitHub

Contribute to CopilotKit/example-todos-app development by creating an account on GitHub.

GitHub

React UI + elegant infrastructure for AI Copilots, AI chatbots, and in-app AI agents. The Agentic last-mile 🪁 - CopilotKit/CopilotKit

strange merlin
#

Thanks! I really appreciate the help!

strange merlin
#

so I've got this setup:

import express from "express";
import {
  CopilotRuntime,
  GoogleGenerativeAIAdapter,
  copilotRuntimeNodeHttpEndpoint,
} from "@copilotkit/runtime";

const app = express();

const serviceAdapter = new GoogleGenerativeAIAdapter({
  model: "gemini-1.5-flash",
});

app.use("/copilotkit", (req, res, next) => {
  (async () => {
    const runtime = new CopilotRuntime();
    const handler = copilotRuntimeNodeHttpEndpoint({
      endpoint: --> "/copilotkit" or "http://localhost:8000" <--,
      runtime,
      serviceAdapter,
    });

    return handler(req, res);
  })().catch(next);
});

app.listen(4000, () => {
  console.log("Listening at http://localhost:4000/copilotkit");
});

I'm using expressJS for the backend, and Vite ReactJS client-side webapp for the front-end.

In the front-end I am setting up CopilotKit with:

<CopilotKit
      publicApiKey={import.meta.env.VITE_COPILOT_CLOUD_API_KEY}
      agent="primordia_agent_copilot" // the name of the agent you want to use
      runtimeUrl="http://localhost:4000/copilotkit"
    >
  • Can you spot anything broken here?
  • Should I be using the endpoint of the Langgraph server in the self-hosted copilotkit, or should it point to the local "/copilotkit" route? And if so, I cannot understand how the self-hosted server is supposed to connect to my Langgraph setup
strange merlin
#

I also notice that copilotkit init is for NextJS applications. Could some if the issues I am hitting be related to me trying to use a different client-side only framework?

south bone
#

What is the issue you are facing? is there any error?

strange merlin
#

@south bone When attempting to send a message in the built-in chat UI, I get:

Failed to find any agents.

See more: https://docs.copilotkit.ai/coagents/troubleshooting/common-issues#i-am-getting-agent-not-found-error

Where

client:

<CopilotKit
      publicApiKey={import.meta.env.VITE_COPILOT_CLOUD_API_KEY}
      agent="primordia_agent_copilot" // the name of the agent you want to use
      runtimeUrl="http://localhost:4000/copilotkit"
    >

and
langgraph.json:

{
  "dependencies": ["."],
  "graphs": {
    "primordia_agent_copilot": "./src/react_agent/graph.py:graph"
  },
  "env": ".env"
}
#

In the help FAQ I see:

langGraphPlatformEndpoint({
    deploymentUrl,
    langsmithApiKey,
    agents: [
        {
            name: "my_agent",
            description: "A helpful agent",
        },
    ],
})

but it is not in the code you shared, so I am assuming it is not relevant

strange merlin
#

I set up the nextjs starter with a langgraph starter and that all worked. I'm going to see what I can learn from that.

south bone
#

@strange merlin In the CopiltoKit component initialization, you don't have to pass the publicApiKey when using self hosted method.

Can you comment out the publicApiKey and try

like :

<CopilotKit
      agent="primordia_agent_copilot" // the name of the agent you want to use
      runtimeUrl="http://localhost:4000/copilotkit"
    >
strange merlin
#

Just tried and no dice. Same error

south bone
#

when you run the app, do you see the requests reaching the runtime and then reaching the agent? can you ee the logs?

strange merlin
#

Got it:

const runtime = new CopilotRuntime({
//////////////////// This was missing ////////////////////
  remoteEndpoints: [
    langGraphPlatformEndpoint({
      deploymentUrl: process.env.LANGGRAPH_DEPLOYMENT_URL || "",
      langsmithApiKey: process.env.LANGSMITH_API_KEY || "", // only used in LangGraph Platform deployments
      agents: [
        {
          name: process.env.COPILOTKIT_AGENT_NAME || "",
          description:
            process.env.COPILOTKIT_AGENT_DESCRIPTION || "A helpful LLM agent.",
        },
      ],
    }),
  ],
//////////////////////////////////////////////////////////
  actions: [
    {
      name: "sayHello",
      description: "say hello so someone by roasting their name",
      parameters: [
        {
          name: "roast",
          description: "A sentence or two roasting the name of the person",
          type: "string",
          required: true,
        },
      ],
      handler: ({ roast }: { roast: string }) => {
        console.log(roast);
        return "The person has been roasted.";
      },
    },
  ],
});

Looking at the NextJS application, I saw we were indeed missing something that says where the LangGraph agent is.

This was what I was asking before "I cannot understand how the self-hosted server is supposed to connect to my Langgraph setup"

In the ExpressJS example, this code isn't missing, so I am still at a loss regarding how the self-hosted CopilotKit runtime knows where to find the LangGraph agent...

Until I added this, I could not connect to my agent via the runtimeUrl/self-hosted CopilotKit runtime

strange merlin
#

So I believe I can at least now work with the self-hosted set up. I would love to figure out why the cloud version isn't working. Please do let me know if any info comes up for this.

south bone
#

Sure

strange merlin
#

Have there been any updates?

south bone
#

Hello, sorry, but we tried and haven't encountered any issues using Copilotkit cloud.

Could you create a GitHub issue and provide all the details? https://github.com/CopilotKit/CopilotKit/issues

Then we can also set up a call with our team so they can check this with you and try to resolve it. Since this is a specific issue occurring only for you, the engineering team needs more data to troubleshoot this.

GitHub

React UI + elegant infrastructure for AI Copilots, AI chatbots, and in-app AI agents. The Agentic last-mile 🪁 - Issues · CopilotKit/CopilotKit