#Urgent Request for Help

1 messages · Page 1 of 1 (latest)

scarlet light
#

Hi CopilotKit team! We're experiencing an infinite loop when our LangGraph workflows call frontend actions. Here's a concrete example:

We're experiencing an infinite loop when LangGraph workflows call frontend actions. Here's our setup:

Architecture:

  • LangGraph supervisor → workflow pattern
  • Workflows fetch data then display via frontend actions

Example Flow:

  1. User: "Show me billing"
  2. Supervisor calls transfer_to_billing_workflow()
  3. Billing workflow:
    - Calls get_billing_info() → gets data
    - Calls show_billing_summary(data) → frontend action
    - Calls copilotkit_exit()
  4. Problem: After copilotkit_exit(), agent restarts with full history including all tool calls. Supervisor sees "billing" in history, routes to workflow again → infinite loop.

Message history after exit:
User: "Show me billing"
AI: [tool: transfer_to_billing_workflow]
AI: [tool: get_billing_info]
Tool: {data}
AI: [tool: show_billing_summary]
Tool: {empty}

Tried:

  1. State flag before exit - workflow runs before check
  2. Filter messages - causes tool/response mismatch errors
  3. Check if action already called - works but needed in every workflow

Questions:

  1. Why does agent re-run with full history after copilotkit_exit()?
  2. How to complete workflow+frontend action without re-execution?
  3. Is there a different exit pattern for workflows with frontend actions?

Works fine with backend-only tools, breaks with frontend actions. Using render property, not handler.

scarlet light
#

overall I am just reaally struggling to integrate frontend actions i.e. get my backend to trigger frontend actions - I have tried so many different configurations and either the action renders and then goes into an infinite loop or the action deosnt render

queen citrus
#

what version of langgraph are you using and what version of cpk?

#

also are you using any react agents or the built in supervisor class

scarlet light
#

ah - I think I have it working

was something very small... was that I needed to disable the followUp option - this is what was causing me the infinite loop

#

thanks for responding

sly sparrow
#

Hey @scarlet light , I’m interested in the solution you found. Would you mind sharing which option you disabled? I’m currently working on an agent that requires a similar setup, so it would be really helpful to know the trick in advance.

scarlet light
#

Hey man - no problem - its here: https://docs.copilotkit.ai/reference/hooks/useCopilotAction

my idea is that I have various deterministic workflows (langgraph subgraphs) that involve (a) get some data (b) display some data and I have an orchestrator agent that routes to these workflows (rather than stuffing one node with a massive prompt saying case A (do this then then this) case B (do this then this) ... etc (unscalable)

the reason I like frontend actions for the displaying data (rather than having the frontend componetns just listening for state updates) is that I feel like it gives me more control of what I render on the frontend (ie usng the copilotaction hook)

the problem I was facing is that be default when your langraph agent triggers a frontend action, the copilotkit runtme will ping your backend with a response after it renders the frontend - this is not desirable if I just want to display information i.e. there is nothing my backend needs in return:

if you look here: https://docs.copilotkit.ai/reference/hooks/useCopilotAction

they have a:

followUp
boolean
Default: "true"
Whether to report the result of a function call to the LLM which will then provide a follow-up response. Pass false to disable

I was getting stuck in an infinite loop when I was calling my frontend actios because my default the followUp flag was set to True

turning it off solved my issues!

also - any overall architectural comments or criticisms or thoughts would be appreciated

The useCopilotAction hook allows your copilot to take action in the app.