#CopilotKit + LangGraph + LangFuse

1 messages · Page 1 of 1 (latest)

nova pike
#

Hey #1313616713647919218!

I'm setting up a very basic app bootstrapped basically exactly from the LangGraph and CopilotKit docs. The only thing I'm trying to add is LangFuse for tracing.

I'm running all of this locally via LangGraph CLI's langgraph dev command. LangGraph-wise it couldn't be more simple, as I'm just using create_react_agent with a few dummy MCP tools.

For some reason, the way CopilotKit is calling my agent doesn't trigger any of my LangGraph agent's callback handlers and I'm not too sure why, which is breaking LangFuse integration. LangSmith traces still work fine but those don't use callback handlers.

Has anyone seen this before?

uncut rootBOT
#

Hello @nova pike, can you share some code snippets on your agent's callback handlers?

nova pike
uncut rootBOT
#

@nova pike Let me check this and I'll reply

nova pike
#

Thank you so much! If you need an actual minimum reproduceable example I can fire something up for you later. Just lmk

median pier
#

Hi @nova pike could you tell us more how you are integrating your Langgraph agent with Copilotkit? We have two routes, one with FastAPI and other using LangGraph. I want to make sure I understand this bit better

nova pike
#

Hey! I'm using LangGraph directly, no FastAPI in between

nova pike
#

Any ideas?

median pier
#

Before we dig into CopilotKit, can we sanity-check a couple of things?

Direct invoke test
If you take the graph that’s built with with_config({"callbacks":[langfuse_handler]}) and call graph.invoke() (no CopilotKit in the loop), do LangFuse events show up?

Agent config peek
Right after agent = create_react_agent(...), could you print(agent.graph._config)? Does it actually list your LangFuseCallbackHandler, or is the callbacks array empty?

If callbacks fire in #1 but disappear in #2, we’ll know it’s a wiring quirk in the create_react_agent path, not CopilotKit itself. Curious what you see.

rancid bay
#

Hello, having this issue also 🙂 , invoking the graph using the langsmith studio bring the traces to langsmith and to langfuse, but invoking the graph using copilotkit will only make traces on langsmith

I didn't go deeper into the issue yet, but I'll keep any relevant observation here in this thread.

red saddle
#

Here is how i set up my langgraph agent with the langfuse callbackhandler

def build_agents(
    context: CopilotKitContext | None = None, 
) -> list[Agent]:

    ... graph setup, etc

    LangGraphAgent(
        name="my-agent",
        description="my agent",
        graph=agent_graph,
        langgraph_config=RunnableConfig(
            metadata={
                'langfuse_tags': tags,
                'langfuse_user_id': user_id,
            },
            callbacks=[get_langfuse_callback()]
        )
    )

sdk = CopilotKitRemoteEndpoint(agents=build_agents)
add_fastapi_endpoint(auth_router, sdk, "/copilotkit")

rancid bay
#

@red saddle thnx for sharing

#

but the behavior is wierd, like nothing is changing, the same langgraph app with a raw setup, it get's me want to find out what is happening behind the scenes

red saddle
#

Yea the key thing that I did was to set the agents argument to the build_agents function where i return the list of all the agents that I want to exposed. I agree it is odd why thats the fix.

rancid bay
#

I'm gonna spin an assistan-ui chat and see if this works or not

red saddle
#

I am actually converting from assistant-ui to copilotKit now. I like the way copilotKit integrates well with the agent state out of the box. assistant-ui works pretty well though overall it just felt like a lot more custom code required. I would definitely give it a try and see which works best for you!

rancid bay
rancid bay
#

I think that the runtime config is bing erased by this, I don't know how to tshoot this in copilotkit, but any help from the team will be appreciated 🙂

#

also I'm not sure how to debug the langgraph part for this:

graph = builder.compile(name="insurance_agent").with_config({"callbacks": [langfuse_handler]})
#

@carmine tartan is there a way to prevent copilotkit from sending any assistant or graph configuration?