#Production Error with CopilotKit + LangGraph Agent

1 messages · Page 1 of 1 (latest)

edgy basalt
#

Hey everyone, I ran into a weird issue when deploying a CopilotKit-based agent to production. Everything works fine locally, but in prod, I’m seeing this error when trying to execute the agent:

TypeError: 'NoneType' object is not a mapping
(config = {**default_config, **(self.graph.config or {}), **config})
It’s coming from the _stream_events function inside copilotkit/langgraph_agent.py.

Local environment: fine
Production: crashes during execution after calling /copilotkit/agents/execute

Here’s what I suspect might be the issue:

  • self.graph.config is None in production.

  • Possibly due to the config not being initialized properly.

Or something’s missing in the deployment setup that’s present locally.

For backend, I’m using FastAPI to self-host the LangGraph agent with the add_fastapi_endpoint tool to serve the CopilotKit frontend. In front-end, I'm using CopilotKit Runtime.

For production, I'm using AWS ECS to deploy the backend API. I can confirm the copilotkit endpoint gets hit when interacting through the frontend.

Would appreciate any help, insights, or debugging tips. I’ve already done a bit of digging but haven’t found a solid fix yet.

Thanks in advance! 🙏

manic zodiac
#

Hello @edgy basalt
Can you share some code snippets, specifically on the runtime implementation, so I can try to debug it?

In the meantime, you can also compare your code to these examples to see if you have missed anything.

https://github.com/CopilotKit/CopilotKit/tree/main/examples/saas-dynamic-dashboards

GitHub

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

edgy basalt
#

Thanks so much for the quick reply, @manic zodiac 🙏

Sure! I’ve attached a few key files that might help pinpoint the issue:

graph.py: sets up and compiles the LangGraph agent.

main.py: FastAPI backend that mounts CopilotKit onto an existing API. I’ve tried applying configs for both LangGraph and CopilotKit here, but the issue persists.

route.ts: the frontend endpoint that uses CopilotKit Runtime to call the backend.

Dockerfile: defines the backend container setup.

Here’s the open-source repo for reference — it mirrors the same architecture and setup:
🔗 https://github.com/al-mz/insight-copilot

For debugging, I even swapped out my graph with the joke-teller agent from CopilotKit examples, deployed it to ECS — and still got the exact same error. So I suspect the root cause might be somewhere in the backend API setup, Dockerfile, or the way the runtime is configured.

Really appreciate you taking the time to look into it!

GitHub

This is an open-source template that enables natural language querying and real-time data visualization for structured dataset. - al-mz/insight-copilot

manic zodiac
#

Thanks for the details. Let me look into this

slender kraken
# edgy basalt Thanks so much for the quick reply, <@1357404001292783762> 🙏 Sure! I’ve attach...

I've seen this in past. it mainly revolves around checkpoints and passing config to langgraph.

# Compile the builder into an executable graph
memory = MemorySaver()
graph = builder.compile(name="powersim_agent")  # ❌ Missing checkpointer

To:

# Compile the builder into an executable graph
memory = MemorySaver()
graph = builder.compile(checkpointer=memory, name="powersim_agent")  # ✅ Fixed

This is the exact pattern that works in all the CopilotKit examples:

from langgraph.checkpoint.memory import MemorySaver
memory = MemorySaver()
graph = workflow.compile(checkpointer=memory)

When you don't provide a checkpointer, LangGraph doesn't initialize the graph's config, leading to the 'NoneType' object is not a mapping error in the CopilotKit runtime.

Alternative if you don't want persistence, you can also just ensure the graph has a config:

graph = builder.compile(name="powersim_agent")
# Ensure config exists for CopilotKit compatibility
if not hasattr(graph, 'config') or graph.config is None:
    graph.config = {}

But the checkpointer approach is cleaner and gives you conversation persistence.

halcyon basin
#

@edgy basalt i faced same issue, u can by pass it temporarily until there is a fix by doing this:

    def execute(self, *args, **kwargs):
        logger.info("Executing custom LangGraphAgent")
        # over ride config parameter

        if "config" not in kwargs or kwargs["config"] is None:
            kwargs["config"] = {}

        return super().execute(*args, **kwargs)```
edgy basalt
#

Thanks @slender kraken , but as you can see in the graph.py attached, the checkpointer has already been included:

memory = MemorySaver()
graph = builder.compile(name="powersim_agent", checkpointer=memory)

#

@halcyon basin Thanks, I'll give it a try

edgy basalt
#

Hey @halcyon basin ! Your workaround solution worked very well. Thank you very much 🙌

fallen idol
#

Hey @edgy basalt
I will issue a fix for this today which will be available in our python sdk 0.1.47

fallen idol
#

released and available

tribal bay
#

Hey all, looks like we got a few resolutions here. Any lingering issues?