How to set recursion_limit for create_agent (v1)?

Hey everyone,

I’m running into this error when using the new create_agent function (LangChain v1):

Recursion limit of 25 reached without hitting a stop condition. You can increase the limit by setting the recursion_limit config key.

I’d like to increase this limit, but I can’t find any clear documentation on where or how to set the recursion_limit config key for create_agent.

Does anyone know the correct syntax or location for setting this (e.g., inside the config dict or as a parameter to create_agent)?

Thanks in advance!

Hey @UK59 you can try do the following

agent = create_agent(

    model=model,

tools=tools,

prompt=AGENT_PROMPT.format(date=get_today_str()),

state_schema=DeepAgentState,

).with_config({"recursion_limit": 50})
1 Like

hi @UK59 and @Jameskanyiri

@Jameskanyiri 's answer should solve your issue. Here is the doc for it Runnables

with_config sets the default values for Runnable.

You might want to change it at runtime. If so, check those docs:

1 Like