I had set recursion_limit=100, but got error “Recursion limit of 25 reached “

I had set recursion_limit=100, but got error “Recursion limit of 25 reached “

 agent = create_agent(
        model=model,
        tools=[generate_podcast_audio, list_assets, text2image, batch_text2image, asr_transcribe],
        system_prompt=system_prompt,
        middleware=[FrontendToolMiddleware(), frontend_context, CustomTodoListMiddleware()],
    ).with_config(recursion_limit=100)

how the agent is being invoked? Most problebly the value is being overwritten during invocation time

  1. run the agent server : langgraph dev
  2. copilotkit langgraph SDK

Have you checked whether copilot SDK overrides it?

I searched for “recursion_limit” in the copilot source code and couldn’t find anywhere to override it.

I did a little experiment:
Setting the recursion_limit to 2 and having a conversation in Langgraph Studio triggers the recursion_limit immediately, while the conversation doesn’t trigger recursion_limit in CopilotKit. Judging from this phenomenon, there may be a problem with copilotkit, but I don’t know what the problem is. Could it be that copilotkit passed an empty config overwriting the config we set?

1 Like

I set the recursion_limit to 2 in the copilokit LangGraphAgent and immediately triggered the recursion limit. Maybe my guess is right

new LangGraphAgent({
    deploymentUrl: "http://localhost:2024", // make sure to replace with your real deployment url
    langsmithApiKey: process.env.LANGSMITH_API_KEY, // only used in LangGraph Platform deployments
    graphId: 'demo', // usually the same as agent name
    assistantConfig: {
    recursion_limit: 2
   }
}),
2 Likes

Yep, this is my finding too :slight_smile: Great catch @itzhoujun :flexed_biceps:

export class LangGraphAgent extends AGUILangGraphAgent {
  // ...
  constructor(config: LangGraphAgentConfig) {
    super(config);
  }
  // ...
}

interface LangGraphAgentConfig extends AgentConfig {
    client?: Client;
    deploymentUrl: string;
    langsmithApiKey?: string;
    propertyHeaders?: Record<string, string>;
    assistantConfig?: Config;
    agentName?: string;
    graphId: string;
}

// ...

export type Config = {
    /**
     * Tags for this call and any sub-calls (eg. a Chain calling an LLM).
     * You can use these to filter calls.
     */
    tags?: string[];
    /**
     * Maximum number of times a call can recurse.
     * If not provided, defaults to 25.
     */
    recursion_limit?: number;
    /**
     * Runtime values for attributes previously made configurable on this Runnable.
     */
    configurable?: {
        /**
         * ID of the thread
         */
        thread_id?: Optional<string>;
        /**
         * Timestamp of the state checkpoint
         */
        checkpoint_id?: Optional<string>;
        [key: string]: unknown;
    };
};