-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Description
Checked other resources
- This is a bug, not a usage question. For questions, please use the LangChain Forum (https://forum.langchain.com/).
- I added a clear and detailed title that summarizes the issue.
- I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example).
- I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue.
Example Code
async def _init_agent(self, llm_parameters: LLMParameters) -> CompiledStateGraph:
"""
Initialize the agent instance.
Args:
llm_parameters: Parameters for the language model.
Returns:
An instance of CompiledStateGraph representing the agent.
"""
llm: AzureChatOpenAI = await self.llm_service.create_llm(
parameters=llm_parameters
)
prompt = databricks_query_gen_agent_prompt.format(
schema_info=self.metadata_catalog_schema
)
agent: CompiledStateGraph = create_agent(
model=llm,
tools=self._create_agent_tools(),
system_prompt=prompt,
response_format=DatabricksQueryGenerationResponse,
).with_config(recursion_limit=self.settings.agent_recursion_limit)
return agent
agent: CompiledStateGraph = await self._init_agent(
llm_parameters=llm_parameters
)
start_time = time()
try:
logger.DEBUG(
f"Databricks Query Generation Agent processing request for user question [{user_question}]..."
)
response: dict[str, Any] | Any = await agent.ainvoke(
{"messages": [{"type": "human", "content": user_question}]}
)Error Message and Stack Trace (if applicable)
Exception:
2026-01-30 10:19:13 - ERROR - agents.dbrks_query_gen_agent - Agent processing error: Recursion limit of 20 reached without hitting a stop condition. You can increase the limit by setting the `recursion_limit` config key.
Stack trace:
2026-01-30 10:18:12 - INFO - chat_route - Databricks query generation request received
2026-01-30 10:18:12 - DEBUG - agents.dbrks_query_gen_agent - Databricks Query Generation Agent processing request for user question [How many retail locations are in California?]...
2026-01-30 10:18:14 - INFO - agents.tools.metadata_catalog - [TOOL] query_metadata_catalog called with Cypher query: MATCH ...
2026-01-30 10:18:16 - INFO - agents.tools.metadata_catalog - [TOOL] query_metadata_catalog called with Cypher query: MATCH ...
2026-01-30 10:18:52 - INFO - agents.tools.databricks - [TOOL] generate_databricks_query called w/ user question [How many retail locations are in California?]...
2026-01-30 10:18:55 - INFO - agents.tools.databricks - [TOOL] query_databricks called with: SELECT COUNT(*) AS count ...
Token exchange failed, using external token: 'access_token'
2026-01-30 10:18:56 - ERROR - agents.tools.databricks - Databricks SQL query error: [REQUIRES_SINGLE_PART_NAMESPACE] spark_catalog requires a single-part namespace, but got `atlas_data`.`retail`. SQLSTATE: 42K05
2026-01-30 10:18:59 - INFO - agents.tools.databricks - [TOOL] query_databricks called with: SELECT COUNT(*) AS count ...
Token exchange failed, using external token: 'access_token'
2026-01-30 10:18:59 - ERROR - agents.tools.databricks - Databricks SQL query error: [REQUIRES_SINGLE_PART_NAMESPACE] spark_catalog requires a single-part namespace, but got . SQLSTATE: 42K05
2026-01-30 10:19:01 - INFO - agents.tools.databricks - [TOOL] query_databricks called with: SELECT COUNT(*) AS count ...
Token exchange failed, using external token: 'access_token'
2026-01-30 10:19:02 - DEBUG - agents.tools.databricks - [TOOL] query_databricks result cached. query_cache now has 1 entries.
2026-01-30 10:19:05 - INFO - agents.tools.databricks - [TOOL] query_databricks called with: SELECT COUNT(*) AS count ...
Token exchange failed, using external token: 'access_token'
2026-01-30 10:19:07 - DEBUG - agents.tools.databricks - [TOOL] query_databricks result cached. query_cache now has 2 entries.
2026-01-30 10:19:08 - INFO - agents.tools.databricks - [TOOL] query_databricks called with: SELECT COUNT(*) AS count ...
Token exchange failed, using external token: 'access_token'
2026-01-30 10:19:10 - DEBUG - agents.tools.databricks - [TOOL] query_databricks result cached. query_cache now has 3 entries.
2026-01-30 10:19:11 - INFO - agents.tools.databricks - [TOOL] query_databricks called with: SELECT DISTINCT channel_cd ...
Token exchange failed, using external token: 'access_token'
2026-01-30 10:19:13 - DEBUG - agents.tools.databricks - [TOOL] query_databricks result cached. query_cache now has 4 entries.
2026-01-30 10:19:13 - ERROR - agents.dbrks_query_gen_agent - Agent processing error: Recursion limit of 20 reached without hitting a stop condition. You can increase the limit by setting the `recursion_limit` config key.
For troubleshooting, visit: https://docs.langchain.com/oss/python/langgraph/errors/GRAPH_RECURSION_LIMITDescription
Packages
langchain 1.2.6
langchain-classic 1.0.1
langchain-community 0.4.1
langchain-core 1.2.7
langchain-neo4j 0.8.0
langchain-openai 1.1.7
langchain-text-splitters 1.1.0
langgraph 1.0.6
langgraph-checkpoint 2.1.2
langgraph-prebuilt 1.0.6
langgraph-sdk 0.3.3
langsmith 0.3.45
Description
The Text-to-SQL LangGraph agent I have created, using version 1.0.6 of langgraph, is looping indefinitely until hitting the error mentioned above (recursion limit error). This is happening despite clear evidence that the agent should be stopping based on the prompt I've given it. I went back to a 0.6* version of langgraph and did not have this issue with the same exact configurations, so I do believe this is a bug with this specific version. I even tried explicitly specifying stop conditions within the prompt on this newer langgraph version but that did not work, either. No matter what I did, it would infinite loop.
System Info
System Information
OS: Darwin
OS Version: Darwin Kernel Version 24.6.0: Wed Nov 5 21:30:44 PST 2025; root:xnu-11417.140.69.705.2~1/RELEASE_ARM64_T6041
Python Version: 3.12.12 (main, Nov 19 2025, 22:30:44) [Clang 21.1.4 ]
Package Information
langchain_core: 1.2.7
langchain: 1.2.6
langchain_community: 0.4.1
langsmith: 0.3.45
langchain_classic: 1.0.1
langchain_neo4j: 0.8.0
langchain_openai: 1.1.7
langchain_text_splitters: 1.1.0
langgraph_sdk: 0.3.3
Optional packages not installed
langserve
Other Dependencies
aiohttp: 3.13.2
dataclasses-json: 0.6.7
httpx: 0.28.1
httpx-sse: 0.4.3
jsonpatch: 1.33
langgraph: 1.0.6
neo4j: 6.0.3
neo4j-graphrag: 1.12.0
numpy: 2.3.5
openai: 2.0.1
opentelemetry-api: 1.38.0
opentelemetry-sdk: 1.38.0
orjson: 3.11.4
packaging: 25.0
pydantic: 2.11.10
pydantic-settings: 2.12.0
PyYAML: 6.0.3
pyyaml: 6.0.3
requests: 2.32.5
requests-toolbelt: 1.0.0
sqlalchemy: 2.0.44
SQLAlchemy: 2.0.44
tenacity: 9.1.2
tiktoken: 0.12.0
typing-extensions: 4.15.0
uuid-utils: 0.13.0
zstandard: 0.23.0